service.py

changeset 134
4ac0f2e2ec4e
parent 127
2bc0529d44a5
child 136
27324a81beca
equal deleted inserted replaced
133:091a48867bae 134:4ac0f2e2ec4e
209 'route-splice': split_route_ref(route_ref), 209 'route-splice': split_route_ref(route_ref),
210 'sign': sign(schedule_entry), 210 'sign': sign(schedule_entry),
211 'trip': schedule_entry['stop'].trip.name, 211 'trip': schedule_entry['stop'].trip.name,
212 'night': is_night_time(schedule_entry['time']), 212 'night': is_night_time(schedule_entry['time']),
213 'imminent': imminent(schedule_entry), 213 'imminent': imminent(schedule_entry),
214 'id': str(schedule_entry['stop'].uuid), 214 'id': str(schedule_entry['stop'].primary_key),
215 'gone': schedule_entry['gone'], 215 'gone': schedule_entry['gone'],
216 }) 216 })
217 return render_template( 217 return render_template(
218 'stop.html', 218 'stop.html',
219 schedule = schedule, 219 schedule = schedule,
447 abort(404) 447 abort(404)
448 return jsonify({ 448 return jsonify({
449 'abbreviation': trip_abbreviation(trip), 449 'abbreviation': trip_abbreviation(trip),
450 }) 450 })
451 451
452
453 def service_start_time(): 452 def service_start_time():
454 from datetime import date, datetime, timedelta 453 from datetime import date, datetime, timedelta
455 result = datetime.now().replace(hour = 0, minute = 0, second = 0, microsecond = 0) 454 result = datetime.now().replace(hour = 0, minute = 0, second = 0, microsecond = 0)
456 if datetime.now().hour < 4: 455 if datetime.now().hour < 4:
457 result -= timedelta(1) 456 result -= timedelta(1)
458 return result 457 return result
459
460 @app.route('/find_halt/<stop_reference>/<blockref>/<int:originalaimeddeparturetime>')
461 def find_halt(stop_reference, blockref, originalaimeddeparturetime):
462 from datetime import datetime
463 from flask import jsonify
464 info = (blockref, datetime.fromtimestamp(originalaimeddeparturetime) - service_start_time())
465 trip = buses.trips_by_vehicle_info[info]
466 try:
467 return jsonify({
468 'id': [str(halt.uuid) for halt in buses.trips_by_vehicle_info[info].schedule if halt.stop.reference == stop_reference][0],
469 })
470 except:
471 abort(404)
472
473 458
474 def current_bus_day(): 459 def current_bus_day():
475 from datetime import date, datetime, timedelta 460 from datetime import date, datetime, timedelta
476 day = date.today() 461 day = date.today()
477 if datetime.now().hour < 5: 462 if datetime.now().hour < 5:

mercurial