Created
February 11, 2012 04:29
-
-
Save tomkel/1796170 to your computer and use it in GitHub Desktop.
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.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