-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhello.py
118 lines (94 loc) · 3.27 KB
/
hello.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
from __future__ import print_function
from flask import Flask, render_template, request
from flightData import getFlightData
from parseFlights import parse_all_flights
from getAirports import get_all_airports
import json
import requests
from lxml import html
from collections import OrderedDict
import argparse
import sys
app = Flask(__name__)
#use for maps
mapKey = "AIzaSyD_3OXGut2rO_V_aH1DFxuJdaqmHtlSofU"
class airport:
def __init__(self, name, key, lat, lng):
self.name = name
self.key = key
self.lat = lat
self.lng = lng
airports = [
airport('Tallhassee International Airport', 'TIA', 30.395412, -84.3472458),
airport('Boston Logan International Airport', 'BOS', 42.3656132, -71.0117489),
airport('Test', 'Te', 37.9045286, -122.1445772)]
destination = airports
#airport_by_key = {airport.key: airport for airport in airports}
reload(sys)
sys.setdefaultencoding("utf-8")
@app.route("/")
def home():
allAirports = []
allAirports = get_all_airports()
for airportitem in allAirports:
print(airportitem[0] + " " + airportitem[1])
return render_template('home.html', airport_list = allAirports)
@app.route("/", methods = ["POST", "GET"])
def home_post():
print("hereeeeeee!!")
source = request.form['from_id']
print("Source: " + str(source))
destination = request.form['to_id']
print("Destination: " + str(destination))
date = request.form['date_id']
print("Date " + str(date))
argparser = argparse.ArgumentParser()
argparser.add_argument('source',help = 'Source airport code')
argparser.add_argument('destination',help = 'Destination airport code')
argparser.add_argument('date',help = 'MM/DD/YYYY')
print("Getting flight details")
scraped_data = getFlightData(source, destination, date)
print("Writing data to JSON file")
with open('%s-%s-flight-results.json'%(source,destination),'w') as fp:
json.dump(scraped_data,fp,indent = 4)
flight_list = parse_all_flights(scraped_data, source, destination)
allAirports = []
coords = []
allAirports = get_all_airports()
for airportitem in allAirports:
if airportitem[1] == source:
coords.append([airportitem[2], airportitem[3]])
if airportitem[1] == destination:
coords.append([airportitem[2], airportitem[3]])
return render_template('map.html', flight_list = flight_list, temp=airport, destination=coords)
@app.route("/returns/")
def returns():
allAirports = []
allAirports = get_all_airports()
for airportitem in allAirports:
print(airportitem[0] + " " + airportitem[1])
return render_template('returns.html', airport_list = allAirports)
@app.route("/source_flight/<string:flight_id>")
def itenerary(flight_id):
return render_template('itenerary.html', source_flight = flight_id)
@app.route("/test/")
def test():
return render_template('test.html', destination = airports)
@app.route('/search/')
def search():
return render_template('search.html', airports = airports)
@app.route('/search/map')
def show_route():
#airport = airport_by_key.get(airport_code)
if airport:
return render_template('map.html', destination = destination)
else:
return render_template('search.html', airports = airports)
@app.route('/about/')
def about():
return render_template('about.html')
@app.route('/information/')
def information():
return render_template('information.html')
if __name__ == "__main__":
app.run(debug=True)