import os import sqlite3 import operator from pytz import timezone import pytz MAX_DISTANCE = 801 if len(sys.argv) < 2: USAGE = """usage: timetable.py inputfile.gtfsdb [calendar start date] If a start date is provided in YYYY-MM-DD format, a calendar will be built for the 32 days following the given date. Otherwise the service calendar will be analyzed and the month with the maximum number of running services will be used.""" print USAGE exit(1) db = GTFSDatabase(sys.argv[1]) out = open("./timetable.dat", "wb") feed_start_date, feed_end_date = db.date_range() print 'feed covers %s -- %s' % (feed_start_date, feed_end_date) # second command line parameter: start date for 32-day calendar try: start_date = date(*map(int, sys.argv[2].split('-'))) except: print 'Scanning service calendar to find the month with maximum service.' print 'NOTE that this is not necessarily accurate and you can end up with sparse service in the chosen period.' start_date = db.find_max_service() print 'calendar start date is %s' % start_date
from gtfsdb import GTFSDatabase import sys if __name__=='__main__': if len(sys.argv) < 3: print "Converts GTFS file to GTFS-DB, which is super handy\nusage: python process_gtfs.py gtfs_filename, gtfsdb_filename" exit() gtfsdb_filename = sys.argv[2] gtfs_filename = sys.argv[1] gtfsdb = GTFSDatabase( gtfsdb_filename, overwrite=True ) gtfsdb.load_gtfs( gtfs_filename, reporter=sys.stdout )
import os import sqlite3 import operator from pytz import timezone import pytz MAX_DISTANCE = 801 if len(sys.argv) < 2 : USAGE = """usage: timetable.py inputfile.gtfsdb [calendar start date] If a start date is provided in YYYY-MM-DD format, a calendar will be built for the 32 days following the given date. Otherwise the service calendar will be analyzed and the month with the maximum number of running services will be used.""" print USAGE exit(1) db = GTFSDatabase(sys.argv[1]) out = open("./timetable.dat", "wb") feed_start_date, feed_end_date = db.date_range() print 'feed covers %s -- %s' % (feed_start_date, feed_end_date) # second command line parameter: start date for 32-day calendar try : start_date = date( *map(int, sys.argv[2].split('-')) ) except : print 'Scanning service calendar to find the month with maximum service.' print 'NOTE that this is not necessarily accurate and you can end up with sparse service in the chosen period.' start_date = db.find_max_service() print 'calendar start date is %s' % start_date
# requires graphserver to be installed from gtfsdb import GTFSDatabase verbose = False RADIUS = 800 # meters OBSTRUCTION = 1.3 # factor to expand straight-line distance range_lat = RADIUS / 111111.111 if len(sys.argv) < 2 : print 'usage: transfers.py infile.gtfsdb [verbose]' exit(1) gtfsdb_file = sys.argv[1] try : with open(gtfsdb_file) as f : db = GTFSDatabase(gtfsdb_file) except IOError as e : print 'gtfsdb file "%s" cannot be opened' % gtfsdb_file exit(1) if len(sys.argv) > 2 and sys.argv[2] == "verbose" : verbose = True # a normal index on lat and lon is sufficiently fast, no need for a spatial index all_query = "select stop_id, stop_name, stop_lat, stop_lon from stops;" near_query = """ select stop_id, stop_name, stop_lat, stop_lon from stops where stop_lat > (:lat - :range_lat) and stop_lat < (:lat + :range_lat) and stop_lon > (:lon - :range_lon) and stop_lon < (:lon + :range_lon) ; """
from gtfsdb import GTFSDatabase import sys if __name__ == '__main__': if len(sys.argv) < 2: print "usage: python gtfsdb_stats.py gtfsdb_filename" exit() db = GTFSDatabase(sys.argv[1]) print "extent: %s" % (db.extent(), ) print "stop count: %d" % db.count_stops() print "date range: %s" % (db.date_range(), )
from gtfsdb import GTFSDatabase import sys if __name__ == "__main__": if len(sys.argv) < 2: print "usage: python gtfsdb_stats.py gtfsdb_filename" exit() db = GTFSDatabase(sys.argv[1]) print "extent: %s" % (db.extent(),) print "stop count: %d" % db.count_stops() print "date range: %s" % (db.date_range(),)