Exemplo n.º 1
0
    def run(self):
        # Update datastore.
        self.log("===== Feed: %s =====" % self.feedid)
        feed = self.registry.feed(self.feedid)
        filename = self.filename or os.path.join(self.workdir,
                                                 '%s.zip' % feed.onestop())
        self.log("Opening: %s" % filename)
        gtfs_feed = mzgtfs.feed.Feed(filename)
        self.log("Creating Onestop Entities")
        gtfs_feed.preload()
        feed.load_gtfs(gtfs_feed, populate=False)
        if not feed.operators():
            self.log(
                "No matching operators specified in the feed registry entry. Nothing to do."
            )
            return

        # Precalculate all Onestop IDs
        for o in feed.operators():
            o._cache_onestop()

        # Compare against datastore entities and merge if possible.
        for stop in feed.stops():
            self._merge_stop(stop)

        # Upload changeset.
        self.log("Updating feed: %s" % feed.onestop())

        # Create empty changeset
        changeset = self.datastore.postjson('/api/v1/changesets',
                                            {"changeset": {
                                                "payload": {}
                                            }})
        changeset_id = changeset['id']
        self.log("Changeset ID: %s" % changeset_id)

        # Append each entity
        self._append_batch(feed.operators(), changeset_id, change_entity)
        self._append_batch(feed.routes(), changeset_id, change_entity)
        self._append_batch(feed.stops(), changeset_id, change_entity)
        if self.schedule_stop_pairs:
            self._append_batch(make_ssp(gtfs_feed), changeset_id, change_ssp)

        # Apply changeset
        self.log("Applying changeset...")
        self.datastore.postjson('/api/v1/changesets/%s/apply' % changeset_id)
        self.log("  -> ok")
        self.log("Finished!")
Exemplo n.º 2
0
  def run(self):
    # Update datastore.
    self.log("===== Feed: %s ====="%self.feedid)
    feed = self.registry.feed(self.feedid)
    filename = self.filename or os.path.join(self.workdir, '%s.zip'%feed.onestop())
    self.log("Opening: %s"%filename)
    gtfs_feed = mzgtfs.feed.Feed(filename)
    self.log("Creating Onestop Entities")
    gtfs_feed.preload()
    feed.load_gtfs(gtfs_feed, populate=False)
    if not feed.operators():
      self.log("No matching operators specified in the feed registry entry. Nothing to do.")
      return

    # Precalculate all Onestop IDs
    for o in feed.operators():
      o._cache_onestop()

    # Compare against datastore entities and merge if possible.
    for stop in feed.stops():
      self._merge_stop(stop)
      
    # Upload changeset.
    self.log("Updating feed: %s"%feed.onestop())

    # Create empty changeset
    changeset = self.datastore.postjson('/api/v1/changesets', {"changeset": {"payload": {}}} )
    changeset_id = changeset['id']
    self.log("Changeset ID: %s"%changeset_id)
    
    # Append each entity
    self._append_batch(feed.operators(), changeset_id, change_entity)  
    self._append_batch(feed.routes(), changeset_id, change_entity)  
    self._append_batch(feed.stops(), changeset_id, change_entity)  
    if self.schedule_stop_pairs:
      self._append_batch(make_ssp(gtfs_feed), changeset_id, change_ssp)

    # Apply changeset
    self.log("Applying changeset...")
    self.datastore.postjson('/api/v1/changesets/%s/apply'%changeset_id)
    self.log("  -> ok")
    self.log("Finished!")
  f = mzgtfs.feed.Feed(filename, debug=args.debug)

  # Create Transitland Feed from GTFS.
  kw = {}
  kw['debug'] = args.debug
  kw['url'] = args.url
  if args.feedname:
    kw['feedname'] = args.feedname
  feed = entities.Feed(**kw)
  feed.bootstrap_gtfs(f)
  
  # Print basic feed information.
  print "Feed:", feed.onestop()
  print "  Stops:", len(feed.stops())
  print "  Routes:", len(feed.routes())
  print "  Operators:", len(feed.operators())
  # Print basic operator information.
  for operator in feed.operators():
    print "  Operator:", operator.name()
    print "    Routes:", len(operator.routes())
    print "    Stops:", len(operator.stops())

  # Write out updated feed.
  output = args.output or '%s.json'%feed.onestop()
  data = feed.json()
  if args.printjson:
    util.json_pretty_print(data)
  if os.path.exists(output):
    print "Error: Filename %s already exists."%output
    sys.exit(1)
  else:
    f = mzgtfs.feed.Feed(filename, debug=args.debug)

    # Create Transitland Feed from GTFS.
    kw = {}
    kw['debug'] = args.debug
    kw['url'] = args.url
    if args.feedname:
        kw['feedname'] = args.feedname
    feed = entities.Feed(**kw)
    feed.bootstrap_gtfs(f)

    # Print basic feed information.
    print "Feed:", feed.onestop()
    print "  Stops:", len(feed.stops())
    print "  Routes:", len(feed.routes())
    print "  Operators:", len(feed.operators())
    # Print basic operator information.
    for operator in feed.operators():
        print "  Operator:", operator.name()
        print "    Routes:", len(operator.routes())
        print "    Stops:", len(operator.stops())

    # Write out updated feed.
    output = args.output or '%s.json' % feed.onestop()
    data = feed.json()
    if args.printjson:
        util.json_pretty_print(data)
    if os.path.exists(output):
        print "Error: Filename %s already exists." % output
        sys.exit(1)
    else: