Skip to content

Instantly share code, notes, and snippets.

@charlesvestal
Created July 25, 2014 00:55
Show Gist options
  • Select an option

  • Save charlesvestal/e6913c01a613a1a01ff5 to your computer and use it in GitHub Desktop.

Select an option

Save charlesvestal/e6913c01a613a1a01ff5 to your computer and use it in GitHub Desktop.
# script to retrieve and calculate total up and down votes for an image and its comments.
# download the json by appending .json to the imgur gallery URL, i.e. http://imgur.com/gallery/SQRELN4 becomes #http://imgur.com/gallery/SQRELN4.json
# using local files because imgur returns different data for non-browsers.
import urllib2
import json
f = open("fIWYSVs.json","rb") #replace with actual image's json
#TODO: retrieve json directly with user-agent spoof
#TODO: prompt for image URL
json = json.loads(f.read())
captionUps = 0
captionDowns = 0
sumImageUps = 0
sumimageUps = 0
for caption in json['data']['captions']:
tempVotes = int(caption['ups'])
captionUps += tempVotes
for caption in json['data']['captions']:
tempVotes = int(caption['downs'])
captionDowns += tempVotes
imageUps = json['data']['image']['ups']
imageDowns = json['data']['image']['downs']
print "Image Upvotes: %s" % imageUps
print "Image Downvotes: %s" % imageDowns
print "Caption Upvotes: %s" % captionUps
print "Caption Downvotes: %s" % captionDowns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment