Skip to content

Instantly share code, notes, and snippets.

@donlovett
Created September 25, 2016 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donlovett/3de442d5dbeae98fe5f16aec302bb33f to your computer and use it in GitHub Desktop.
Save donlovett/3de442d5dbeae98fe5f16aec302bb33f to your computer and use it in GitHub Desktop.
Final As Submitted
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'
mycounter = 0
mysum = 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"]
sumcount = int(item["count"])+ 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