コード例 #1
0
ファイル: api.py プロジェクト: srainier/buses-near-me
def get_departures_at_stop(stop_id):
    """
    This method returns a list of departures times for routes with departures
    from the specified stop as given by the 511.org real-time departure api
    (http://511.org/developer-resources_transit-api.asp).
    """
    stop = Stop.query.filter_by(stop_id=stop_id).first()
    if stop:
        return jsonify({'departures': departures_at_stop(stop.stop_id)})

    return jsonify({'error': 'no stop with id {0}'.format(stop_id)})
コード例 #2
0
ファイル: api.py プロジェクト: srainier/buses-near-me
def get_departures(lat, lon):
    """
    This method returns a list of departures times for routes with departures
    from stops near the specified latitude-longitude coordinates as given by
    the 511.org real-time departure api
    (http://511.org/developer-resources_transit-api.asp).
    This method can optionally specify a maximum distance (in miles) a stop can
    be from the input coordinates. If none is specified the default is 1 mile.
    """
    # This method can optionally specify a maximum distance a stop can
    # be from the input coordinates.
    distance = 1.0
    distance_list = request.args.getlist('distance')
    if 0 < len(distance_list):
        distance = float(distance_list[0])

    stops = stops_near_point(lat, lon, distance)
    if stops:
        departures = [departures_at_stop(stop['stop_id']) for stop in stops]
        return jsonify({'departures': departures})

    return jsonify({'error': 'No stops near ({0}, {1})'.format(lat, lon)})