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