Exemple #1
0
  def test_basic(self):
    curpath = os.path.dirname(os.path.realpath(__file__))
    feedpath = os.path.join(curpath,"data/sample-feed.zip")

    fd = Feed(feedpath)
    rd = fd.get_reader( "stops.txt" )

    self.assertEqual( rd.next(), 
      {u'stop_lat': u'37.728631', u'stop_lon': 
      u'-122.431282', u'stop_url': u'', u'stop_id': 
      u'S1', u'stop_desc': 
      u'The stop is located at the southwest corner of the intersection.', 
      u'stop_name': u'Mission St. & \u9280 Ave.', u'location_type': u''})
Exemple #2
0
    def test_basic(self):
        curpath = os.path.dirname(os.path.realpath(__file__))
        feedpath = os.path.join(curpath, "data/sample-feed.zip")

        fd = Feed(feedpath)
        rd = fd.get_reader("stops.txt")

        self.assertEqual(
            rd.next(), {
                u'stop_lat': u'37.728631',
                u'stop_lon': u'-122.431282',
                u'stop_url': u'',
                u'stop_id': u'S1',
                u'stop_desc':
                u'The stop is located at the southwest corner of the intersection.',
                u'stop_name': u'Mission St. & \u9280 Ave.',
                u'location_type': u''
            })
Exemple #3
0
def load(feed_filename, db_filename=":memory:"):
    schedule = Schedule(db_filename)
    schedule.create_tables()

    schedule.engine.execute("PRAGMA synchronous=OFF")

    fd = Feed(feed_filename)

    for gtfs_class in (Agency, Route, Stop, Trip, StopTime, ServicePeriod,
                       ServiceException, Fare, FareRule, ShapePoint, Frequency,
                       Transfer):

        print "loading %s" % gtfs_class

        filename = gtfs_class.__tablename__ + ".txt"

        try:
            records = fd.get_reader(filename)

            for (i, record) in enumerate(records):
                if (i % 25000) == 0:
                    sys.stdout.write(".")
                    sys.stdout.flush()
                    schedule.session.commit()

                instance = gtfs_class(**record)
                schedule.session.add(instance)
            print
            schedule.session.commit()
        except (FileNotFoundError):
            optional_files = [
                'calendar_dates', 'fare_rules', 'frequencies', 'transfers'
            ]
            if filename in optional_files:
                print "Optional file %s not found. Continuing." % filename
                continue

    return schedule
Exemple #4
0
def load(feed_filename, connection_string=DEFAULT_CONNECTION_STRING):
    schedule = Schedule(connection_string)
    schedule.create_tables()

    schedule.engine.execute("PRAGMA synchronous=OFF")

    fd = Feed(feed_filename)

    for gtfs_class in (Agency, Route, Stop, Trip, StopTime,
                       ServicePeriod, ServiceException,
                       Fare, FareRule, ShapePoint,
                       Frequency, Transfer):

        print "loading %s" % gtfs_class

        filename = gtfs_class.__tablename__ + ".txt"

        try:
            records = fd.get_reader(filename)

            for (i, record) in enumerate(records):
                if (i % 25000) == 0:
                    sys.stdout.write(".")
                    sys.stdout.flush()
                    schedule.session.commit()

                instance = gtfs_class(**record)
                schedule.session.add(instance)
            print
            schedule.session.commit()
        except (FileNotFoundError):
            optional_files = ['calendar_dates', 'fare_rules',
                              'frequencies', 'transfers']
            if filename in optional_files:
                print "Optional file %s not found. Continuing." % filename
                continue

    return schedule