def send(sock, message): #TODO: the response is worthless HTTP.post( 'http://' + sock.server + ':' + str(sock.port) + '/socket.io/1/xhr-polling/' + sock.session + '/?name=' + chatserv.user + '&key=' + sock.key + '&roomId=' + str(sock.id) + '&client=Chatserv&version=' + str(chatserv.version), '5:::' + json.dumps({'name': 'message', 'args': [message]}), {'Content-Type': 'text/plain', 'Cookie': chatserv.session}, timeout=10 )
def login(name = None, passw = None): global session, user, password if name == None: name = user if passw == None: passw = password print('Logging in...') response = HTTP.post('http://community.wikia.com/api.php', {'action': 'login', 'lgname': name, 'lgpassword': passw, 'format': 'json'}) cookie = response.getheader('Set-Cookie') newsession = cookie[:cookie.find(';') + 1] result = json.loads(response.read().decode('utf-8')) try: HTTP.post('http://community.wikia.com/api.php', {'action': 'login', 'lgname': name, 'lgpassword': passw, 'lgtoken': result['login']['token']}, {'Cookie': newsession}) except: print(result) raise user = name #this should minimize race conditions if we ever have to log in again while connected password = passw session = newsession print('Session:', session)
def cajax(method, post): return HTTP.post( 'http://community.wikia.com/index.php?acion=ajax&rs=ChatAjax&method=' + method + '&client=Chatserv&version=' + str(chatserv.version), post, {'Cookie': chatserv.session} ).read().decode('utf-8')