Created
April 30, 2015 23:34
-
-
Save openfly/1577a31751ccb87bf86f to your computer and use it in GitHub Desktop.
upvote imgur automatically
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
#!/usr/bin/env python | |
import sys | |
import time | |
import json | |
import requests | |
import pprint | |
import codecs | |
imgur_client = "6091596e15cc839" | |
imgur_secret = "9bc23634db8750778l0lz2ddd210d9624d13a3e44" | |
imgur_url = "https://api.imgur.com" | |
username = "vissago" | |
def count_comments(username, imgur_client): | |
header= {"Content-Type": "text", "Authorization": "Client-ID " + imgur_client} | |
r = requests.get("https://api.imgur.com/3/account/" + username +"/comments/count.json", headers=header) | |
j = json.loads(r.text) | |
count = j['data'] | |
return count | |
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'] | |
commentid = comment['id'] | |
# https://api.imgur.com/3/comment/{id}/vote/{vote} | |
r = requests.get("https://api.imgur.com/3/comment/" + str(commentid) + "/vote/up", headers=header) | |
print "\033[32mUPVOTE\033[0m: %s : %s \n" % (commentid, string) | |
time.sleep(5) | |
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" | |
acquire_comments(username, imgur_client) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment