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 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('*********************************') | |
I think we need to check that the time isn't between 12am and 5:30am.
The 801 and 1 are inactive between those times open-austin/project-ideas#3 (comment)
Some days there are active vehicles in that time range. But sending false alarms in the middle of the night means real alarms will go ignored. Even if there is a real alarm in the middle of the night, nobody will fix it.
from __future__ import print_function
import json
import urllib2
from datetime import datetime
LAMBDA_API = 'https://lnykjry6ze.execute-api.us-west-2.amazonaws.com/prod/gtfsrt-debug'
GTFSRT_FEED = 'https://data.texas.gov/download/eiei-9rpf/application/octet-stream'
CRONITOR = '...'
def lambda_handler(event, context):
url = '{}?url={}'.format(LAMBDA_API, GTFSRT_FEED)
res = urllib2.urlopen(url)
data = json.load(res)
date = datetime.now()
now = date.isoformat()
print('*********************************')
if len(data['vehicle_positions']) > 0:
print('{} - SUCCESS - vehicle positions is NOT empty, url: {}'.format(now, url))
urllib2.urlopen(CRONITOR)
elif date.hour > 6 and date.hour <= 11:
print('{} - FAILURE - vehicle positions is empty, but IGNORED because hour is {}, url: {}'.format(now, date.hour, url))
urllib2.urlopen(CRONITOR)
else:
print('{} - FAILURE - vehicle positions is empty, url: {}'.format(now, url))
print('*********************************')
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Current time:
1455894457