-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
36 lines (27 loc) · 1012 Bytes
/
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
from flask import Flask,render_template,url_for,redirect,session,request
import requests
app=Flask(__name__)
@app.route("/",methods=['GET','POST'])
def home():
try:
name = request.form.get("just")
if name:
url='https://api.openweathermap.org/data/2.5/weather?q={}&appid=43ee602cd3f013c1a0c2fa793155236e'.format(name)
else:
url='https://api.openweathermap.org/data/2.5/weather?q=mumbai&appid=43ee602cd3f013c1a0c2fa793155236e'
whether=requests.get(url).json()
wl=[]
whe={
'description':whether['weather'][0]['description'],
'name':whether['name'],
'temp':whether['main']['temp'],
'humidity':whether['main']['humidity'],
'speed':whether['wind']['speed'],
'country':whether['sys']['country']
}
wl.append(whe)
except Exception as e:
print(e)
return render_template("home.html",title="home",name=wl)
if __name__ == "__main__":
app.run(debug=True)