-
Notifications
You must be signed in to change notification settings - Fork 1
/
readcSV.py
47 lines (43 loc) · 1.37 KB
/
readcSV.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
import traceback
import csv
import glob
import MySQLdb
def addTweetDataMany(tweetList):
try:
con = MySQLdb.connect(host='127.0.0.1', user='root', passwd='root', db='ab_twitter')
cur = con.cursor()
cur.executemany('INSERT INTO adobe(date,tweet,user) values (%s,%s,%s)',[sub for sub in tweetList])
con.commit()
con.close()
except Exception, e:
print traceback.format_exc()
source = raw_input("Enter the source:")
filename = 'D:/Innovaccer/Projects/Abhishek borah - twitter data/Input-Files/distinct csv/' + source + '.csv'
with open(filename, 'rb') as f:
try:
reader = csv.reader(f)
count = 0
tweetList = []
for row in reader:
# print row
tweetTuple = tuple(row)
# print tweetTuple
tweetList.append(tweetTuple)
count += 1
if count >= 10000:
print count
addTweetDataMany(tweetList)
count = 0
tweetList = []
print count,tweetList
# break
print count
addTweetDataMany(tweetList)
count = 0
tweetList = []
print count,tweetList
# if 'RT ' in row[1]:
# print row
# break
except Exception, e:
print traceback.format_exc()