-
Notifications
You must be signed in to change notification settings - Fork 3
/
load-data-v2a.py
50 lines (43 loc) · 1.14 KB
/
load-data-v2a.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
#
#
#Will iterate through the demo-data-extract csv file and put into Riak in batches of 100
#SMDE 29/4/16
from riak import RiakClient
from datetime import datetime
import calendar
import csv
def changetime(stime):
dt=datetime.strptime(stime,'%Y-%m-%dT%H:%M:%S')
#print dt
return calendar.timegm(datetime.timetuple(dt))*1000
c=RiakClient()
c.ping()
#to load data in the table
totalcount=0
batchcount=0
batchsize=100
ds=[]
t=c.table('aarhus2')
print t
with open('./demo-data-extract.csv', 'rU') as infile:
r=csv.reader(infile)
for l in r:
if l[0]!='status':
newl=[l[0],str(l[3]),datetime.strptime(l[5],'%Y-%m-%dT%H:%M:%S'),int(l[1]),int(l[2]),int(l[4]),int(l[6]),int(l[7]),int(l[8])]
totalcount=totalcount+1
#print count
ds.append(newl)
batchcount=batchcount+1
if batchcount==batchsize:
#add the records to the table
print "Count at ", totalcount
to=t.new(ds)
print "Created ts object"
print "Storage result: ",to.store()
batchcount=0
ds=[]
infile.close()
print "Input file closed"
to=t.new(ds)
print "Storage result: ",to.store()
print totalcount