-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
36 lines (27 loc) · 1.37 KB
/
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
#make a virtual envirnment and install all the module
#import the flask module
from flask import Flask,render_template,request
import requests
app = Flask(__name__)
#make a route and render all the html templates in this route
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
city_name = request.form.get('city')
#take a variable to show the json data
r = requests.get('https://api.openweathermap.org/data/2.5/weather?q='+city_name+'&appid=cbf1b9f6f3127d65b15aa57c0cd3d28a')
#read the json object
json_object = r.json()
#take some attributes like temperature,humidity,pressure of this
temperature = int(json_object['main']['temp']-273.15) #this temparetuure in kelvin
humidity = int(json_object['main']['humidity'])
pressure = int(json_object['main']['pressure'])
wind = int(json_object['wind']['speed'])
#atlast just pass the variables
condition = json_object['weather'][0]['main']
desc = json_object['weather'][0]['description']
return render_template('home.html',temperature=temperature,pressure=pressure,humidity=humidity,city_name=city_name,condition=condition,wind=wind,desc=desc)
else:
return render_template('home.html')
if __name__ == '__main__':
app.run(debug=True)