-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweather_app.py
37 lines (25 loc) · 1.01 KB
/
weather_app.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
from flask import Flask, render_template, request
from flask_cors import CORS
from weather_controller import WeatherController
app = Flask(__name__)
CORS(app)
@app.route("/")
def index():
return render_template('index.html')
@app.route('/weather', methods=['POST', 'GET'])
def process_weather():
if request.method == 'POST':
data = request.json
input_location = data['location']
weather = WeatherController()
geo_location = weather.getLocation(input_location)
if geo_location == None:
address = "Unknown location"
report_template = render_template('reports.html', weather_address=address)
return report_template
address = geo_location.address
weather_reports = weather.getWeatherReports(data, geo_location)
report_template = render_template('reports.html', weather_address=address, weather_reports=weather_reports)
return report_template
if __name__ == '__main__':
app.run(debug=False, host='0.0.0.0')