Skip to content

Instantly share code, notes, and snippets.

@nhfruchter
Created December 26, 2018 21:06
Show Gist options
  • Save nhfruchter/8ab19cce240f13cb227f1ffe57a56203 to your computer and use it in GitHub Desktop.
Save nhfruchter/8ab19cce240f13cb227f1ffe57a56203 to your computer and use it in GitHub Desktop.
import requests
def fetchPredictions():
apikey = ""
filter_route = "Green-B,Green-C,Green-D,Green-E"
include = "vehicle,trip"
p = {"filter[route]": filter_route, "include": include}
result = requests.get("https://api-v3.mbta.com/predictions", params=p).json()
return result
def findNew(result):
SERIES = "39"
out = []
for v in result['included']:
if v['attributes'].get('label'):
ids = v['attributes'].get('label').split("-")
if any(id.startswith(SERIES) for id in ids):
out.append(v)
return out
print(findNew(fetchPredicions))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment