diff --git a/app/ogn_backend_app.py b/app/ogn_backend_app.py index 1a43b61..71eb498 100644 --- a/app/ogn_backend_app.py +++ b/app/ogn_backend_app.py @@ -16,13 +16,13 @@ app = Flask(__name__) @app.route("/rec.php") -def index(): +def rec(): sq = session.query(ReceiverBeacon.name, func.max(ReceiverBeacon.timestamp).label('lastseen')) \ .group_by(ReceiverBeacon.name) \ .subquery() last_10_minutes = datetime.utcnow() - timedelta(minutes=10) - receiver_query = session.query(ReceiverBeacon.name, ReceiverBeacon.latitude, ReceiverBeacon.longitude, case([(sq.c.lastseen>last_10_minutes, True)], else_=False).label('is_online')) \ + receiver_query = session.query(ReceiverBeacon.name, ReceiverBeacon.latitude, ReceiverBeacon.longitude, case([(sq.c.lastseen > last_10_minutes, True)], else_=False).label('is_online')) \ .filter(and_(ReceiverBeacon.name == sq.c.name, ReceiverBeacon.timestamp == sq.c.lastseen)) \ .order_by(ReceiverBeacon.name) @@ -39,21 +39,21 @@ def index(): @app.route('/lxml.php', methods=['GET', 'POST']) -def live(): - show_offline = request.args.get('a', False) +def lxml(): + show_offline = request.args.get('a', 0) == 1 lat_max = request.args.get('b', 90) lat_min = request.args.get('c', -90) lon_max = request.args.get('d', 180) lon_min = request.args.get('e', -180) if show_offline: - start_observation = date.today() + observation_start = date.today() else: - start_observation = datetime.utcnow - timedelta(minutes=5) + observation_start = datetime.utcnow() - timedelta(minutes=5) sq = session.query(AircraftBeacon.address, func.max(AircraftBeacon.timestamp).label('lastseen')) \ - .filter(and_(between(AircraftBeacon.latitude, lat_max, lat_min), between(AircraftBeacon.longitude, lon_max, lon_min))) \ - .filter(AircraftBeacon.timestamp > start_observation) \ + .filter(and_(between(AircraftBeacon.latitude, lat_min, lat_max), between(AircraftBeacon.longitude, lon_min, lon_max))) \ + .filter(AircraftBeacon.timestamp > observation_start) \ .group_by(AircraftBeacon.address) \ .subquery() @@ -65,7 +65,7 @@ def live(): lines.append('') lines.append('') - hashcode = '4711abcd' + hashcode = '4711abcd' #Todo flarm_competition = lambda flarm_object: '_' + hashcode[6:7] if flarm_object is None else flarm_object.competition flarm_registration = lambda flarm_object: hashcode if flarm_object is None else flarm_object.registration flarm_address = lambda flarm_object: 0 if flarm_object is None else flarm_object.address @@ -77,5 +77,41 @@ def live(): return Response(xml, mimetype='text/xml') +#Todo +@app.route('/livexml1.php', methods=['GET', 'POST']) +def livexml1(): + id = request.args.get('id') + l = request.args.get('l') + + lines = list() + lines.append('') + lines.append('') + lines.append('') + + lines.append(''.format(1, 'asdf', '')) + + lines.append('') + xml = '\n'.join(lines) + return Response(xml, mimetype='text/xml') + + +#Todo +@app.route('/dataxml.php', methods=['GET', 'POST']) +def dataxml(): + i = request.args.get('id') + address = request.args.get('l') + + lines = list() + lines.append('') + lines.append('') + lines.append('') + + lines.append(''.format(0, 1, 2, 3, 4, 5, 6, 7)) + + lines.append('') + xml = '\n'.join(lines) + return Response(xml, mimetype='text/xml') + + if __name__ == "__main__": app.run(debug=True)