Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- mobilebot = "/home/pi/webbot/bot.js"
- cookiefile = "cookies.json"
- from SimpleWebSocketServer import SimpleWebSocketServer, WebSocket
- import time, threading, subprocess
- import requests, json, time, datetime, os
- from bs4 import BeautifulSoup
- def runProcess(exe):
- p = subprocess.Popen(exe, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
- while(True):
- retcode = p.poll() #returns None while subprocess is running
- line = p.stdout.readline()
- yield line
- if(retcode is not None):
- break
- status = "Closed"
- def emit_message(message):
- for client in clients:
- client.sendMessage(message)
- def emit_status():
- emit_message(json.dumps({"type": "status", "data": status}))
- def mobilebot_thread():
- global status
- status = "Starting"
- emit_status()
- while True:
- for line in runProcess(("node " + mobilebot).split()):
- line = str(line, "utf-8")
- if line.startswith("SteamGuard code is needed"):
- status = "Needs code"
- emit_status()
- elif line.startswith("Logged into Steam as"):
- status = "Logged in"
- emit_status()
- elif line.startswith("NOTIFICATION: "):
- line = line[14:]
- emit_message(json.dumps({"type": "message", "data": line}))
- print("M: " + line, end="")
- status = "Closed"
- emit_status()
- time.sleep(10)
- status = "Restarting"
- emit_status()
- last_bump_data = {}
- def get_bumpable_trades(cookies):
- pagedata = requests.get("https://csgolounge.com/mytrades", cookies=cookies).text
- soup = BeautifulSoup(pagedata, "html.parser")
- trades = []
- for button in soup.find_all("a", class_="buttonright"):
- if "Bump" in button.get_text():
- text = str(button)
- trade_id = text[text.index("bumpTrade('")+11:text.index("')")]
- trades.append(trade_id)
- return trades
- def bump_thread():
- global last_bump_data
- while True:
- print("Attempting trade bump...")
- file = open(cookiefile)
- data = json.loads(file.read())
- file.close()
- cookies = {}
- for cookie in data:
- cookies[cookie["name"]] = cookie["value"]
- trades = get_bumpable_trades(cookies)
- attempted_bumps = len(trades)
- for trade in trades:
- requests.post("https://csgolounge.com/ajax/bumpTrade.php", cookies=cookies, data={"trade": trade})
- time.sleep(20)
- trades = get_bumpable_trades(cookies)
- successful_bumps = attempted_bumps - len(trades)
- if successful_bumps > 0:
- last_bump_data = {"timestamp": time.time(), "trades": attempted_bumps, "successful": successful_bumps}
- emit_message(json.dumps({"type": "bump", "data": last_bump_data}))
- print("Successfully bumped " + str(successful_bumps) + "/" + str(attempted_bumps))
- time.sleep(300 - 20)
- clients = []
- class SimpleServer(WebSocket):
- def handleConnected(self):
- print(self.address, 'connected')
- clients.append(self)
- self.sendMessage(json.dumps({"type": "bump", "data": last_bump_data}))
- self.sendMessage(json.dumps({"type": "status", "data": status}))
- def handleClose(self):
- print(self.address, 'closed')
- clients.remove(self)
- server = SimpleWebSocketServer('', 8432, SimpleServer)
- def serve_thread():
- print("Starting WebSocket server...")
- server.serveforever()
- serve_t = threading.Thread(target=serve_thread)
- serve_t.start()
- print("Started server thread")
- bump_t = threading.Thread(target=bump_thread)
- bump_t.start()
- print("Started bump thread")
- mobile_t = threading.Thread(target=mobilebot_thread)
- mobile_t.start()
- print("Started mobilebot thread")
- while True:
- time.sleep(10000)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement