-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassign1.py
60 lines (51 loc) · 2 KB
/
assign1.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
from flask import Flask,render_template,request, redirect,jsonify
import requests
import time
app=Flask(
__name__,
template_folder="templates",
static_folder="static"
)
def getwea(city):
url="http://api.openweathermap.org/data/2.5/weather?q="+ city +"&appid=7897a76f5dcea3f90e8f56433b91c980"
json_response=requests.get(url).json()
#print (json_response)
wea_desc=json_response["weather"][0]["description"]
temp=json_response["main"]["temp"]
return{"description":wea_desc,"temp":temp}
@app.route("/api/weather",methods=['GET'])
def weather():
city=request.args.get("city")
print(city)
weat=getwea(city)
print("inside api")
return jsonify(weat)
@app.route("/",methods=['GET','POST'])
def gweather():
return render_template("weather.html")
# @app.route("/in",methods =['POST', 'GET'])
# def weather():
# location = request.form['city']
# if request.method == 'POST':
# row=get(location)
# print(row)
# if len(row)==0:
# details=getwea(location)
# insert(location, details['temp'], details['description'], time.time())
# return render_template("weather.html", details=details, location=location,mode="api")
# else:
# print("inside else , ")
# print(row)
# tim =row[0][2]
# if tim - time.time() >= 86400:
# details = getwea(location)
# delete(location)
# insert(location,details['temp'],details['description'],time.time())
# return render_template("weather.html", details=details, location=location, mode="replacedb")
# else:
# details1 = {'temp': row[0][0], 'description': row[0][1]}
# return render_template("weather.html", details=details1, location=location, mode="db")
# else:
# return render_template("weather.html")
if __name__=='__main__':
app.run(debug=True,port=5000)