-
Notifications
You must be signed in to change notification settings - Fork 1
/
22_change_colors_in_weather_app.py
42 lines (33 loc) · 1.27 KB
/
22_change_colors_in_weather_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
37
38
39
40
41
42
from tkinter import *
from PIL import ImageTk, Image
import requests
import json
root = Tk()
root.title("weather")
root.geometry("400x40")
# https://www.airnowapi.org/aq/observation/zipCode/current/?format=application/json&zipCode=89129&distance=5&API_KEY=C7C129A2-2532-44B6-84B8-D82F8BC20191
try:
api_request = requests.get(
"https://www.airnowapi.org/aq/observation/zipCode/current/?format=application/json&zipCode=70801&distance=5&API_KEY=C7C129A2-2532-44B6-84B8-D82F8BC20191")
api = json.loads(api_request.content)
city = api[0]['ReportingArea']
quality = api[0]['AQI']
category = api[0]['Category']['Name']
if category == "Good":
weather_color = "#0C0"
elif category == "Moderate":
weather_color = "#FFFF00"
elif category == "Unhealthy for Sensitive Groups":
weather_color = "#FF9900"
elif category == "Unheathy":
weather_color = "#FF0000"
elif category == "Very Unheathy":
weather_color = "#990066"
elif category == "Hazardous":
weather_color = '#660000'
root.configure(bg=weather_color)
my_label = Label(root, text=city+' Air Quality'+str(quality)+' '+category, font=('Helvetica', 20), bg=weather_color)
my_label.pack()
except Exception as e:
api = "Error"
root.mainloop()