Created
February 6, 2019 17:07
-
-
Save chadmhorner/60270439e0296556d2a4aa81eaac7440 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from readypipe import requests, starting_task, subtask, schedule, save | |
API_KEY = 'your_api_key_here' | |
SERVICE_URL = 'https://collector-otp-prod.camsys-apps.com/realtime/serviceStatus?apikey=' + API_KEY | |
@starting_task | |
def check_routes(): | |
json_data = requests.get_json_from_content(SERVICE_URL) | |
last_updated = json_data.get('lastUpdated') | |
route_details = json_data.get('routeDetails') | |
for route in route_details: | |
if route.get('statusDetails'): | |
status = route.get('statusDetails')[0] | |
status_summary = status.get('statusSummary') | |
route_name = route.get('route') | |
mode = route.get('mode').upper() | |
print(mode + ": " + status_summary + " on the " + route_name + " line.") | |
@starting_task | |
def get_status(): | |
json_data = requests.get_json_from_content(SERVICE_URL) | |
last_updated = json_data.get('lastUpdated') | |
route_details = json_data.get('routeDetails') | |
for route in route_details: | |
_route = route.get('route') | |
_color = route.get('color') | |
_mode = route.get('mode') | |
_agency = route.get('agency') | |
_route_id = route.get('routeId') | |
_in_service = route.get('inService') | |
_route_type = route.get('routeType') | |
if route.get('statusDetails'): | |
status_index = 1 | |
status_details = route.get('statusDetails') | |
for status in status_details: | |
_status_summary = status.get('statusSummary') | |
_status_description = status.get('statusDescription') | |
_priority = status.get('priority') | |
_direction = status.get('direction') | |
_creation_date = status.get('creationDate') | |
_start_date = status.get('startDate') | |
_end_date = status.get('endDate') | |
data = { | |
'route': _route, | |
'color': _color, | |
'mode': _mode, | |
'agency': _agency, | |
'route_id': _route_id, | |
'in_service': _in_service, | |
'route_type': _route_type, | |
'status_summary': _status_summary, | |
'status_description': _status_description, | |
'priority': _priority, | |
'direction': _direction, | |
'creation_date': _creation_date, | |
'start_date': _start_date, | |
'end_date': _end_date, | |
'status_index': status_index, | |
} | |
save('service_status', data) | |
status_index += 1 | |
else: | |
data = { | |
'route': _route, | |
'color': _color, | |
'mode': _mode, | |
'agency': _agency, | |
'route_id': _route_id, | |
'in_service': _in_service, | |
'route_type': _route_type, | |
'status_summary': None, | |
'status_description': None, | |
'priority': None, | |
'direction': None, | |
'creation_date': None, | |
'start_date': None, | |
'end_date': None, | |
'status_index': 1, | |
} | |
save('service_status', data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment