Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@stevage
Created March 27, 2014 12:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevage/9806720 to your computer and use it in GitHub Desktop.
Save stevage/9806720 to your computer and use it in GitHub Desktop.
PTVAPI-GTFS scratch 1
'''
1. get stops
2. get lines
3. get runs
'''
import ptvapi
import pprint
pp = pprint.PrettyPrinter(indent=4).pprint
stops=[]
long1= 140
long2=141
lat1=-35
lat2=-37
stopids=[]
lines={}
linedirs={}
terminuses={}
patterns={}
def getStops():
stops = ptvapi.transportPOIsByMap('0,1,2,3,4', lat1, long1, lat2, long2, 0, 10000)
stopids = map(lambda x: x['stop_id'], stops['locations'])
def getLines():
getStops()
for stop in stops['locations']:
b = ptvapi.broadNextDepartures(stop['transport_type'], stop['stop_id'], 1)
for l in b:
line = l['platform']['direction']['line']
# pp.pprint(line)
lines[line['line_id']] = line
dir = l['platform']['direction']
linedirs[dir['linedir_id']] = dir
dest = l['run']
terminuses[dest['destination_id']] = {
'destination_name': dest['destination_name'], 'transport_type': dest['transport_type']
}
# The goal: a list of (mode, line, stop, direction_id) that we can pass to specificNextDepartures
# to get a comprehensive list of all services each day.
# Approach?
# 1. Get destinations
# 2. broad departures at each destination to find platforms and directions
# 3. specific departures?
def getRuns():
getLines()
for d in terminuses:
terminuses[d]['runs'] = ptvapi.broadNextDepartures(terminuses[d]['transport_type'], d, 1)
def getTimeTable():
for d in terminuses:
patterns[d] = {}
for r in terminuses[d]['runs']:
patterns[d][r['run']['run_id']] = ptvapi.stoppingPattern(r['run']['transport_type'], r['run']['run_id'], d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment