Skip to content

Instantly share code, notes, and snippets.

@tomkel
Created February 11, 2012 04:29
Show Gist options
  • Save tomkel/1796170 to your computer and use it in GitHub Desktop.
Save tomkel/1796170 to your computer and use it in GitHub Desktop.
import urllib.parse, urllib.request, json, http.cookiejar, re, sys, time
user = ''
passwd = ''
target = ''
def main():
# login
jar = http.cookiejar.CookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(jar))
data = {'user':user,'passwd':passwd,'api_type':'json'}
data = urllib.parse.urlencode(data).encode('utf-8')
response = opener.open('https://ssl.reddit.com/api/login/'+user, data)
# parse response
jso = json.loads(response.read().decode('utf-8'))["json"]["data"]
modhash = jso["modhash"]
lastid = ''
# get comments
while (True):
response = opener.open('http://www.reddit.com/user/'+target)
toSearch = str(response.read())
search = re.search('data-fullname="([^"]+)"', toSearch)
id = search.group(1)
if (id != lastid):
data = {'id':id,'dir':-1,'uh':modhash}
data = urllib.parse.urlencode(data).encode('utf-8')
response = opener.open('http://www.reddit.com/api/vote', data)
if (len(response.read()) > 5):
print(response.read())
sys.exit('bad')
lastid = id
print('downvoted',id)
time.sleep(30)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment