Example #1
0
  def directions(self):
    """Get paths followed by each direction this bus can travel

    A bus typically travels 2 directions: inbound and outbound. These paths
    need not be the same, however, and there may be alternative paths of
    travel. This function lets one enumerate all such paths.

    Returns
    -------
    directions : [Direction]
    """
    result = NextBus._fetch_xml({
      'command': 'routeConfig',
      'a': self.agency,
      'r': self.tag,
    })
    stops = [Stop(route=self.tag, **e.attrs) for e in result[0].children
             if e.tag == 'stop']
    stops = { stop.tag: stop for stop in stops }

    directions = []
    for direction in [x for x in result[0].children if x.tag == 'direction']:
      directions.append(Direction(
        route=self.tag,
        stops=[stops[str(e.attrs.tag)] for e in direction.children],
        **direction.attrs
      ))

    return directions
Example #2
0
    def routes(self):
        """All routes this agency serves

        Returns
        -------
        routes : [Route]
        """
        if (self._routes is None):
            result = NextBus._fetch_xml({
                'command': 'routeList',
                'a': self.tag,
            })
            self._routes = dict((r.tag, r) for r in [Route(agency=self.tag, **e.attrs) for e in result if e.tag == 'route'])
        return self._routes
Example #3
0
  def stops(self):
    """Get all bus stops served by this route

    Returns
    -------
    stops : [Stop]
    """
    result = NextBus._fetch_xml({
      'command': 'routeConfig',
      'a': self.agency,
      'r': self.tag,
    })
    stops = [Stop(route=self.tag, **e.attrs) for e in result[0].children
             if e.tag == 'stop']
    return stops