def main(RequestHandlerClass = ScheduleRequestHandler): usage = \ '''%prog [options] [<input GTFS.zip>] Runs a webserver that lets you explore a <input GTFS.zip> in your browser. If <input GTFS.zip> is omited the filename is read from the console. Dragging a file into the console may enter the filename. For more information see https://github.com/google/transitfeed/wiki/ScheduleViewer ''' parser = util.OptionParserLongError( usage=usage, version='%prog '+transitfeed.__version__) parser.add_option('--feed_filename', '--feed', dest='feed_filename', help='file name of feed to load') parser.add_option('--key', dest='key', help='Google Maps API key or the name ' 'of a text file that contains an API key') parser.add_option('--host', dest='host', help='Host name of Google Maps') parser.add_option('--port', dest='port', type='int', help='port on which to listen') parser.add_option('--file_dir', dest='file_dir', help='directory containing static files') parser.add_option('-n', '--noprompt', action='store_false', dest='manual_entry', help='disable interactive prompts') parser.set_defaults(port=8765, host='maps.google.com', file_dir=FindDefaultFileDir(), manual_entry=True) (options, args) = parser.parse_args() if not os.path.isfile(os.path.join(options.file_dir, 'index.html')): print "Can't find index.html with --file_dir=%s" % options.file_dir exit(1) if not options.feed_filename and len(args) == 1: options.feed_filename = args[0] if not options.feed_filename and options.manual_entry: options.feed_filename = raw_input('Enter Feed Location: ').strip('"') default_key_file = GetDefaultKeyFilePath() if not options.key and os.path.isfile(default_key_file): options.key = open(default_key_file).read().strip() if options.key and os.path.isfile(options.key): options.key = open(options.key).read().strip() # This key is registered to [email protected] if not options.key: options.key = 'AIzaSyAZTTRO6RC6LQyKCD3JODhxbClsZl95P9U' schedule = transitfeed.Schedule(problem_reporter=transitfeed.ProblemReporter()) print 'Loading data from feed "%s"...' % options.feed_filename print '(this may take a few minutes for larger cities)' schedule.Load(options.feed_filename) server = StoppableHTTPServer(server_address=('', options.port), RequestHandlerClass=RequestHandlerClass) server.key = options.key server.schedule = schedule server.file_dir = options.file_dir server.host = options.host server.feed_path = options.feed_filename print ("To view, point your browser at http://localhost:%d/" % (server.server_port)) server.serve_forever()
def main(): usage = """%prog [options] <input GTFS.zip> [<output.kml>] Reads GTFS file or directory <input GTFS.zip> and creates a KML file <output.kml> that contains the geographical features of the input. If <output.kml> is omitted a default filename is picked based on <input GTFS.zip>. By default the KML contains all stops and shapes. For more information see https://github.com/google/transitfeed/wiki/KMLWriter """ parser = util.OptionParserLongError( usage=usage, version="%prog " + transitfeed.__version__ ) parser.add_option( "-t", "--showtrips", action="store_true", dest="show_trips", help="include the individual trips for each route", ) parser.add_option( "-a", "--altitude_per_sec", action="store", type="float", dest="altitude_per_sec", help="if greater than 0 trips are drawn with time axis " "set to this many meters high for each second of time", ) parser.add_option( "-s", "--splitroutes", action="store_true", dest="split_routes", help="split the routes by type", ) parser.add_option( "-d", "--date_filter", action="store", type="string", dest="date_filter", help="Restrict to trips active on date YYYYMMDD", ) parser.add_option( "-p", "--display_shape_points", action="store_true", dest="shape_points", help="shows the actual points along shapes", ) parser.add_option( "--show_stop_hierarchy", action="store_true", dest="show_stop_hierarchy", help="include station-stop hierarchy info in output", ) parser.set_defaults(altitude_per_sec=1.0) options, args = parser.parse_args() if len(args) < 1: parser.error("You must provide the path of an input GTFS file.") if args[0] == "IWantMyCrash": raise Exception("For testCrashHandler") input_path = args[0] if len(args) >= 2: output_path = args[1] else: path = os.path.normpath(input_path) (feed_dir, feed_name) = os.path.split(path) if "." in feed_name: feed_name = feed_name.rsplit(".", 1)[0] # strip extension output_filename = "%s.kml" % feed_name output_path = os.path.join(feed_dir, output_filename) feed = None try: loader = transitfeed.Loader(input_path) feed = loader.Load() except transitfeed.ExceptionWithContext as e: print( ( "\n\nGTFS feed must load without any errors.\n" "While loading %s the following error was found:\n%s\n%s\n" % ( input_path, e.FormatContext(), transitfeed.EncodeUnicode(e.FormatProblem()), ) ), file=sys.stderr, ) sys.exit(1) print("Writing %s" % output_path) writer = KMLWriter() writer.show_trips = options.show_trips writer.altitude_per_sec = options.altitude_per_sec writer.split_routes = options.split_routes writer.date_filter = options.date_filter writer.shape_points = options.shape_points writer.show_stop_hierarchy = options.show_stop_hierarchy writer.Write(feed, output_path)
def main(): usage = \ '''%prog [options] <input GTFS.zip> [<output.kml>] Reads GTFS file or directory <input GTFS.zip> and creates a KML file <output.kml> that contains the geographical features of the input. If <output.kml> is omitted a default filename is picked based on <input GTFS.zip>. By default the KML contains all stops and shapes. For more information see http://code.google.com/p/googletransitdatafeed/wiki/KMLWriter ''' parser = util.OptionParserLongError(usage=usage, version='%prog ' + transitfeed.__version__) parser.add_option('-t', '--showtrips', action='store_true', dest='show_trips', help='include the individual trips for each route') parser.add_option('-a', '--altitude_per_sec', action='store', type='float', dest='altitude_per_sec', help='if greater than 0 trips are drawn with time axis ' 'set to this many meters high for each second of time') parser.add_option('-s', '--splitroutes', action='store_true', dest='split_routes', help='split the routes by type') parser.add_option('-d', '--date_filter', action='store', type='string', dest='date_filter', help='Restrict to trips active on date YYYYMMDD') parser.add_option('-p', '--display_shape_points', action='store_true', dest='shape_points', help='shows the actual points along shapes') parser.set_defaults(altitude_per_sec=1.0) options, args = parser.parse_args() if len(args) < 1: parser.error('You must provide the path of an input GTFS file.') if args[0] == 'IWantMyCrash': raise Exception('For testCrashHandler') input_path = args[0] if len(args) >= 2: output_path = args[1] else: path = os.path.normpath(input_path) (feed_dir, feed) = os.path.split(path) if '.' in feed: feed = feed.rsplit('.', 1)[0] # strip extension output_filename = '%s.kml' % feed output_path = os.path.join(feed_dir, output_filename) loader = transitfeed.Loader(input_path, problems=transitfeed.ProblemReporter()) feed = loader.Load() print "Writing %s" % output_path writer = KMLWriter() writer.show_trips = options.show_trips writer.altitude_per_sec = options.altitude_per_sec writer.split_routes = options.split_routes writer.date_filter = options.date_filter writer.shape_points = options.shape_points writer.Write(feed, output_path)
def main(): usage = \ '''%prog [options] <input GTFS.zip> [<output.kml>] Reads GTFS file or directory <input GTFS.zip> and creates a KML file <output.kml> that contains the geographical features of the input. If <output.kml> is omitted a default filename is picked based on <input GTFS.zip>. By default the KML contains all stops and shapes. For more information see https://github.com/google/transitfeed/wiki/KMLWriter ''' parser = util.OptionParserLongError(usage=usage, version='%prog ' + transitfeed.__version__) parser.add_option('-t', '--showtrips', action='store_true', dest='show_trips', help='include the individual trips for each route') parser.add_option('-a', '--altitude_per_sec', action='store', type='float', dest='altitude_per_sec', help='if greater than 0 trips are drawn with time axis ' 'set to this many meters high for each second of time') parser.add_option('-s', '--splitroutes', action='store_true', dest='split_routes', help='split the routes by type') parser.add_option('-d', '--date_filter', action='store', type='string', dest='date_filter', help='Restrict to trips active on date YYYYMMDD') parser.add_option('-p', '--display_shape_points', action='store_true', dest='shape_points', help='shows the actual points along shapes') parser.add_option('--show_stop_hierarchy', action='store_true', dest='show_stop_hierarchy', help='include station-stop hierarchy info in output') parser.set_defaults(altitude_per_sec=1.0) options, args = parser.parse_args() if len(args) < 1: parser.error('You must provide the path of an input GTFS file.') if args[0] == 'IWantMyCrash': raise Exception('For testCrashHandler') input_path = args[0] if len(args) >= 2: output_path = args[1] else: path = os.path.normpath(input_path) (feed_dir, feed_name) = os.path.split(path) if '.' in feed_name: feed_name = feed_name.rsplit('.', 1)[0] # strip extension output_filename = '%s.kml' % feed_name output_path = os.path.join(feed_dir, output_filename) feed = None try: loader = transitfeed.Loader(input_path) feed = loader.Load() except transitfeed.ExceptionWithContext as e: print >> sys.stderr, ( "\n\nGTFS feed must load without any errors.\n" "While loading %s the following error was found:\n%s\n%s\n" % (input_path, e.FormatContext(), transitfeed.EncodeUnicode(e.FormatProblem()))) sys.exit(1) print "Writing %s" % output_path writer = KMLWriter() writer.show_trips = options.show_trips writer.altitude_per_sec = options.altitude_per_sec writer.split_routes = options.split_routes writer.date_filter = options.date_filter writer.shape_points = options.shape_points writer.show_stop_hierarchy = options.show_stop_hierarchy writer.Write(feed, output_path)
def ParseCommandLineArguments(): usage = \ '''%prog [options] [<input GTFS.zip>] Validates GTFS file (or directory) <input GTFS.zip> and writes a HTML report of the results to validation-results.html. If <input GTFS.zip> is omitted the filename is read from the console. Dragging a file into the console may enter the filename. For more information see https://github.com/google/transitfeed/wiki/FeedValidator ''' parser = util.OptionParserLongError(usage=usage, version='%prog ' + transitfeed.__version__) parser.add_option('-n', '--noprompt', action='store_false', dest='manual_entry', help='do not prompt for feed location or load output in ' 'browser') parser.add_option('-o', '--output', dest='output', metavar='FILE', help='write html output to FILE or --output=CONSOLE to ' 'print all errors and warnings to the command console') parser.add_option('-p', '--performance', action='store_true', dest='performance', help='output memory and time performance (Availability: ' 'Unix') parser.add_option( '-m', '--memory_db', dest='memory_db', action='store_true', help='Use in-memory sqlite db instead of a temporary file. ' 'It is faster but uses more RAM.') parser.add_option( '-d', '--duplicate_trip_check', dest='check_duplicate_trips', action='store_true', help='Check for duplicate trips which go through the same ' 'stops with same service and start times') parser.add_option('-l', '--limit_per_type', dest='limit_per_type', action='store', type='int', help='Maximum number of errors and warnings to keep of ' 'each type') parser.add_option( '--latest_version', dest='latest_version', action='store', help='a version number such as 1.2.1 or None to get the ' 'latest version from the project site. Output a warning if ' 'transitfeed.py is older than this version.') parser.add_option( '--service_gap_interval', dest='service_gap_interval', action='store', type='int', help='the number of consecutive days to search for with no ' 'scheduled service. For each interval with no service ' 'having this number of days or more a warning will be ' 'issued') parser.add_option( '--extension', dest='extension', help='the name of the Python module that containts a GTFS ' 'extension that is to be loaded and used while validating ' 'the specified feed.') parser.add_option( '--error_types_ignore_list', dest='error_types_ignore_list', help='a comma-separated list of error and warning type ' 'names to be ignored during validation (e.g. ' '"ExpirationDate,UnusedStop"). Bad error type names will ' 'be silently ignored!') parser.set_defaults(manual_entry=True, output='validation-results.html', memory_db=False, check_duplicate_trips=False, limit_per_type=5, latest_version='', service_gap_interval=13) (options, args) = parser.parse_args() if not len(args) == 1: if options.manual_entry: feed = input('Enter Feed Location: ') else: parser.error('You must provide the path of a single feed') else: feed = args[0] feed = feed.strip('"') # transform options.error_types_ignore_list into a valid list if options.error_types_ignore_list: options.error_types_ignore_list = options.error_types_ignore_list.split( ',') else: options.error_types_ignore_list = None return (feed, options)
def main(): usage = \ '''%prog [options] <GTFS.zip> Sets the trip_type for trips that have an unusual pattern for a route. <GTFS.zip> is overwritten with the modifed GTFS file unless the --output option is used. For more information see https://github.com/google/transitfeed/wiki/UnusualTripFilter ''' parser = util.OptionParserLongError(usage=usage, version='%prog ' + transitfeed.__version__) parser.add_option( '-o', '--output', dest='output', metavar='FILE', help='Name of the output GTFS file (writing to input feed if omitted).' ) parser.add_option('-m', '--memory_db', dest='memory_db', action='store_true', help='Force use of in-memory sqlite db.') parser.add_option( '-t', '--threshold', default=0.1, dest='threshold', type='float', help='Frequency threshold for considering pattern as non-regular.') parser.add_option('-r', '--route_type', default=None, dest='route_type', type='string', help='Filter only selected route type (specified by number' 'or one of the following names: ' + \ ', '.join(transitfeed.Route._ROUTE_TYPE_NAMES) + ').') parser.add_option('-f', '--override_trip_type', default=False, dest='override_trip_type', action='store_true', help='Forces overwrite of current trip_type values.') parser.add_option('-q', '--quiet', dest='quiet', default=False, action='store_true', help='Suppress information output.') (options, args) = parser.parse_args() if len(args) != 1: parser.error('You must provide the path of a single feed.') filter = UnusualTripFilter(float(options.threshold), force=options.override_trip_type, quiet=options.quiet, route_type=options.route_type) feed_name = args[0] feed_name = feed_name.strip() filter.info('Loading %s' % feed_name) loader = transitfeed.Loader(feed_name, extra_validation=True, memory_db=options.memory_db) data = loader.Load() filter.filter(data) print 'Saving data' # Write the result if options.output is None: data.WriteGoogleTransitFeed(feed_name) else: data.WriteGoogleTransitFeed(options.output)