Skip to content

Instantly share code, notes, and snippets.

@juliusmh
Created June 9, 2016 15:52
Show Gist options
  • Save juliusmh/4b7cdeb8ea2f88d2719b1cbf5cb2f8ce to your computer and use it in GitHub Desktop.
Save juliusmh/4b7cdeb8ea2f88d2719b1cbf5cb2f8ce to your computer and use it in GitHub Desktop.
Hacking-Lab.com python chat client
# !/usr/bin/env python
# Please dont judge me the code is shity i just was anooyed by the website
# Please some body clean up the mess below and implement a nicer one. Thanks!
# This code needs Ghost.py installed. (Run install.sh)
import thread
import ghost
import sys
class HackingLab():
URL_HOST = "https://www.hacking-lab.com/"
URL_LOGIN = URL_HOST + "about/agb.html"
URL_CHAT_READ = URL_HOST + "chat/chathandler.html?channel=0"
def __init__(self):
self.logged_in = False
self.hlssl = None
self.outmsg = ""
self.gs = ghost.Session(ghost.Ghost(log_level=50), display=False)
def login(self, username, password):
self.gs.open(self.URL_LOGIN)
self.gs.set_field_value("input[name=userEmail]", username)
self.gs.set_field_value("input[name=userPassword]", password)
self.gs.click("button[name=login]", expect_loading=True)
def inputListener(self):
while True: self.outmsg = str(raw_input("Your message: "))
def chatMonitor(self):
started = True
cont = True
oldmsg = ""
# Enter the LOOP
while cont:
if not started : thread.start_new_thread(self.inputListener, ())
body = ""
if len(self.outmsg) > 0 :
body = "&message=%s" % self.outmsg
self.gs.open(self.URL_CHAT_READ, method="post", body=body)
oldmsg = ""
self.outmsg = ""
p,r = self.gs.open(self.URL_CHAT_READ)
msg = p.content
if len(oldmsg) == 0 :
delta = msg
else:
delta = oldmsg.replace(msg, "")
if len(delta) > 0 :
delta = delta.replace("&lt;", "<").replace("&gt;", ">")
delta = delta.replace('<span style="color:#87cefa;" >', '')
delta = delta.replace('</span>', '').replace('<br>', '')
lines = delta.split("\n")
for line in lines:
line = line.strip()
if len(line) > 10 :
date = line[1:9]
name = line[line.find("<") + 1 : line.find(">")]
data = line[line.find(">") + 2 :]
print "[%s] %s > %s" % (date, name, data)
started = False
oldmsg = msg
# Cleaning up when finished
self.exit()
def exit(self):
self.gs.exit()
h = HackingLab()
h.login(sys.argv[1], sys.argv[2])
h.chatMonitor()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment