forked from flatplanet/Intro-To-TKinter-Youtube-Course
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweather.py
56 lines (42 loc) · 1.65 KB
/
weather.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
from tkinter import *
from PIL import ImageTk,Image
import requests
import json
root = Tk()
root.title('Codemy.com - Learn To Code!')
root.iconbitmap('c:/gui/codemy.ico')
root.geometry("600x100")
#Create Zipcode Lookup Function
def zipLookup():
#zip.get()
#zipLabel = Label(root, text=zip.get())
#zipLabel.grid(row=1, column=0, columnspan=2)
try:
api_request = requests.get("http://www.airnowapi.org/aq/observation/zipCode/current/?format=application/json&zipCode=" + zip.get() + "&distance=5&API_KEY=96A38DFD-5C56-4740-AD99-E38C0C855A1B")
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 == "Unhealthy":
weather_color = "#FF0000"
elif category == "Very Unhealthy":
weather_color = "#990066"
elif category == "Hazardous":
weather_color = "#660000"
root.configure(background=weather_color)
myLabel = Label(root, text=city + " Air Quality " + str(quality) + " " + category, font=("Helvetica", 20), background=weather_color)
myLabel.grid(row=1, column=0, columnspan=2)
except Exception as e:
api = "Error..."
# http://www.airnowapi.org/aq/observation/zipCode/current/?format=application/json&zipCode=89129&distance=5&API_KEY=96A38DFD-5C56-4740-AD99-E38C0C855A1B
zip = Entry(root)
zip.grid(row=0, column=0, sticky=W+E+N+S)
zipButton = Button(root, text="Lookup Zipcode", command=zipLookup)
zipButton.grid(row=0, column=1, sticky=W+E+N+S)
root.mainloop()