Advertisement
Guest User

Untitled

a guest
Nov 17th, 2017
473
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. import json
  2. import requests
  3. from lxml import html
  4. import socket
  5. import re
  6.  
  7. #we set up the URLs we're gonna need
  8. URL_AUTH = "https://www.saltybet.com/authenticate?signin=1"
  9. URL_STATS = "http://www.saltybet.com/ajax_get_stats.php"
  10. URL_MAIN = "http://www.saltybet.com"
  11.  
  12. #open a session and authenticate to saltybet
  13. session_requests = requests.session()
  14.  
  15. result = session_requests.get(URL_AUTH)
  16. tree = html.fromstring(result.text)
  17. signin = list(set(tree.xpath("//input[@name='authenticate']/@value")))[0]
  18.  
  19. AUTH = {"email": "hsafwcaseycrane@gmail.com", "pword": "e8EgNk8U", "authenticate": signin}
  20.  
  21. result = session_requests.post(URL_AUTH, data = AUTH, headers = dict(referer = URL_AUTH))
  22.  
  23.  
  24. #we set up the twitch stuff
  25. HOST = "irc.twitch.tv"
  26. PORT = 6667
  27. NICK = "casey666666"
  28. PASS = 'oauth:6aqdwxmv51wt99p176cpto9wg87cqt'
  29.  
  30. #we probably won't ever need the bot to send a message but whatever here it is
  31. def send_message(message):
  32. s.send(bytes("PRIVMSG #" + NICK + " :" + message + "\r\n", "UTF-8"))
  33.  
  34. s = socket.socket()
  35. s.connect((HOST, PORT))
  36. s.send(bytes("PASS " + PASS + "\r\n", "UTF-8"))
  37. s.send(bytes("NICK " + NICK + "\r\n", "UTF-8"))
  38. s.send(bytes("JOIN #saltybet" + " \r\n", "UTF-8"))
  39.  
  40. def getUser(line):
  41. separate = line.split(":")
  42. user = separate[1].split("!")[0]
  43. return user
  44. def getMessage(line):
  45. separate = line.split(":")
  46. message = ""
  47. if "QUIT" not in separate[1] and "JOIN" not in separate[1] and "PART" not in separate[1]:
  48. message = separate[2][:len(separate[2])]
  49. return message
  50.  
  51. #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.
  52. def illuminati_scrape():
  53. sb = session_requests.get(URL_STATS, headers = dict(referer = URL_STATS))
  54. return sb.json();
  55.  
  56. #now for phase two, after betting ends but before the fight.
  57. #THIS DOESN'T WORK AT ALL RIGHT NOW
  58. def odds_scrape(message):
  59. odds = re.findall(r'\$\W+', message)
  60. if len(odds) != 2:
  61. return 0;
  62. else:
  63. ratio = odds[0]/odds[1]
  64. print(odds[0] + " / " + odds[1]);
  65. return odds;
  66.  
  67. #last is phase three, after the winner is declared but before the next fight.
  68. #this is when we stitch together the whole JSON entry
  69. def winner_scrape(message):
  70. if "Payouts to Team Red" in message:
  71. return 0;
  72. else:
  73. return 1;
  74.  
  75. def main():
  76. readbuffer = ""
  77. while True:
  78. readbuffer = readbuffer + str(s.recv(1024))
  79. temp = readbuffer.split("\\r\\n")
  80. readbuffer = temp.pop()
  81.  
  82. for line in temp:
  83. #print(line)
  84. if "PING" in line:
  85. s.send(line.replace("PING", "PONG").encode())
  86. break
  87. if getUser(line).upper() == "WAIFU4U":
  88. if "Bets are OPEN" in getMessage(line):
  89. print(illuminati_scrape());
  90. elif "Bets are locked" in getMessage(line):
  91. print(odds_scrape(line));
  92. elif "Payouts to Team" in getMessage(line):
  93. print(winner_scrape(line));
  94.  
  95. main();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement