Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import urllib2
- import urllib
- import cookielib
- import sys
- import time
- import re
- import random
- def main(username, password):
- # Define urls and variables for later
- loginURL = 'http://love2d.org/forums/ucp.php?mode=login'
- pageURL = 'http://love2d.org/forums/search.php?author_id='
- editURL = 'http://love2d.org/forums/posting.php?mode=edit&'
- cookies = []
- cookiez = cookielib.CookieJar()
- opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiez))
- urllib2.install_opener(opener)
- headers = {
- 'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 5.0; en-GB; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12',
- 'Accept': 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',
- 'Accept-Language': 'en-gb,en;q=0.5',
- 'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
- }
- # Unnecessary in most cases
- urllib2.urlopen(urllib2.Request('http://love2d.org/forums/', None, headers))
- login_headers = headers.copy()
- login_headers.update({
- 'Referer' : 'http://love2d.org/forums/',
- 'Content-Type': 'application/x-www-form-urlencoded',
- })
- html = urllib2.urlopen(urllib2.Request(loginURL,
- urllib.urlencode({
- 'referer' : 'http://love2d.org/forums/',
- 'username' : username,
- 'password' : password,
- 'autologin' : 'on',
- 'login' : 'Login',
- }),
- login_headers)).read()
- # Checks for successful log-in
- if "You have been successfully logged in." in html:
- print "You have been successfully logged in."
- print "Cookies are:"
- for cookie in cookiez:
- print cookie
- cookies.append(cookie.value)
- print cookies
- print "==========================================="
- print "=============== GATHERING ================="
- else:
- print "Log-in failed!"
- sys.exit("Failed to log-in - exiting")
- currPage = 0
- pageIDs = []
- while 1:
- # cookies[2] is your userID
- gatherPage = opener.open(pageURL + cookies[2] + '&start=' + str(currPage)).read()
- if "Sorry but you cannot use search at this time. Please try again in a few minutes." in gatherPage:
- print "Sleeping..."
- time.sleep(5)
- continue
- elif "No suitable matches were found." in gatherPage:
- print "==========================================="
- print "================ RESULTS =================="
- print "Gathering finished, amount of posts gathered: ",
- print len(pageIDs)
- print "==========================================="
- print "================ EDITING =================="
- lenpageIDs = len(pageIDs)
- edit_headers = headers.copy()
- for x in xrange(lenpageIDs):
- # This is where it decides what the post will be edited to. If even, the post will be the first image,
- # if odd, the second. Spike is the best.
- # To suit your preference: Delete entirely or tweak. use "\r" as a linebreak
- random_image = random.choice(["TpEkr", "VOW4i", "eDYMgap", "VxJHUJA", "3GbqHl9","2DF0wxa"])
- message = '-snip-'
- edit_headers.update({
- # Chances are that this is unnecessary
- 'Referer' : 'http://love2d.org/forums/posting.php?mode=edit&f='+pageIDs[x][0]+'&p='+pageIDs[x][1],
- 'Content-Type': 'application/x-www-form-urlencoded',
- })
- editPage = opener.open(editURL + '&f=' + pageIDs[x][0] + '&p=' + pageIDs[x][1]).read()
- # String might need tweaking, depends on the forum's theme.
- if 'This topic is locked, you cannot edit posts or make further replies.' in editPage:
- print str(x) + '. Post #' + str(pageIDs[x][1]) + ' is locked, you cannot edit posts or make further replies.'
- continue
- # There's definitely a better way than use re.findall for all of these. /2lazy
- # RegExp on the subject variable most likely needs tweaking. Again, depends on the forum's theme.
- subject = re.findall('<input type="text" name="subject" id="subject".*value="(.*)"', editPage)
- lastclick = re.findall('name="lastclick" value="(\d*)"', editPage)
- post_checksum = re.findall('name="edit_post_message_checksum" value="(.*)"', editPage)
- subject_checksum = re.findall('name="edit_post_subject_checksum" value="(.*)"', editPage)
- creation_time = re.findall('name="creation_time" value="(.*)"', editPage)
- form_token = re.findall('name="form_token" value="(.*)"', editPage)
- # Increase/decrease. Depends on the forum's anti-spam measurements.
- time.sleep(8)
- html = urllib2.urlopen(urllib2.Request(editURL + '&f=' + pageIDs[x][0] + '&sid=' + cookies[1] + '&p=' + pageIDs[x][1],
- urllib.urlencode({
- 'subject' : subject,
- # No idea what addbbcode20 is, might wanna use Tamper Data for firefox to see what is submitted on your forum.
- 'addbbcode20' : '100',
- 'message' : message,
- 'lastclick' : lastclick[0],
- 'edit_post_message_checksum' : post_checksum[0],
- 'edit_post_subject_checksum' : subject_checksum[0],
- 'post' : 'Submit',
- 'creation_time' : creation_time[0],
- 'form_token' : form_token[0],
- }),
- edit_headers)).read()
- if 'This message has been edited successfully.' in html:
- print str(x) + '. Post #' + str(pageIDs[x][1]) + ' has been edited successfully.'
- else:
- print str(x) + '. Post #' + str(pageIDs[x][1]) + ' failed. There has been an error.'
- continue
- else:
- # Regular expression's success depends on the forum theme. Will probably need tweaking.
- # Familiarize yourself with regular expression, view the source code of the 'pageURL' site and tweak accordingly.
- IDs = re.findall('<a href="\./viewtopic.php\?f=(\d*)&t=\d*&p=\d*#p(\d*)" class="right">Jump to post</a>', gatherPage)
- pageIDs.extend(IDs)
- currPage += 10
- print currPage,
- # Put your username and password here
- main("username", "password")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement