-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsandbox.py
More file actions
34 lines (29 loc) · 1.14 KB
/
sandbox.py
File metadata and controls
34 lines (29 loc) · 1.14 KB
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
import requests
from dotenv import load_dotenv
import os
import json
import pandas as pd
import datetime
load_dotenv()
global URL
global api_key
global stopcodes # stopcodes intrinsically defines the destination as SF-bound
global operator
URL = os.getenv('URL')
api_key = os.getenv('api_key')
stopcodes = os.getenv('stopcodes')
operator = os.getenv('operator')
stopcodes = stopcodes.split(',')
for i in range(len(stopcodes)):
stopcodes[i] = stopcodes[i].strip()
print(stopcodes)
for stop in stopcodes:
r = requests.get(f'{URL}/StopMonitoring',
params = {'agency': operator,
'api_key': api_key,
'stopcode': stop})
content = json.loads(r.content)
stopinfo = pd.DataFrame.from_records(content)
stopinfo = stopinfo['ServiceDelivery']['StopMonitoringDelivery']['MonitoredStopVisit']
for arrival in stopinfo:
print(arrival['MonitoredVehicleJourney']['MonitoredCall']['ExpectedArrivalTime'], arrival['MonitoredVehicleJourney']['MonitoredCall']['DestinationDisplay']) # standard time of next 3 projected arrivals for specified stop