def ns_api(): api = NSApi(app.config['NS_AUTH_STRING']) results = api.get(FROM_STATION, TO_STATION, datetime.now()) #results = [] return render_template('edition.html', results=results, from_station=FROM_STATION, to_station=TO_STATION)
def poll_api(): with app.app_context(): api = NSApi(app.config['NS_AUTH_STRING']) for subscription_id, config in db().hgetall('train_delays:api_queue').iteritems(): user_settings = json.loads(config) today = dt.datetime.today() time_slot_begin = dt.datetime.combine(today, dt.datetime.strptime(user_settings['time_slot_begin'], '%H:%M').time()) delays = api.get(user_settings['from_station'], user_settings['to_station'], time_slot_begin) time_slot_end = dt.datetime.combine(today, dt.datetime.strptime(user_settings['time_slot_end'], '%H:%M').time()) # filter delays to match time frame delays = [d for d in delays if d['departure_actual'] <= time_slot_end.time()] if delays: send_to_printer(subscription_id, delays, user_settings)
def test(): api = NSApi(app.config['NS_AUTH_STRING']) for subscription_id, config in db().hgetall('train_delays:api_queue').iteritems(): user_settings = json.loads(config) today = datetime.today() time_slot_begin = datetime.combine(today, datetime.strptime(user_settings['time_slot_begin'], '%H:%M').time()) delays = api.get(user_settings['from_station'], user_settings['to_station'], time_slot_begin) time_slot_end = datetime.combine(today, datetime.strptime(user_settings['time_slot_end'], '%H:%M').time()) # filter delays to match time frame delays = [d for d in delays if d['departure_actual'] <= time_slot_end.time()] #if delays: print delays data = dict(results=delays, from_station=user_settings['from_station'], to_station=user_settings['to_station']) return render_edition(data)