def handle_route_run(agency_id, route_id, run_id):
    route_config = nextbus.get_route_config(agency_id, route_id)
    for nb_d in route_config.directions:
        if nb_d.tag == run_id:
            return model.RunOnRoute.from_nextbus(nb_d)
    from proximobus import service
    raise service.NotFoundError()
def handle_route_stop(agency_id, route_id, stop_id):
    route_config = nextbus.get_route_config(agency_id, route_id)
    for nb_s in route_config.stops:
        if nb_s.tag == stop_id:
            return model.StopOnRoute.from_nextbus(nb_s)
    from proximobus import service
    raise service.NotFoundError()
def get_all_directions(route_tag):
    route = nextbus.get_route_config('sf-muni',route_tag)
    directions = route.directions
    dir = []
    for each in directions:
        dir_dict = {}
        dir_dict['tag'], dir_dict['title'] = each.tag, each.title
        dir.append(dir_dict)
    return dir
def get_all_stops(route_tag, direction_tag):
    route = nextbus.get_route_config('sf-muni', route_tag)
    directions = route.directions
    stop_list = []
    for each in directions:
        if each.tag == direction_tag:
            stops = each.stops
            for stop in stops:
                stop_dict = {}
                stop_dict['tag'] = stop.tag
                stop_dict['title'] = stop.title
                stop_dict['stop_id'] = stop.stop_id
                stop_list.append(stop_dict)
    return stop_list
def handle_route_run_stops(agency_id, route_id, run_id):
    route_config = nextbus.get_route_config(agency_id, route_id)
    stops = map(lambda nb_s: model.StopOnRoute.from_nextbus(nb_s), route_config.directions_dict[run_id].stops)
    return model.List(ObjectField(model.Stop))(stops)
def handle_route_runs(agency_id, route_id):
    route_config = nextbus.get_route_config(agency_id, route_id)
    runs = map(lambda nb_d: model.RunOnRoute.from_nextbus(nb_d), route_config.directions)
    return model.List(ObjectField(model.RunOnRoute))(runs)
def handle_route(agency_id, route_id):
    route_config = nextbus.get_route_config(agency_id, route_id)
    return model.Route.from_nextbus(route_config)