-
Notifications
You must be signed in to change notification settings - Fork 179
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·32 lines (21 loc) · 872 Bytes
/
main.py
File metadata and controls
executable file
·32 lines (21 loc) · 872 Bytes
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
from flask import Flask, render_template, request
import requests
import json
import os
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == "POST":
city = request.form['city']
country = request.form['country']
api_key = os.environ["API_KEY"]
weather_url = requests.get(
f'http://api.openweathermap.org/data/2.5/weather?appid={api_key}&q={city},{country}&units=imperial')
weather_data = weather_url.json()
temp = round(weather_data["main"]["temp"])
humidity = weather_data['main']['humidity']
wind_speed = weather_data['wind']['speed']
return render_template("result.html", temp=temp, humidity=humidity, wind_speed=wind_speed, city=city)
return render_template("index.html")
if __name__ == '__main__':
app.run(debug=True)