-
Notifications
You must be signed in to change notification settings - Fork 10
/
NycTaxi_Producer_Cloud9_JSON.py
53 lines (39 loc) · 1.06 KB
/
NycTaxi_Producer_Cloud9_JSON.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
# Download the taxi cab file
'''
wget https://s3.amazonaws.com/nyc-tlc/trip+data/yellow_tripdata_2020-01.csv
'''
# Install boto3
'''
pip install boto3
'''
# Import req. libraries
import json
import csv
import boto3
# Make JSON from the yellow cab trip data CSV files
taxiCabRides = []
with open('./yellow_tripdata_2020-01.csv', encoding='utf-8') as csvf:
csvReader = csv.DictReader(csvf)
for rows in csvReader:
taxiCabRides.append(rows)
# print(rows)
# print(taxiCabRides[0])
# Create a kinesis client
client = boto3.client('kinesis')
counter = 0
for ride in taxiCabRides:
# print(ride)
# print(json.dumps(ride))
# print(ride['VendorID'])
# Send message to Kinesis DataStream
response = client.put_record(
StreamName = "yellow-cab-trip",
Data = json.dumps(ride),
PartitionKey = str(hash(ride['tpep_pickup_datetime']))
)
counter = counter + 1
print('Message sent #' + str(counter))
# If the message was not sucssfully sent print an error message
if response['ResponseMetadata']['HTTPStatusCode'] != 200:
print('Error!')
print(response)