Skip to content

Instantly share code, notes, and snippets.

@openfly
Created May 1, 2015 00:18
Show Gist options
  • Save openfly/c3de543a06820567f502 to your computer and use it in GitHub Desktop.
Save openfly/c3de543a06820567f502 to your computer and use it in GitHub Desktop.
def acquire_comments(username, imgur_client):
count = count_comments(username, imgur_client)
if ( count > 0):
print "count of commentary is %s" % count
pages = int(count / 50)
finger = 0
f = codecs.open(username + ".csv", encoding='utf-8', mode='w+')
while ( finger < pages ):
header= {"Content-Type": "text", "Authorization": "Client-ID " + imgur_client}
r = requests.get("https://api.imgur.com/3/account/" + username + "/comments/newest/" + str(finger) + ".json", headers=header)
comments = json.loads(r.text)
for comment in comments['data']:
#pprint.pprint( comment, indent=4 )
string = comment['comment']
datetime = comment['datetime']
points = comment['points']
imageid = comment['image_id']
outputline = "%s, %s, %s, %s, %s\n" % (username, imageid, datetime, points, string)
f.write(outputline)
finger += 1
f.seek(0)
print repr(f.readline()[:1])
f.close()
else:
print "%s has no commentary... must be the gruqq =(\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment