Advertisement
Guest User

Untitled

a guest
Nov 17th, 2017
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.56 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. #we open or initialize the data set so we can start adding to it
  52. data = {}
  53. #with open('data.json') as json_file:
  54. # data = json.load(json_file)
  55.  
  56.  
  57. #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.
  58. def illuminati_scrape():
  59. sb = session_requests.get(URL_STATS, headers = dict(referer = URL_STATS))
  60. return sb.json();
  61.  
  62. #now for phase two, after betting ends but before the fight.
  63. #THIS DOESN'T WORK AT ALL RIGHT NOW
  64. def odds_scrape(message):
  65. odds = re.findall(r'(?<=\$)(\d*\,?)*', message)
  66. for odd in odds:
  67. odd = "".join(odd.split(","));
  68. print(odd);
  69. return odds;
  70.  
  71. def streak_scrape(message):
  72. streak = re.findall(r'(?<=\()\-?\d+', message)
  73. for strk in streak:
  74. print(strk);
  75. return streak;
  76.  
  77. def streak_adjust(streak, winner):
  78. if len(streak) == 2:
  79. if winner == 0:
  80. if streak[0] < 0:
  81. streak[0] = 1;
  82. elif streak[0] >= 0:
  83. streak[0] = streak[0] + 1;
  84. if streak[1] < 0:
  85. streak[1] = streak[1] - 1;
  86. elif streak[1] >= 0:
  87. streak[1] = -1;
  88. elif winner == 1:
  89. if streak[0] < 0:
  90. streak[0] = streak[0] - 1;
  91. elif streak[0] >= 0:
  92. streak[0] = -1;
  93. if streak[1] < 0:
  94. streak[1] = 1;
  95. elif streak[1] >= 0:
  96. streak[1] = streak[1] + 1;
  97. return streak;
  98.  
  99. #last is phase three, after the winner is declared but before the next fight.
  100. #this is when we stitch together the whole JSON entry
  101. def winner_scrape(message):
  102. if "Payouts to Team Red" in message:
  103. return 0;
  104. else:
  105. return 1;
  106.  
  107. def main():
  108. readbuffer = ""
  109. new_data = []
  110. streak_table = json.dumps({})
  111. i=0
  112. while True:
  113. readbuffer = readbuffer + str(s.recv(1024))
  114. temp = readbuffer.split("\\r\\n")
  115. readbuffer = temp.pop()
  116.  
  117. for line in temp:
  118. #print(line)
  119. if "PING" in line:
  120. s.send(line.replace("PING", "PONG").encode())
  121. break
  122. if getUser(line).upper() == "WAIFU4U":
  123. if "Bets are OPEN" in getMessage(line):
  124. new_data = json.load(illuminati_scrape());
  125. #data.append(illuminati_scrape());
  126. elif "Bets are locked" in getMessage(line):
  127. print(odds_scrape(line));
  128. streak_scrape(line);
  129. elif "Payouts to Team" in getMessage(line):
  130. #print(winner_scrape(line));
  131. for strk in streak_adjust(streak_scrape(line),winner_scrape(line)):
  132. print(strk);
  133. #new_data[0].append({'winner':winner_scrape(line)});
  134. print(new_data);
  135. i=i+1;
  136. #print(data);
  137. print("END OF MATCH " + str(i));
  138.  
  139. main();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement