-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
146 lines (112 loc) · 4.07 KB
/
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
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
from flask import Flask,render_template,request
from bs4 import BeautifulSoup
import requests
import xmltodict
import json
import os
from flask_googlemaps import GoogleMaps, Map, icons
app = Flask(__name__)
GoogleMaps(app)
keylist = []
valuelist = []
dictkeyslist = []
latitude = '37.4300'
longitude = '-122.1400'
parcelid = ''
owner = ''
state = ''
zip = ''
street = ''
#Function to convert XML response to JSON
def printallkeys(json_object):
global keylist
global valuelist,street,state,zip
global dictkeyslist,longitude,latitude,parcelid,owner
for key,value in json_object.items():
if type(value) is dict:
keylist.append((key,None))
if key == 'LATITUDE':
latitude = value['value']
print(latitude)
if key == 'LONGITUDE':
longitude = value['value']
print(longitude)
if key == "towner":
owner = value['value']
if key == "MAIL_STREET_SUFFIX":
street = value['value']
if key == "MAIL_STATE":
state = value['value']
if key == "MAIL_ZIPCODE":
zip = value['value']
printallkeys(value)
else:
if type(value) is not list:
if key == 'id':
parcelid = value
if value == None:
value = 'N/A'
keylist.append((key,value))
if type(value) is list:
for i in value:
keylist.append((key,None))
printallkeys(i)
return keylist
#Create Google Map with the specified latitude and longitude
def map_view(latitude,longitude):
global parcelid
Idinfo = 'ID:'+ parcelid
gmap = Map(
identifier="gmap",
varname="gmap",
lat=latitude,
lng=longitude,
markers=[{
'icon': 'http://maps.google.com/mapfiles/ms/icons/green-dot.png',
'lat': latitude,
'lng': longitude,
'infobox': "<p>"+Idinfo+"</p>" "<p>"+'Owner:' + owner + "</p>""<p>"+'Street:' + street +"</p>""<p>"+'State:' + state +"</p>""<p>"+'Zip:' + zip +"</p>"
}],
style="height:100%;width:100%;margin:0;background-color:black;",
)
return gmap
#Route for Landing page
@app.route("/")
def hello():
gmap = map_view(latitude,longitude)
return render_template("map.html",gmap=gmap)
#Route for get the parcel info
@app.route("/getParcelInfo", methods=['GET','POST'])
def handle_parcel():
global keylist,valuelist,dictkeyslist,longitude,latitude
keylist = []
valuelist = []
endPoint = "http://neocando.case.edu/cando/housingReport/lbxml.jsp?parcel="
save_path_file = os.path.join(os.path.curdir, 'result.xml')
xml_str = ""
parcelId = request.form['options']
endpoint = endPoint + parcelId
result = requests.get(endpoint)
for line in result.text:
if line != "<?xmlversion='1.0'?>":
line = line.strip()
xml_str += line
else:
xml_str += line
with open(save_path_file, "w") as f:
f.write(BeautifulSoup(xml_str, "xml").prettify())
with open(os.path.join(os.path.curdir, 'result.xml')) as fd:
doc = xmltodict.parse(fd.read())
json_data = json.dumps(doc)
with open(os.path.join(os.path.curdir, 'data.json'), "w") as json_file:
json_file.write(json_data)
json_file.close()
with open(os.path.join(os.path.curdir, 'data.json'), 'r') as json_file:
json_object = json.load(json_file)
list1= printallkeys(json_object)
imagesource = parcelid + ".jpg"
#Create Google Map
gmap = map_view(latitude,longitude)
return render_template("map.html",heading="Parcel Info",mapheader="Location of the parcel",imagesource=imagesource,keyslist=list1,gmap=gmap)
if __name__ == "__main__":
app.run(debug=True)