Created
September 25, 2016 06:44
-
-
Save donlovett/52992f1904b30cd5b1f5afacbe1a87be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib | |
import json | |
# step 1 determine file to read from the web | |
# #url = raw_input('Enter file: ') | |
#url = 'http://python-data.dr-chuck.net/comments_42.json' | |
#url = 'http://python-data.dr-chuck.net/comments_318174.json' | |
url = 'http://64.137.250.177/comments_318174.json' | |
mycounter = 0 | |
mysum = 0 | |
countval = 0 | |
# step 2 read web info into a dictionary | |
while True: | |
print 'Retrieving', url | |
uh = urllib.urlopen(url) | |
input = uh.read() | |
#print 'Retrieved',len(input),'characters' | |
print input | |
break | |
print 'finished reading data from web' | |
#step 3 load into a dictionary | |
#print 'comments:',info2["name"]["count"] | |
info = json.loads(input) | |
print 'note:',info["note"] | |
print 'comments:', info["comments"] # [{"name"}] | |
#Step 4 Evaluate and sum counts | |
print 'User count:', len(info) | |
#info = json.loads(info) | |
info2 = [] | |
info2 = info['comments'] | |
itemcount = len(info2) | |
sumcount = 0 | |
print 'User count:', itemcount | |
print 'print info 2 here: ',info2 | |
for item in info2: | |
#print 'Name', item['name'] | |
#print 'Count of Names', item['count'] | |
#print 'comments:', info["comments"][0]["comment"] | |
print 'item: ',item | |
#print 'name:', info2["comments"][0]["name"] | |
print 'values = ', item["count"] | |
countval = int(item["count"]) | |
sumcount = int(item["count"])+ sumcount | |
print countval, sumcount | |
continue | |
print sumcount | |
print 'End of Program' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment