def api_airport_details(code): try: ap = Airport.get(Airport.code == code.upper()) except: return api_json_error('No such airport found') return api_json_response(create_airport_data(ap, with_flights=True))
def api_current_planes(): data = [] for plane in Plane.select(): details = {} flying, coordinates, code = plane.current_position() details = { 'name': plane.alias, 'manufacturer': plane.manufacturer, 'aircraft': plane.aircraft, 'registration': plane.registration, 'situation': 'IN-FLIGHT' if flying else 'ON-GROUND', 'current_coordinates': { 'lat': coordinates[0], 'lon': coordinates[1], 'map': url_for('static', filename='imgs/flightmap.png'), 'flight' if flying else 'airport': code, }, 'details': url_for('api_plane_details', registration=plane.registration), } data.append(details) return api_json_response(data)
def api_flight_details(flight_number): try: ra = RouteAssignment.get_by_flight_number(flight_number.upper()) except: return api_json_error('No such flight found') data = create_route_assignment_data(ra, flight_number=False) data.update({'flight_number': flight_number.upper()}) return api_json_response(data=data)
def api_plane_details(registration): try: plane = Plane.get(Plane.registration == registration.upper()) except: return api_json_error('No such plane found') flying, coordinates, code = plane.current_position() data = { 'registration': plane.registration, 'name': plane.alias, 'aircraft': plane.aircraft, 'manufacturer': plane.manufacturer, 'crew': { 'pilots': plane.pilots, 'flight_attendants': plane.layout.flight_attendants, 'total': plane.layout.flight_attendants + plane.pilots, }, 'passangers': { 'economy': plane.layout.economy_class, 'business': plane.layout.business_class, 'first': plane.layout.first_class, 'total': plane.layout.economy_class + plane.layout.business_class + plane.layout.first_class, }, 'imgs': { 'cabin': url_for('static', filename='imgs/layout/%s' % plane.layout.picture), 'livery': url_for('static', filename='imgs/planes/%s' % plane.picture), }, 'situation': 'IN-FLIGHT' if flying else 'ON-GROUND', 'current_coordinates': { 'lat': coordinates[0], 'lon': coordinates[1], 'map': url_for('gallery_live_map'), 'flight' if flying else 'airport': code, } } return api_json_response(data)
def api_airports(): data = [] for ap in Airport.select(): data.append(create_airport_data(ap, with_flights=False)) return api_json_response(data)