Skip to content

Commit ad66c94

Browse files
Add files via upload
1 parent 7f864a7 commit ad66c94

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# prompt for a URL, read the JSON data from that URL using urllib and then parse
2+
# and extract the comment counts from the JSON data, compute the sum of the
3+
# numbers in the file
4+
import urllib.request, urllib.parse,urllib.error
5+
import json
6+
import ssl
7+
8+
#ignore cert
9+
ctx=ssl.create_default_context()
10+
ctx.check_hostname=False
11+
ctx.verify_mode=ssl.CERT_NONE
12+
13+
url=input('Enter URL: ')
14+
if len(url)<1:
15+
url='http://py4e-data.dr-chuck.net/comments_42.json'
16+
fhand=urllib.request.urlopen(url,context=ctx).read().decode()
17+
formattedJson=json.loads(fhand)
18+
countNum=list()
19+
20+
for counts in formattedJson['comments']:
21+
countNum.append(counts['count'])
22+
print(countNum)
23+
print(sum(countNum))

0 commit comments

Comments
 (0)