Skip to content

Commit a229521

Browse files
Add files via upload
1 parent 412aa8a commit a229521

File tree

4 files changed

+485
-0
lines changed

4 files changed

+485
-0
lines changed

Week 5/assignmentweek5.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import urllib.request, urllib.parse, urllib.error
2+
import xml.etree.ElementTree as ET
3+
import ssl
4+
5+
#Ignore SSL certificate errors
6+
ctx = ssl.create_default_context()
7+
ctx.check_hostname = False
8+
ctx.verify_mode = ssl.CERT_NONE
9+
10+
count = 0
11+
sum = 0
12+
13+
14+
address = input('Enter location: ')
15+
16+
print('Retrieving ' + address)
17+
data = urllib.request.urlopen(address, context=ctx).read()
18+
19+
tree = ET.fromstring(data)
20+
lst = tree.findall('.//count')
21+
22+
for item in lst:
23+
count += 1
24+
sum = sum + int(item.text)
25+
26+
print('Count: ', count)
27+
print('Sum: ', sum)
28+

Week 5/data.xml

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<commentinfo>
3+
<note>This file contains the actual data for your assignment - good luck!</note>
4+
5+
<comments>
6+
<comment>
7+
<name>Avinash</name>
8+
<count>97</count>
9+
</comment>
10+
<comment>
11+
<name>Shonagh</name>
12+
<count>93</count>
13+
</comment>
14+
<comment>
15+
<name>Eidhan</name>
16+
<count>87</count>
17+
</comment>
18+
<comment>
19+
<name>Tammy</name>
20+
<count>86</count>
21+
</comment>
22+
<comment>
23+
<name>Eassan</name>
24+
<count>82</count>
25+
</comment>
26+
<comment>
27+
<name>Kaydi</name>
28+
<count>80</count>
29+
</comment>
30+
<comment>
31+
<name>Hugo</name>
32+
<count>79</count>
33+
</comment>
34+
<comment>
35+
<name>Orlah</name>
36+
<count>77</count>
37+
</comment>
38+
<comment>
39+
<name>Aidy</name>
40+
<count>77</count>
41+
</comment>
42+
<comment>
43+
<name>Maili</name>
44+
<count>74</count>
45+
</comment>
46+
<comment>
47+
<name>Malikye</name>
48+
<count>74</count>
49+
</comment>
50+
<comment>
51+
<name>Andrei</name>
52+
<count>73</count>
53+
</comment>
54+
<comment>
55+
<name>Lyla</name>
56+
<count>73</count>
57+
</comment>
58+
<comment>
59+
<name>Neshawn</name>
60+
<count>72</count>
61+
</comment>
62+
<comment>
63+
<name>Nairne</name>
64+
<count>72</count>
65+
</comment>
66+
<comment>
67+
<name>Adain</name>
68+
<count>70</count>
69+
</comment>
70+
<comment>
71+
<name>Saicu</name>
72+
<count>68</count>
73+
</comment>
74+
<comment>
75+
<name>Samira</name>
76+
<count>65</count>
77+
</comment>
78+
<comment>
79+
<name>Bob</name>
80+
<count>65</count>
81+
</comment>
82+
<comment>
83+
<name>Joelle</name>
84+
<count>65</count>
85+
</comment>
86+
<comment>
87+
<name>Ruqaiya</name>
88+
<count>60</count>
89+
</comment>
90+
<comment>
91+
<name>Nabeeha</name>
92+
<count>60</count>
93+
</comment>
94+
<comment>
95+
<name>Ericlee</name>
96+
<count>59</count>
97+
</comment>
98+
<comment>
99+
<name>Avesta</name>
100+
<count>59</count>
101+
</comment>
102+
<comment>
103+
<name>Lia</name>
104+
<count>53</count>
105+
</comment>
106+
<comment>
107+
<name>Enzo</name>
108+
<count>53</count>
109+
</comment>
110+
<comment>
111+
<name>Stacy</name>
112+
<count>49</count>
113+
</comment>
114+
<comment>
115+
<name>Indie</name>
116+
<count>47</count>
117+
</comment>
118+
<comment>
119+
<name>Dhrishti</name>
120+
<count>44</count>
121+
</comment>
122+
<comment>
123+
<name>Darl</name>
124+
<count>42</count>
125+
</comment>
126+
<comment>
127+
<name>Corey</name>
128+
<count>42</count>
129+
</comment>
130+
<comment>
131+
<name>Joris</name>
132+
<count>42</count>
133+
</comment>
134+
<comment>
135+
<name>Kali</name>
136+
<count>40</count>
137+
</comment>
138+
<comment>
139+
<name>Kaleena</name>
140+
<count>40</count>
141+
</comment>
142+
<comment>
143+
<name>Rohaan</name>
144+
<count>32</count>
145+
</comment>
146+
<comment>
147+
<name>Fendi</name>
148+
<count>27</count>
149+
</comment>
150+
<comment>
151+
<name>Emerson</name>
152+
<count>27</count>
153+
</comment>
154+
<comment>
155+
<name>Ruaidhri</name>
156+
<count>26</count>
157+
</comment>
158+
<comment>
159+
<name>Lilygrace</name>
160+
<count>20</count>
161+
</comment>
162+
<comment>
163+
<name>Cynthia</name>
164+
<count>20</count>
165+
</comment>
166+
<comment>
167+
<name>Riha</name>
168+
<count>18</count>
169+
</comment>
170+
<comment>
171+
<name>Del</name>
172+
<count>14</count>
173+
</comment>
174+
<comment>
175+
<name>Olubanke</name>
176+
<count>14</count>
177+
</comment>
178+
<comment>
179+
<name>Coray</name>
180+
<count>13</count>
181+
</comment>
182+
<comment>
183+
<name>Zachary</name>
184+
<count>13</count>
185+
</comment>
186+
<comment>
187+
<name>Maha</name>
188+
<count>9</count>
189+
</comment>
190+
<comment>
191+
<name>Innis</name>
192+
<count>4</count>
193+
</comment>
194+
<comment>
195+
<name>Eden</name>
196+
<count>2</count>
197+
</comment>
198+
<comment>
199+
<name>Titi</name>
200+
<count>2</count>
201+
</comment>
202+
<comment>
203+
<name>Isak</name>
204+
<count>2</count>
205+
</comment>
206+
</comments>
207+
</commentinfo>

Week 5/sample.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import urllib.request, urllib.parse, urllib.error
2+
import xml.etree.ElementTree as ET
3+
import ssl
4+
5+
api_key = False
6+
# If you have a Google Places API key, enter it here
7+
# api_key = 'AIzaSy___IDByT70'
8+
# https://developers.google.com/maps/documentation/geocoding/intro
9+
10+
if api_key is False:
11+
api_key = 42
12+
serviceurl = 'http://py4e-data.dr-chuck.net/xml?'
13+
else :
14+
serviceurl = 'https://maps.googleapis.com/maps/api/geocode/xml?'
15+
16+
# Ignore SSL certificate errors
17+
ctx = ssl.create_default_context()
18+
ctx.check_hostname = False
19+
ctx.verify_mode = ssl.CERT_NONE
20+
21+
while True:
22+
address = input('Enter location: ')
23+
if len(address) < 1: break
24+
25+
parms = dict()
26+
parms['address'] = address
27+
if api_key is not False: parms['key'] = api_key
28+
url = serviceurl + urllib.parse.urlencode(parms)
29+
print('Retrieving', url)
30+
uh = urllib.request.urlopen(url, context=ctx)
31+
32+
data = uh.read()
33+
print('Retrieved', len(data), 'characters')
34+
print(data.decode())
35+
tree = ET.fromstring(data)
36+
37+
results = tree.findall('result')
38+
lat = results[0].find('geometry').find('location').find('lat').text
39+
lng = results[0].find('geometry').find('location').find('lng').text
40+
location = results[0].find('formatted_address').text
41+
42+
print('lat', lat, 'lng', lng)
43+
print(location)

0 commit comments

Comments
 (0)