-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.py
24 lines (24 loc) · 5.41 KB
/
test.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
import json
stop_time_json = "[{'trip_id': '10267000951731-SEPT22', 'stop_id': '11957', 'arrival': 0, 'departure': 1666917116, 'stop_sequence': 1, 'agency_id': 'LACMTA', 'schedule_relationship': 0}, {'trip_id': '10267000951731-SEPT22', 'stop_id': '501', 'arrival': 1666917360, 'departure': 0, 'stop_sequence': 2, 'agency_id': 'LACMTA', 'schedule_relationship': 0}, {'trip_id': '10267000951731-SEPT22', 'stop_id': '13695', 'arrival': 1666917524, 'departure': 0, 'stop_sequence': 3, 'agency_id': 'LACMTA', 'schedule_relationship': 0}, {'trip_id': '10267000951731-SEPT22', 'stop_id': '9905', 'arrival': 1666917578, 'departure': 0, 'stop_sequence': 4, 'agency_id': 'LACMTA', 'schedule_relationship': 0}, {'trip_id': '10267000951731-SEPT22', 'stop_id': '9907', 'arrival': 1666917618, 'departure': 0, 'stop_sequence': 5, 'agency_id': 'LACMTA', 'schedule_relationship': 0}, {'trip_id': '10267000951731-SEPT22', 'stop_id': '9909', 'arrival': 1666917630, 'departure': 1666917730, 'stop_sequence': 6, 'agency_id': 'LACMTA', 'schedule_relationship': 0}, {'trip_id': '10267000951731-SEPT22', 'stop_id': '9911', 'arrival': 1666917730, 'departure': 0, 'stop_sequence': 7, 'agency_id': 'LACMTA', 'schedule_relationship': 0}, {'trip_id': '10267000951731-SEPT22', 'stop_id': '9915', 'arrival': 1666917820, 'departure': 0, 'stop_sequence': 8, 'agency_id': 'LACMTA', 'schedule_relationship': 0}, {'trip_id': '10267000951731-SEPT22', 'stop_id': '9902', 'arrival': 1666917854, 'departure': 0, 'stop_sequence': 9, 'agency_id': 'LACMTA', 'schedule_relationship': 0}, {'trip_id': '10267000951731-SEPT22', 'stop_id': '9544', 'arrival': 1666917883, 'departure': 0, 'stop_sequence': 10, 'agency_id': 'LACMTA', 'schedule_relationship': 0}, {'trip_id': '10267000951731-SEPT22', 'stop_id': '9901', 'arrival': 1666917987, 'departure': 0, 'stop_sequence': 11, 'agency_id': 'LACMTA', 'schedule_relationship': 0}, {'trip_id': '10267000951731-SEPT22', 'stop_id': '9898', 'arrival': 1666918052, 'departure': 0, 'stop_sequence': 12, 'agency_id': 'LACMTA', 'schedule_relationship': 0}, {'trip_id': '10267000951731-SEPT22', 'stop_id': '9900', 'arrival': 1666918077, 'departure': 0, 'stop_sequence': 13, 'agency_id': 'LACMTA', 'schedule_relationship': 0}, {'trip_id': '10267000951731-SEPT22', 'stop_id': '9903', 'arrival': 1666918100, 'departure': 0, 'stop_sequence': 14, 'agency_id': 'LACMTA', 'schedule_relationship': 0}, {'trip_id': '10267000951731-SEPT22', 'stop_id': '9897', 'arrival': 1666918115, 'departure': 0, 'stop_sequence': 15, 'agency_id': 'LACMTA', 'schedule_relationship': 0}, {'trip_id': '10267000951731-SEPT22', 'stop_id': '9914', 'arrival': 1666918149, 'departure': 0, 'stop_sequence': 16, 'agency_id': 'LACMTA', 'schedule_relationship': 0}, {'trip_id': '10267000951731-SEPT22', 'stop_id': '9899', 'arrival': 1666918180, 'departure': 0, 'stop_sequence': 17, 'agency_id': 'LACMTA', 'schedule_relationship': 0}, {'trip_id': '10267000951731-SEPT22', 'stop_id': '9912', 'arrival': 1666918210, 'departure': 0, 'stop_sequence': 18, 'agency_id': 'LACMTA', 'schedule_relationship': 0}, {'trip_id': '10267000951731-SEPT22', 'stop_id': '9904', 'arrival': 1666918277, 'departure': 0, 'stop_sequence': 19, 'agency_id': 'LACMTA', 'schedule_relationship': 0}, {'trip_id': '10267000951731-SEPT22', 'stop_id': '9906', 'arrival': 1666918289, 'departure': 0, 'stop_sequence': 20, 'agency_id': 'LACMTA', 'schedule_relationship': 0}, {'trip_id': '10267000951731-SEPT22', 'stop_id': '9908', 'arrival': 1666918326, 'departure': 0, 'stop_sequence': 21, 'agency_id': 'LACMTA', 'schedule_relationship': 0}, {'trip_id': '10267000951731-SEPT22', 'stop_id': '9552', 'arrival': 1666918354, 'departure': 0, 'stop_sequence': 22, 'agency_id': 'LACMTA', 'schedule_relationship': 0}, {'trip_id': '10267000951731-SEPT22', 'stop_id': '9553', 'arrival': 1666918396, 'departure': 0, 'stop_sequence': 23, 'agency_id': 'LACMTA', 'schedule_relationship': 0}, {'trip_id': '10267000951731-SEPT22', 'stop_id': '9554', 'arrival': 1666918436, 'departure': 0, 'stop_sequence': 24, 'agency_id': 'LACMTA', 'schedule_relationship': 0}, {'trip_id': '10267000951731-SEPT22', 'stop_id': '13072', 'arrival': 1666918481, 'departure': 0, 'stop_sequence': 25, 'agency_id': 'LACMTA', 'schedule_relationship': 0}, {'trip_id': '10267000951731-SEPT22', 'stop_id': '9828', 'arrival': 1666918522, 'departure': 0, 'stop_sequence': 26, 'agency_id': 'LACMTA', 'schedule_relationship': 0}, {'trip_id': '10267000951731-SEPT22', 'stop_id': '65300029', 'arrival': 1666918677, 'departure': 0, 'stop_sequence': 27, 'agency_id': 'LACMTA', 'schedule_relationship': 0}]"
stop_time_updates = []
clean_stop_time_json = stop_time_json.replace("'", '"')
for stop_time in json.loads(clean_stop_time_json):
this_stop_time = {}
if 'stop_squence' in stop_time:
this_stop_time['stopSequence'] = stop_time['stop_sequence']
if 'arrival' in stop_time:
arrival = {}
arrival['time'] = stop_time['arrival']
this_stop_time['arrival'] = arrival
if 'departure' in stop_time:
departure = {}
departure['time'] = stop_time['departure']
this_stop_time['departure'] = departure
# if 'schedule_relationship' in stop_time:
# this_stop_time['scheduleRelationship'] = get_readable_schedule_relationship(stop_time['schedule_relationship'])
if 'stop_id' in stop_time:
this_stop_time['stopId'] = stop_time['stop_id']
stop_time_updates.append(this_stop_time)
print(stop_time_updates)
# json_load = json.loads(str(s))
# print(json_load)