daily pastebin goal
10%
SHARE
TWEET

love2d forum removal spell

a guest Jan 23rd, 2014 308 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import urllib2
  2. import urllib
  3. import cookielib
  4. import sys
  5. import time
  6. import re
  7. import random
  8.  
  9.  
  10. def main(username, password):
  11.     # Define urls and variables for later
  12.     loginURL = 'http://love2d.org/forums/ucp.php?mode=login'
  13.     pageURL = 'http://love2d.org/forums/search.php?author_id='
  14.     editURL = 'http://love2d.org/forums/posting.php?mode=edit&'
  15.     cookies = []
  16.    
  17.     cookiez = cookielib.CookieJar()
  18.     opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiez))
  19.     urllib2.install_opener(opener)
  20.     headers = {
  21.     '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',
  22.     'Accept': 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',
  23.     'Accept-Language': 'en-gb,en;q=0.5',
  24.     'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
  25.     }
  26.  
  27.     # Unnecessary in most cases
  28.     urllib2.urlopen(urllib2.Request('http://love2d.org/forums/', None, headers))
  29.    
  30.     login_headers = headers.copy()
  31.     login_headers.update({
  32.         'Referer' : 'http://love2d.org/forums/',
  33.         'Content-Type': 'application/x-www-form-urlencoded',
  34.     })
  35.     html = urllib2.urlopen(urllib2.Request(loginURL,
  36.                                            urllib.urlencode({
  37.                                                'referer' : 'http://love2d.org/forums/',
  38.                                                'username' : username,
  39.                                                'password' : password,
  40.                                                'autologin' : 'on',
  41.                                                'login' : 'Login',
  42.                                                }),
  43.                                            login_headers)).read()
  44.    
  45.     # Checks for successful log-in
  46.     if "You have been successfully logged in." in html:
  47.         print "You have been successfully logged in."
  48.         print "Cookies are:"
  49.         for cookie in cookiez:
  50.             print cookie
  51.             cookies.append(cookie.value)
  52.         print cookies
  53.         print "==========================================="
  54.         print "=============== GATHERING ================="
  55.     else:
  56.         print "Log-in failed!"
  57.         sys.exit("Failed to log-in - exiting")
  58.  
  59.     currPage = 0
  60.     pageIDs = []
  61.    
  62.     while 1:
  63.         # cookies[2] is your userID
  64.         gatherPage = opener.open(pageURL + cookies[2] + '&start=' + str(currPage)).read()
  65.  
  66.         if "Sorry but you cannot use search at this time. Please try again in a few minutes." in gatherPage:
  67.             print "Sleeping..."
  68.             time.sleep(5)
  69.             continue
  70.         elif "No suitable matches were found." in gatherPage:
  71.             print "==========================================="
  72.             print "================ RESULTS =================="
  73.             print "Gathering finished, amount of posts gathered: ",
  74.             print len(pageIDs)
  75.  
  76.            
  77.             print "==========================================="
  78.             print "================ EDITING =================="
  79.             lenpageIDs = len(pageIDs)
  80.             edit_headers = headers.copy()
  81.             for x in xrange(lenpageIDs):
  82.  
  83.                 # This is where it decides what the post will be edited to. If even, the post will be the first image,
  84.                 # if odd, the second. Spike is the best.
  85.                 # To suit your preference: Delete entirely or tweak. use "\r" as a linebreak
  86.                 random_image = random.choice(["TpEkr", "VOW4i", "eDYMgap", "VxJHUJA", "3GbqHl9","2DF0wxa"])
  87.                 message = '-snip-'
  88.                
  89.                
  90.                 edit_headers.update({
  91.                     # Chances are that this is unnecessary
  92.                     'Referer' : 'http://love2d.org/forums/posting.php?mode=edit&f='+pageIDs[x][0]+'&p='+pageIDs[x][1],
  93.                     'Content-Type': 'application/x-www-form-urlencoded',
  94.                 })
  95.                
  96.                 editPage = opener.open(editURL + '&f=' + pageIDs[x][0] + '&p=' + pageIDs[x][1]).read()
  97.  
  98.                 # String might need tweaking, depends on the forum's theme.
  99.                 if 'This topic is locked, you cannot edit posts or make further replies.' in editPage:
  100.                     print str(x) + '. Post #' + str(pageIDs[x][1]) + ' is locked, you cannot edit posts or make further replies.'
  101.                     continue
  102.  
  103.                 # There's definitely a better way than use re.findall for all of these. /2lazy
  104.                 # RegExp on the subject variable most likely needs tweaking. Again, depends on the forum's theme.
  105.                 subject = re.findall('<input type="text" name="subject" id="subject".*value="(.*)"', editPage)
  106.                 lastclick = re.findall('name="lastclick" value="(\d*)"', editPage)
  107.                 post_checksum = re.findall('name="edit_post_message_checksum" value="(.*)"', editPage)
  108.                 subject_checksum = re.findall('name="edit_post_subject_checksum" value="(.*)"', editPage)
  109.                 creation_time = re.findall('name="creation_time" value="(.*)"', editPage)
  110.                 form_token = re.findall('name="form_token" value="(.*)"', editPage)
  111.  
  112.                 # Increase/decrease. Depends on the forum's anti-spam measurements.
  113.                 time.sleep(8)
  114.  
  115.                 html = urllib2.urlopen(urllib2.Request(editURL + '&f=' + pageIDs[x][0] + '&sid=' + cookies[1] + '&p=' + pageIDs[x][1],
  116.                                                    urllib.urlencode({
  117.                                                        'subject' : subject,
  118.                                                        # No idea what addbbcode20 is, might wanna use Tamper Data for firefox to see what is submitted on your forum.
  119.                                                        'addbbcode20' : '100',                                                      
  120.                                                        'message' : message,
  121.                                                        'lastclick' : lastclick[0],
  122.                                                        'edit_post_message_checksum' : post_checksum[0],
  123.                                                        'edit_post_subject_checksum' : subject_checksum[0],
  124.                                                        'post' : 'Submit',
  125.                                                        'creation_time' : creation_time[0],
  126.                                                        'form_token' : form_token[0],
  127.                                                        }),
  128.                                                    edit_headers)).read()
  129.                
  130.                 if 'This message has been edited successfully.' in html:
  131.                     print str(x) + '. Post #' + str(pageIDs[x][1]) + ' has been edited successfully.'
  132.                 else:
  133.                     print str(x) + '. Post #' + str(pageIDs[x][1]) + ' failed. There has been an error.'
  134.                     continue
  135.                
  136.         else:
  137.             # Regular expression's success depends on the forum theme. Will probably need tweaking.
  138.             # Familiarize yourself with regular expression, view the source code of the 'pageURL' site and tweak accordingly.
  139.             IDs = re.findall('<a href="\./viewtopic.php\?f=(\d*)&amp;t=\d*&amp;p=\d*#p(\d*)" class="right">Jump to post</a>', gatherPage)
  140.             pageIDs.extend(IDs)
  141.  
  142.             currPage += 10
  143.             print currPage,
  144.            
  145. # Put your username and password here
  146. main("username", "password")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top