pip install -r requirements.txt
python api-client.py
Last active
November 23, 2020 06:38
-
-
Save winstonma/0af29a86ff1c1911fb0be340c0005554 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
# import requests module | |
import requests | |
import dateutil.parser as dp | |
from dateutil.relativedelta import relativedelta | |
from dateutil.tz import tz, tzlocal | |
from datetime import * | |
# Making a get request | |
response = requests.get('http://localhost:5000/getETAsByStopID/CH15-T-1100-0') | |
# Set Timezone | |
to_zone = tz.gettz('Asia/Hong_Kong') | |
NOW = datetime.now(tzlocal()) | |
# print json content | |
jsonResponse = response.json() | |
for route in jsonResponse: | |
# Print route info | |
print("Route: " + str(route[0]['stopping']['variant']['route']['number'])) | |
print("Destination: " + str(route[0]['stopping']['variant']['destination'])) | |
print("ETA:") | |
for stop in route: | |
# Print ETA | |
time = dp.isoparse(stop['time']) | |
print(" " + time.astimezone(to_zone).strftime('%H:%M') + " (" + str(relativedelta(time, NOW).minutes) + " minutes)") | |
print("\n") |
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
requests | |
python-dateutil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment