def authenticate(flight_number, auth_hash): # TODO if app.config["APP_AUTHENTICATE_FLIGHT"]: LOG.critical("Authenticating Not Implemented") return False else: return True
def api_dumbjson(): if request.method == 'POST': LOG.info("POST request") json_request = json.dumps( request.get_json(force=False, silent=False, cache=False)) LOG.debug(json_request) socketio.emit("baloon_update", json_request, namespace="/map") return "Data sent."
def saveNewEvent(flight_number, event, data): LOG.info("Saving new Event") if not isValidEvent(data['event'], event): return False flight = service.getFlightByNumber(flight_number) time_received = int(time.time()) return service.saveNewEvent(flight, data, time_received)
def saveNewFlight(number, datetime): LOG.info("Saving new Flight") datetime = parseHTMLDateTimeToDateTime(datetime) # Parse DateTime formated by HTML input tag to Python datetime object hash = service.computeHash(number) # Compute hash for Flight flight = Flight(int(number), hash, datetime) # Create new Flight object return service.saveNewFlight(flight)
def add_flight(): if not request.method == 'POST': abort(405) if request.form['flightStartDate'] is not None and request.form[ 'flightNumber'] is not None: # flash("Flight saved.") Controller.saveNewFlight(request.form['flightNumber'], request.form['flightStartDate']) else: LOG.debug("Wrong input parameters for new Flight") return redirect(url_for('flight_administration'))
def getBalloonStart(flight_number): position = None # flight = service.getFlightByNumber(flight_number) parameter = service.getFlightFirstPosition(flight_number) if parameter is not None: position = { 'type': "start", 'point': { 'time': parameter.time_received, 'lat': parameter.valuesDict["lat"].value, 'lng': parameter.valuesDict["lng"].value } } LOG.debug("BalloonStart: ", position) return position
def getBalloonPath(flight_number): # flight = service.getFlightByNumber(flight_number) parameters = service.getFlightPath(flight_number) path = {'type': "path", 'data': {'points': []}} for p in parameters: LOG.debug(p) point = { 'time': p.time_received, 'lat': p.valuesDict["lat"].value, 'lng': p.valuesDict["lng"].value } path["data"]["points"].append(point) LOG.debug("BalloonPath: ", path) return path
def api_telemetry(flight_number): if request.method != 'POST': abort(405) json_request = request.get_json(force=False, silent=False, cache=False) if not json_request.has_key("flightHash"): abort(400) flightHash = json_request["flightHash"] if not Controller.authenticate(flight_number, flightHash): abort(401) if json_request.has_key("data"): LOG.info("Telemetry data accepted") # Controller.checkTelemetryJsonData(json_request["data"]) Controller.saveNewParameters(flight_number, json_request["data"]) # WebController.refreshSite(flight_number) # SocialController.postStatuses(altitude,timestamp) return "OK", 201
def getBalloonBurst(flight_number): position = None flight = service.getFlightByNumber(flight_number) events = service.getEventsByFlight(flight.id) for e in events: if e.type == "burst": service.fillParametersDictionary(e) parameter = e.parametersDict["position"] position = { 'type': "burst", 'point': { 'time': parameter.time_received, 'lat': parameter.valuesDict["lat"].value, 'lng': parameter.valuesDict["lng"].value } } LOG.debug("BalloonBurst: ", position) return position
def balloonDashboard(): # balloonStatus = # TODO Try/catch encode() and int() if request.args.has_key("flight"): num = request.args.get("flight") num = num.encode('ascii', 'ignore') if num.isdigit(): flight_number = int(num) LOG.debug("Custom flight number: %d", flight_number) else: LOG.debug("Custom flight number: %d - Wrong variable", num) flight_number = 42 else: flight_number = 42 if Controller.flightExists(flight_number): # TODO Error message if Flight does not exists flight_number = 42 data = {} balloonLocation = Controller.getBalloonLocation(flight_number) if balloonLocation: data['location'] = balloonLocation balloonPath = Controller.getBalloonPath(flight_number) if balloonPath: data['path'] = balloonPath balloonBurst = Controller.getBalloonBurst(flight_number) if balloonBurst: data['burst'] = balloonBurst balloonStart = Controller.getBalloonStart(flight_number) if balloonStart: data['start'] = balloonStart flightList = Controller.getFlightList() if flightList: data['flightList'] = flightList # balloonLanding = getBalloonLanding() # balloonTelemetry = getActualTelemetry() LOG.debug("Sending data: ", data) return render_template("index.html", async_mode=socketio.async_mode, balloon_data=data)
def initdb_command(): """Creates the database tables.""" init_db() LOG.info('Initialized the database.')
def balloonUpdate(): LOG.info("Client connected") emit('message', {'data': '[Server]: You have been connected.'}) global thread
def test_connect(): LOG.info("Connected.") emit('message', {'data': 'Connected to Socket'}) LOG.debug("Message sent.")
def api_test(): LOG.debug("API TEST") return "TEST", 202
# Flask imports from datetime import datetime from flask import Flask, render_template, request, url_for, current_app, jsonify, abort, redirect, flash from flask_socketio import SocketIO, emit import json # Controller from balon.controller import Controller, WebController, SocialController from balon import app, socketio, LOG, db # ----------------- IMPORTS ----------------- from balon.models.Flight import Flight LOG.debug("Starting flask app main.py") @app.route('/map') def balloonDashboard(): # balloonStatus = # TODO Try/catch encode() and int() if request.args.has_key("flight"): num = request.args.get("flight") num = num.encode('ascii', 'ignore') if num.isdigit(): flight_number = int(num) LOG.debug("Custom flight number: %d", flight_number) else: LOG.debug("Custom flight number: %d - Wrong variable", num)
def postFacebookStatus(altitude): api = getFacebookApi() LOG.info("Facebook API loaded") status = graph.put_wall_post(message=MSG_FACEBOOK.format(altitude))
def postTwitterStatus(altitude): api = getTwitterApi() LOG.info("Twitter API loaded") status = api.update_status(status=MSG_TWITTER.format(altitude))
from sqlite3 import dbapi2 as sqlite3 from balon import app, LOG from flask import g LOG.info("Database imported") def connect_db(): """Connects to the specific database.""" rv = sqlite3.connect(app.config['DATABASE']) rv.row_factory = sqlite3.Row return rv def init_db(): """Initializes the database.""" db = get_db() with app.open_resource('schema.sql', mode='r') as f: db.cursor().executescript(f.read()) db.commit() def get_db(): """Opens a new database connection if there is none yet for the current application context. """ if not hasattr(g, 'sqlite_db'): g.sqlite_db = connect_db() return g.sqlite_db