-
Notifications
You must be signed in to change notification settings - Fork 0
/
hackathon.py
75 lines (63 loc) · 2.29 KB
/
hackathon.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from flask import Flask, jsonify, Response
from flask.ext.restless import APIManager
from flask.ext.sqlalchemy import SQLAlchemy
from flask_admin import Admin
from flask_admin.contrib.sqla import ModelView
import os
from suds.client import Client
import logging
import datetime
import json
from flask_cors import CORS
port = os.getenv('PORT', '4999')
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db'
db = SQLAlchemy(app)
CORS(app)
admin = Admin(app, name='pingins', template_mode='bootstrap3')
app.secret_key='daahackathon'
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.TEXT)
balance = db.Column(db.REAL)
parking = db.Column(db.BOOLEAN)
checkin = db.Column(db.BOOLEAN)
security = db.Column(db.BOOLEAN)
shopping = db.Column(db.BOOLEAN)
departure = db.Column(db.BOOLEAN)
db.create_all()
admin.add_view(ModelView(User, db.session))
api_manager = APIManager(app, flask_sqlalchemy_db=db)
api_manager.create_api(User, methods=['GET', 'POST', 'DELETE', 'PUT'])
username = 'headbroken'
apiKey = '2428b712a94d4e1489340da6da32625791ad6e8d'
url = 'http://flightxml.flightaware.com/soap/FlightXML2/wsdl'
# This is a custom HTTP transport that allows Basic Authentication.
logging.basicConfig(level=logging.INFO)
api = Client(url, username=username, password=apiKey)
@app.route("/flightapi")
def hello():
# print api
# Get the weather
result = api.service.Metar('KAUS')
# Get the flights enroute
result = api.service.Scheduled('EIDW', 30, '', 0)
flights = result['scheduled']
flightlisting = []
# flightdict = {}
# flightsdict = {}
for flight in flights:
flightdict = {}
flightdict['flightnumber'] = flight['ident']
flightdict['destinationName'] =flight['destinationName']
flightdict['estimatedarrivaltime'] = flight['estimatedarrivaltime']
flightdict['filed_departuretime'] = flight['filed_departuretime']
#flightsdict[flight['ident']] = flightdict
flightlisting.append(flightdict)
# flightlisting.append(flightsdict)
resp = Response(response=json.dumps(flightlisting),
status=200,
mimetype="application/json")
return resp
if __name__ == "__main__":
app.run('0.0.0.0', port=int(port))