Python - Create a Gaia Online Login
URL: Gaiaonline Python Login Tutorial
Was bored earlier, so just recorded it. I don't think many people will get much out of it, so be it. Final code is in the spoiler tags.
edit: should probably be said it was for Python 2.7.
Was bored earlier, so just recorded it. I don't think many people will get much out of it, so be it. Final code is in the spoiler tags.
edit: should probably be said it was for Python 2.7.
Spoiler
import urllib, urllib2, cookielib
import re
class HTTP:
def __init__(self):
self.cookiejar = cookielib.CookieJar()
self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cookiejar))
def request(self, url, data = []):
return self.opener.open(url, urllib.urlencode(data)).read()
def setHeader(self, name, val):
self.opener.addheaders = [(name, value)]
class GaiaOnline:
def __init__(self):
self.HTTP = HTTP()
def login(self, username, password):
source = self.HTTP.request("http://www.gaiaonline.com/")
inputPattern = re.compile("<input([^>]+)>")
inputs = inputPattern.findall(source)
fieldPattern = re.compile("([a-zA-Z0-9\-\_]+)\=\"([^\"]{0,})\"")
fieldList = {}
for y in range(0, len(inputs)):
fields = fieldPattern.findall(inputs[y])
name = ""
val = ""
for z in range(0, len(fields)):
if fields[z][0] == "name":
name = fields[z][1]
elif fields[z][0] == "value":
val = fields[z][1]
try:
fieldList[name] = val
except:
pass
fieldList["username"] = username
fieldList["password"] = password
login = self.HTTP.request("http://www.gaiaonline.com/auth/login/", fieldList)
return login.find("Welcome back") != -1
def bump(self, topicId, text = "bump"):
topic = self.HTTP.request("http://www.gaiaonline.com/forum/fullmetal-alchemist/test/t." + str(topicId) + "/")
print topic
gaiaonline = GaiaOnline()
if gaiaonline.login("username", "password"):
gaiaonline.bump(81911787)[/name][/1][/z][/0][/z][/1][/z][/0][/z][/y]