Ejemplo n.º 1
0
def handle_stop_messages(agency_id, stop_id):
    nb_preds = nextbus.get_predictions_for_stop(agency_id, stop_id)

    if nb_preds.stop_title is None:
        return None

    return model.List(PrimitiveField(str))(nb_preds.messages)
Ejemplo n.º 2
0
def get_predictions_for_stop(stop_id, route_tag):
    predictions = nextbus.get_predictions_for_stop('sf-muni',stop_id)

    list_prediction = []
    for prediction in predictions.predictions:
        if prediction.direction.route.tag == route_tag:
            list_prediction.append(prediction)
    return list_prediction
Ejemplo n.º 3
0
def json_get_predictions_for_stop(stop_id, route_tag):
    predictions = nextbus.get_predictions_for_stop('sf-muni',stop_id)
    list_prediction = []
    for prediction in predictions.predictions:
        list_prediction.append(prediction.minutes)
    dict = {}
    dict['predictions'] = list_prediction
    return dict
Ejemplo n.º 4
0
def check_for_busses(stopID, route_tag, minutes_away):
    predictions = nextbus.get_predictions_for_stop('sf-muni', stopID)
    checked_predictions = []
    x = 0
    for prediction in predictions.predictions:
        if prediction.direction.route.tag == route_tag and x < 3:
            checked_predictions.append(prediction)
            x += 1
    return checked_predictions
Ejemplo n.º 5
0
def handle_single_stop(agency_id, stop_id):
    nb_preds = nextbus.get_predictions_for_stop(agency_id, stop_id)
    ret = model.StopRef()
    ret.display_name = nb_preds.stop_title
    ret.id = stop_id
    if ret.display_name is not None:
        return ret
    else:
        return None
Ejemplo n.º 6
0
def handle_stop_routes(agency_id, stop_id):
    nb_preds = nextbus.get_predictions_for_stop(agency_id, stop_id)

    if nb_preds.stop_title is None:
        return None

    nb_routes = {}
    for nb_d in nb_preds.directions:
        nb_routes[nb_d.route.tag] = nb_d.route

    routes = map(lambda nb_r: model.RouteRef.from_nextbus(nb_r), nb_routes.values())

    return model.List(ObjectField(model.RouteRef))(routes)
def check_for_busses(stopID, route_tag, minutes_away):
	predictions = nextbus.get_predictions_for_stop('sf-muni', stopID)
	checked_predictions = []
	
	# if prediction is within fifteen minutes from now, add it to checked_predictions
	if prediction.minutes <= int(minutes_away) and prediction.direction.route.tag == route_tag:
		x = 0
		while x < 3:

			for prediction in predictions.predictions:
				if prediction.route.tag == route_tag:
					checked_predictions.append(prediction)
					x += 1
	return checked_predictions
Ejemplo n.º 8
0
def handle_stop_predictions(agency_id, stop_id, route_id=None):
    nb_preds = nextbus.get_predictions_for_stop(agency_id, stop_id)

    if nb_preds.stop_title is None:
        return None

    if route_id is not None:
        nb_preds = filter(lambda nb_p: nb_p.direction.route.tag == route_id, nb_preds.predictions)
    else:
        nb_preds = nb_preds.predictions

    predictions = map(lambda nb_p: model.Prediction.from_nextbus(nb_p), nb_preds)

    return model.List(ObjectField(model.Prediction))(predictions)