-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathghtorrent_commit_comments.py
61 lines (53 loc) · 1.86 KB
/
ghtorrent_commit_comments.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import psycopg2
import csv
csv_data = csv.reader(file('/data/aditi/raw_data/github/commit_comments.csv','rU'))
database = psycopg2.connect(database='netdata', user='postgres', password='postgres')
count = 0
x = 0
y = 0
z = 0
cursor = database.cursor()
delete = "Drop table if exists ghtorrent_commit_comments"
print (delete)
mydata = cursor.execute(delete)
cursor.execute("""CREATE TABLE ghtorrent_commit_comments(id integer PRIMARY KEY NOT NULL, commit_id integer NOT NULL, user_id integer NOT NULL, body character varying(500), line integer, position integer, comment_id integer NOT NULL, created_at timestamp without time zone NOT NULL)""")
print "Table created successfully"
for row in csv_data:
print " : one"
for i,column in enumerate(row):
if column == '\N':
row[i] = 0
try:
z = z + 1
print row[1]," : two"
if row[0] >= -10:
print "three"
for column in row:
count = count + 1;
#print "now : ",count
if count == 8:
#print "here : ",count
for i,column in enumerate(row):
if row[7] == '0000-00-00 00:00:00':
print "date changed"
row[7] = '1111-11-11 11:11:11'
print "inserting"
cursor.execute("INSERT INTO ghtorrent_commit_comments (id, commit_id, user_id, body, line, position, comment_id, created_at) VALUES (%s,%s,%s,%s,%s,%s,%s,%s)",row)
print x," : ",count
x = x + 1
count = 0
else:
count = 0
else:
pass
except (psycopg2.DataError, IndexError) as e:
print row," : exception : ",e
y = y + 1
pass
print z
print y
print x
cursor.close()
database.commit()
database.close()
print "CSV users data imported"