-
Notifications
You must be signed in to change notification settings - Fork 0
/
city.py
71 lines (56 loc) · 1.55 KB
/
city.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
61
62
63
64
65
66
67
68
69
70
71
"""
This program tells you which cities are in demand and which are not.
"""
import sys
import urllib.request as ur
import json
import tkinter as tk
from tkinter import messagebox
url = 'https://www.quandl.com/api/v3/datasets/ZILLOW/C4{}_ZHVITT.json?api_key={}'
api_key = 'wborJm5zx5u4r8PS9JLy'
City = [100,102,103,105,106,107,109,110,111,113,114,115,116,117,118,120]
Data = []
cityavgs = {}
for c in City:
try:
u = ur.urlopen(url.format(c, api_key))
f = u.read().decode('utf-8')
except:
print("Something went wrong.")
sys.exit(1)
u.close()
try:
f = json.loads(f)
except:
print("Something went wrong.")
sys.exit(1)
Data.append(f)
num = len(City)
for i in range(num):
a = 0;n = []
Housing_Price_Data = Data[i]['dataset']['data']
for d,p in Housing_Price_Data:
n.append(p)
a += p
avg = int(a / len(Housing_Price_Data))
city_name = Data[i]['dataset']['name'].split('- Top Tier - ')[1]
if avg >= n[0]:
cityavgs[city_name] = "Everyone seems to want to live in "+city_name+" as prices are on the rise."
elif avg < n[0]:
cityavgs[city_name] = "Prices are low in "+city_name+". Is it a good deal? Or will it be the next Detroit?"
else:
cityavgs[city_name] = None
r=tk.Tk()
r.title("Select city")
l = tk.Frame(r)
lb = tk.Listbox(l, relief='groove')
for c, key in enumerate(cityavgs.keys()):
lb.insert(c, key)
def dia():
messagebox.showinfo("City desirability", cityavgs[lb.get(lb.curselection())])
b = tk.Button(l, text="Press me", command=dia)
b.pack(padx=10, side=tk.RIGHT)
lb.pack()
l.pack(pady=5, padx=5)
r.mainloop()
sys.exit(0)