-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHw1
44 lines (37 loc) · 1.28 KB
/
Hw1
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
from flask import Flask
import requests
app = Flask(__name__)
@app.route('/')
def hello():
return 'Hello World!'
@app.route('/weather/<city>')
def weather(city):
w_secret = '6368c4e70cebc7526b160d4ad081ff3b'
w_url = 'http://api.openweathermap.org/data/2.5/weather'
w_params = {'q': city, 'units': 'metric', 'appid': w_secret}
w_response = requests.get(url = w_url, params = w_params)
g_secret = 'aAORJ8KC9ReEXOTjPtKUFK2YKEnscxEi'
g_url = 'http://api.giphy.com/v1/gifs/random'
temp = float(w_response.json()['main']['temp'])
print('TEMP = ' + str(temp))
if temp >= 20:
print("over 20")
g_tag = 'fire'
color = 'red'
if 10 <= temp < 20:
print("nice weather")
g_tag = 'sunny weather'
color = 'yellow'
if 5 <= temp < 10:
print("cool weather")
g_tag = 'rain'
color = 'blue'
if temp < 5:
print("below 5")
g_tag = 'frozen snow'
color = 'white'
g_params = {'api_key': g_secret, 'tag': g_tag, 'random_id': 'e826c9fc5c929e0d6c6d423841a282aa', 'rating': 'g'}
g_response = requests.get(url=g_url, params=g_params)
return "<body style=\"background-color:black;\"> <p style=\"color:" + color + ";\">" + "Temp in " + city + " is " + str(temp) + "</p>" + "<img src=" + str(g_response.json()['data']['images']['downsized']['url']) + "></body>"
if __name__ == "__main__":
app.run()