Created
February 18, 2016 06:26
-
-
Save scascketta/27804594c3a8bac55201 to your computer and use it in GitHub Desktop.
Monitor GTFS-realtime vehicle positions using Cronitor.io.
This file contains hidden or 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 __future__ import print_function | |
import os | |
import json | |
import urllib2 | |
from datetime import datetime | |
LAMBDA_API = 'https://vni1fkrx5b.execute-api.us-east-1.amazonaws.com/prod/gtfsrt-debug' | |
GTFSRT_FEED = 'https://data.texas.gov/download/eiei-9rpf/application/octet-stream' | |
CRONITOR = '<YOUR-CRONITOR-URL>' | |
def lambda_handler(event, context): | |
url = '{}?url={}'.format(LAMBDA_API, GTFSRT_FEED) | |
res = urllib2.urlopen(url) | |
data = json.load(res) | |
now = datetime.now().isoformat() | |
print('*********************************') | |
if len(data['vehicle_positions']) > 0: | |
print('{} - SUCCESS - vehicle positions is NOT empty, url: {}'.format(now, url)) | |
urllib2.urlopen(CRONITOR) | |
else: | |
print('{} - FAILURE - vehicle positions is empty, url: {}'.format(now, url)) | |
print('*********************************') | |
luqmaan
commented
Mar 9, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment