1+ #########
2+ # Use: python ./example_read_csv.py -b your_bucket_key -k your_access_key -f 'csv_file_location.csv'
3+ # Note: The CSV file structure should NOT contain a header and should be in the following format
4+ # <ISO-8601 Date Time>,<StreamKey>,<StreamValue>/n
5+ ##########
6+
17import getopt , sys , time , csv
28from ISStreamer .Streamer import Streamer
39
410def read_args (argv ):
511 try :
6- opts , args = getopt .getopt (argv ,"hb:k:f:" ,["bucket_name =" , "access_key=" , "file_location=" ])
12+ opts , args = getopt .getopt (argv ,"hb:k:f:" ,["bucket_key =" , "access_key=" , "file_location=" ])
713 except getopt .GetoptError :
8- print ('example_read_csv.py -b <bucket_name > -k <access_key> -f <file_location>' )
14+ print ('example_read_csv.py -b <bucket_key > -k <access_key> -f <file_location>' )
915 sys .exit (1 )
1016
1117 for opt , arg in opts :
1218 if opt == '-h' :
13- print ('example_read_csv.py -b <bucket_name > -k <access_key> -f <file_location>' )
14- elif opt in ("-b" , "--bucket_name " ):
19+ print ('example_read_csv.py -b <bucket_key > -k <access_key> -f <file_location>' )
20+ elif opt in ("-b" , "--bucket_key " ):
1521 bucket = arg
1622 elif opt in ("-k" , "--access_key" ):
1723 access_key = arg
@@ -20,17 +26,26 @@ def read_args(argv):
2026
2127 return bucket , access_key , file_location
2228
29+ def is_float (str ):
30+ try :
31+ float (str )
32+ return True
33+ except ValueError :
34+ return False
2335
2436if __name__ == "__main__" :
2537 bucket , access_key , file_location = read_args (sys .argv [1 :])
2638
27- streamer = Streamer (bucket_name = bucket , access_key = access_key , buffer_size = 20 , offline = False )
39+ streamer = Streamer (bucket_name = bucket , bucket_key = bucket , access_key = access_key , buffer_size = 20 , offline = False )
2840
2941 with open (file_location , 'rb' ) as csvfile :
3042 reader = csv .reader (csvfile )
3143 counter = 0
3244 for row in reader :
33- streamer .log (row [1 ], row [2 ], epoch = row [0 ])
45+ epoch = row [0 ]
46+ if not is_float (epoch ):
47+ epoch = ((dateutil .parser .parse (epoch ))- (dateutil .parser .parse ("1970-01-01T00:00:00Z" ))).total_seconds ()
48+ streamer .log (row [1 ], row [2 ], epoch = epoch )
3449 counter += 1
3550
3651 if counter % 10 == 0 :
0 commit comments