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.55 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. ratio = 0
  66. odds = re.findall(r'(?<=\$)[\d\,]*', message)
  67. for odd in odds:
  68. odd = int("".join(odd.split(",")));
  69. if len(odds) > 1:
  70. return odds[0]/odds[1];
  71.  
  72. def streak_scrape(message):
  73. streak = re.findall(r'(?<=\()\-?\d+', message)
  74. for strk in streak:
  75. print(strk);
  76. return streak;
  77.  
  78. def streak_adjust(streak, winner):
  79. if len(streak) == 2:
  80. if winner == 0:
  81. if streak[0] < 0:
  82. streak[0] = 1;
  83. elif streak[0] >= 0:
  84. streak[0] = streak[0] + 1;
  85. if streak[1] < 0:
  86. streak[1] = streak[1] - 1;
  87. elif streak[1] >= 0:
  88. streak[1] = -1;
  89. elif winner == 1:
  90. if streak[0] < 0:
  91. streak[0] = streak[0] - 1;
  92. elif streak[0] >= 0:
  93. streak[0] = -1;
  94. if streak[1] < 0:
  95. streak[1] = 1;
  96. elif streak[1] >= 0:
  97. streak[1] = streak[1] + 1;
  98. return streak;
  99.  
  100. #last is phase three, after the winner is declared but before the next fight.
  101. #this is when we stitch together the whole JSON entry
  102. def winner_scrape(message):
  103. if "Payouts to Team Red" in message:
  104. return 0;
  105. else:
  106. return 1;
  107.  
  108. def main():
  109. readbuffer = ""
  110. new_data = {}
  111. streak_table = json.dumps({})
  112. i=0
  113. while True:
  114. readbuffer = readbuffer + str(s.recv(1024))
  115. temp = readbuffer.split("\\r\\n")
  116. readbuffer = temp.pop()
  117.  
  118. for line in temp:
  119. #print(line)
  120. if "PING" in line:
  121. s.send(line.replace("PING", "PONG").encode())
  122. break
  123. if getUser(line).upper() == "WAIFU4U":
  124. if "Bets are OPEN" in getMessage(line):
  125. new_data = illuminati_scrape();
  126. #data.append(illuminati_scrape());
  127. elif "Bets are locked" in getMessage(line):
  128.  
  129. streak_scrape(line);
  130. elif "Payouts to Team" in getMessage(line):
  131. #print(winner_scrape(line));
  132. for strk in streak_adjust(streak_scrape(line),winner_scrape(line)):
  133. print(strk);
  134. new_data.update({'winner':winner_scrape(line)});
  135. print(new_data);
  136. i=i+1;
  137. #print(data);
  138. print("END OF MATCH " + str(i));
  139.  
  140. main();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement