Created
September 25, 2016 02:05
-
-
Save donlovett/098f2b2e7bc9a5608ee949a24c476a05 to your computer and use it in GitHub Desktop.
This is the first assignement for week 6 of the Python Data Course
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' | |
mycounter = 0 | |
mysum = 0 | |
# step 2 read web info into a dictionary | |
while True: | |
print 'Retrieving', url | |
uh = urllib.urlopen(url) | |
info = uh.read() | |
#print 'Retrieved',len(input),'characters' | |
print info | |
break | |
print 'finished reading data from web' | |
#step 3 load into a dictionary | |
#print 'comments:',info2["name"]["count"] | |
info2 = json.loads(info) | |
print 'note:',info2["note"] | |
print 'comments:', info2["comments"] # [{"name"}] | |
#Step 4 Evaluate and sum counts | |
print 'User count:', len(info) | |
info = json.loads(input) | |
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