Artificial wrote:I wish you'd all stop bawwing. Why can't we all just get along.
Either way, just wrote and tested this - works fine.
import re
class Gaiaonline():
def __init__(self):
self.http = HTTP()
def login(self, username, password):
try:
httpSource = self.http.get('http://www.gaiaonline.com/auth/login/')
formSource = httpSource[httpSource.find('<form action="/auth/login/"'):httpSource.find('</form>')]
formFields = {}
fields = re.compile("<input([^>]+)>", re.IGNORECASE|re.MULTILINE).findall(formSource)
regex = re.compile("([a-z\-]+)\=\"([\w\-]{0,})\"", re.IGNORECASE|re.MULTILINE)
for x in range(0, len(fields)):
(name,value) = ["",""]
data = regex.findall(fields[x])
for y in range(0, len(data)):
if data[y][0] == "name":
name = data[y][1]
elif data[y][0] == "value":
value = data[y][1]
try:
formFields[name] = value
except:
pass
formFields['username'] = username
formFields['password'] = password
return self.http.post('http://www.gaiaonline.com/auth/login/', formFields).find('Welcome to Gaia') != -1
except:
return False
[/name][/1][/y][/0][/y][/1][/y][/0][/y][/x]
Yeah everything got pretty derailed after I (granted, bluntly) commented on the quality of MattSmith's code and apparently telling boa man5 his port was invalid.
Either way, nice work. Clean, sophisticated solution. This is commendation-worthy.
I was going to ramble about a few things pertaining to the topic, but I tend to make things a bit more verbose than it needs to be.
Might as well make this short and sweet by conveying the idea of this:
;Author: The Unintelligible
;Version: v.0.0.1
;Powered by: AutoIt3
#NoTrayIcon
#include <IE.au3>
Const $SOH = Chr(01), $EOH = Chr(05)
If $CmdLine[0] >= 1 Then
If $CmdLine[0] > 3 Then
ConsoleWrite("+> Terminal error -- maximum command-line parameters exceeded!" & @CRLF)
Exit
EndIf
Else
ConsoleWrite("+> Terminal error -- insufficient amount of command-line parameters specified." & @CRLF)
Exit
EndIf
Switch $CmdLine[1]
Case '/log-in'
$oIE = _IECreate("http://www.gaiaonline.com/auth/login", Default, 0)
$strHTML = _IEDocReadHTML($oIE)
If StringInStr($strHTML, "Welcome back") Then _IELinkClickByText($oIE, "Logout")
$oUser = _IEGetObjById($oIE, "username")
_IEFormElementSetValue($oUser, $CmdLine[2])
$oPass = _IEGetObjByID($oIE, "password")
_IEFormElementSetValue($oPass, $CmdLine[3])
$oSubmit = _IEGetObjByID($oIE, "signInbutton")
_IEAction($oSubmit, "click")
Sleep(2000)
_IENavigate($oIE, "http://gaiaonline.com/chat/gsi/index.php?m=109")
$sSID = StringReplace(_IEBodyReadText($oIE), "109" & $SOH & $EOH & $SOH, '')
ConsoleWrite($sSID & @CRLF)
Case '/log-out'
If StringInStr($strHTML, "Welcome back") Then
_IELinkClickByText($oIE, "Logout")
Else
ConsoleWrite("+> You are already signed out." & @CRLF)
EndIf
Case '/free'
$oIE = 0
ConsoleWrite("+> DOM/IE object successfully liberated!" & @CRLF)
Case '/construct'
$oIE = _IECreate("http://www.gaiaonline.com/auth/login", Default, 0)
If Not @error Then
ConsoleWrite("+> Object construction successful!" & @CRLF)
Else
ConsoleWrite("+> Object construction failed." & @CRLF)
EndIf
Case Else
ConsoleWrite("+> Invalid command specified!" & @CRLF)
EndSwitch[/3][/2][/1][/0][/0]Have fun, guys.
