Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- import requests
- from lxml import html
- import socket
- import re
- #we set up the URLs we're gonna need
- URL_AUTH = "https://www.saltybet.com/authenticate?signin=1"
- URL_STATS = "http://www.saltybet.com/ajax_get_stats.php"
- URL_MAIN = "http://www.saltybet.com"
- #open a session and authenticate to saltybet
- session_requests = requests.session()
- result = session_requests.get(URL_AUTH)
- tree = html.fromstring(result.text)
- signin = list(set(tree.xpath("//input[@name='authenticate']/@value")))[0]
- AUTH = {"email": "hsafwcaseycrane@gmail.com", "pword": "e8EgNk8U", "authenticate": signin}
- result = session_requests.post(URL_AUTH, data = AUTH, headers = dict(referer = URL_AUTH))
- #we set up the twitch stuff
- HOST = "irc.twitch.tv"
- PORT = 6667
- NICK = "casey666666"
- PASS = 'oauth:6aqdwxmv51wt99p176cpto9wg87cqt'
- #we probably won't ever need the bot to send a message but whatever here it is
- def send_message(message):
- s.send(bytes("PRIVMSG #" + NICK + " :" + message + "\r\n", "UTF-8"))
- s = socket.socket()
- s.connect((HOST, PORT))
- s.send(bytes("PASS " + PASS + "\r\n", "UTF-8"))
- s.send(bytes("NICK " + NICK + "\r\n", "UTF-8"))
- s.send(bytes("JOIN #saltybet" + " \r\n", "UTF-8"))
- def getUser(line):
- separate = line.split(":")
- user = separate[1].split("!")[0]
- return user
- def getMessage(line):
- separate = line.split(":")
- message = ""
- if "QUIT" not in separate[1] and "JOIN" not in separate[1] and "PART" not in separate[1]:
- message = separate[2][:len(separate[2])]
- return message
- #we open or initialize the data set so we can start adding to it
- data = {}
- #with open('data.json') as json_file:
- # data = json.load(json_file)
- #now we start phase one of data mining, the illuminati stats. we scrape this right after bets are open and return it as a JSON object.
- def illuminati_scrape():
- sb = session_requests.get(URL_STATS, headers = dict(referer = URL_STATS))
- return sb.json();
- #now for phase two, after betting ends but before the fight.
- #THIS DOESN'T WORK AT ALL RIGHT NOW
- def odds_scrape(message):
- odds = re.findall(r'(?<=\$)(\d*\,?)*', message)
- for odd in odds:
- odd = "".join(odd.split(","));
- print(odd);
- return odds;
- def streak_scrape(message):
- streak = re.findall(r'(?<=\()\-?\d+', message)
- for strk in streak:
- print(strk);
- return streak;
- def streak_adjust(streak, winner):
- if len(streak) == 2:
- if winner == 0:
- if streak[0] < 0:
- streak[0] = 1;
- elif streak[0] >= 0:
- streak[0] = streak[0] + 1;
- if streak[1] < 0:
- streak[1] = streak[1] - 1;
- elif streak[1] >= 0:
- streak[1] = -1;
- elif winner == 1:
- if streak[0] < 0:
- streak[0] = streak[0] - 1;
- elif streak[0] >= 0:
- streak[0] = -1;
- if streak[1] < 0:
- streak[1] = 1;
- elif streak[1] >= 0:
- streak[1] = streak[1] + 1;
- return streak;
- #last is phase three, after the winner is declared but before the next fight.
- #this is when we stitch together the whole JSON entry
- def winner_scrape(message):
- if "Payouts to Team Red" in message:
- return 0;
- else:
- return 1;
- def main():
- readbuffer = ""
- new_data = []
- streak_table = json.dumps({})
- i=0
- while True:
- readbuffer = readbuffer + str(s.recv(1024))
- temp = readbuffer.split("\\r\\n")
- readbuffer = temp.pop()
- for line in temp:
- #print(line)
- if "PING" in line:
- s.send(line.replace("PING", "PONG").encode())
- break
- if getUser(line).upper() == "WAIFU4U":
- if "Bets are OPEN" in getMessage(line):
- new_data = json.load(illuminati_scrape());
- #data.append(illuminati_scrape());
- elif "Bets are locked" in getMessage(line):
- print(odds_scrape(line));
- streak_scrape(line);
- elif "Payouts to Team" in getMessage(line):
- #print(winner_scrape(line));
- for strk in streak_adjust(streak_scrape(line),winner_scrape(line)):
- print(strk);
- #new_data[0].append({'winner':winner_scrape(line)});
- print(new_data);
- i=i+1;
- #print(data);
- print("END OF MATCH " + str(i));
- main();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement