Skip to content

Commit aee1a05

Browse files
authored
Extracting_Data_from_JSON
1 parent f1159bd commit aee1a05

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import urllib.request, urllib.parse, urllib.error
2+
import json
3+
import ssl
4+
5+
ctx = ssl.create_default_context()
6+
ctx.check_hostname = False
7+
ctx.verify_mode = ssl.CERT_NONE
8+
9+
url = input("Enter Location: ")
10+
#url = "http://py4e-data.dr-chuck.net/comments_853295.json"
11+
print("Reteriving", url)
12+
13+
uh = urllib.request.urlopen(url)
14+
data = uh.read().decode()
15+
print("Reteriving", len(data),"Characters")
16+
#print(data)
17+
18+
try:
19+
js = json.loads(data)
20+
21+
except:
22+
js = None
23+
24+
count = 0
25+
sum = 0
26+
27+
for x in js['comments']:
28+
count = count + 1
29+
sum = sum + x['count']
30+
31+
print("Count:",count)
32+
print("Sum:",sum)
33+
34+

0 commit comments

Comments
 (0)