3
0

sell_bot.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. from rival_regions_wrapper.middleware import LocalAuthentication
  2. from rival_regions_wrapper import util
  3. from rival_regions_wrapper.wrapper.abstract_wrapper import AbstractWrapper
  4. import re
  5. from bs4 import BeautifulSoup
  6. authentication = LocalAuthentication(True)
  7. authentication.set_credentials("mail@gmail.com", "password", "google")
  8. class Market2(AbstractWrapper):
  9. def info(self, resource):
  10. """Get profile"""
  11. if isinstance(resource, str) and resource in util.ITEM_KEYS:
  12. resource = util.ITEM_KEYS[resource]
  13. path = "storage/listed/{}".format(resource)
  14. response = self.middleware.get(path)
  15. soup = BeautifulSoup(response, "html.parser")
  16. offers_tree = soup.find_all(class_="list_link")
  17. test = 0
  18. i = 0
  19. for offer_tree in offers_tree:
  20. if (
  21. int(
  22. re.sub(
  23. r"^.*\/",
  24. "",
  25. offer_tree.select_one(".results_date")["action"],
  26. )
  27. )
  28. == 2000883512
  29. ):
  30. test = int(
  31. offer_tree.select_one(".list_level.imp.small")["rat"]
  32. )
  33. i = i + 1
  34. return test
  35. class Storage(AbstractWrapper):
  36. """Wrapper class for storage"""
  37. def info(self, resource):
  38. """storage info"""
  39. path = "storage"
  40. resource = util.ITEM_KEYS[resource]
  41. response = self.middleware.get(path)
  42. soup = BeautifulSoup(response, "html.parser")
  43. storage = int(
  44. soup.find("span", {"urlbar": resource}).text.replace(".", "")
  45. )
  46. return storage
  47. class Market(AbstractWrapper):
  48. def info(self, resource):
  49. """Get profile"""
  50. if isinstance(resource, str) and resource in util.ITEM_KEYS:
  51. resource = util.ITEM_KEYS[resource]
  52. path = "storage/listed/{}".format(resource)
  53. response = self.middleware.get(path)
  54. soup = BeautifulSoup(response, "html.parser")
  55. offers_tree = soup.find_all(class_="list_link")
  56. test = 0
  57. prijs = 0
  58. for offer_tree in offers_tree:
  59. if test == 0:
  60. test = 1
  61. prijs = int(
  62. float(offer_tree.select(".list_level")[1]["rat"]) * 100
  63. )
  64. if (
  65. int(
  66. re.sub(
  67. r"^.*\/",
  68. "",
  69. offer_tree.select_one(".results_date")["action"],
  70. )
  71. )
  72. == 2000883512
  73. ):
  74. prijs = 0
  75. return prijs
  76. class MarketBot(AbstractWrapper):
  77. def info(self, resource, minprice):
  78. test = 0
  79. current_price = Market(authentication).info(resource)
  80. if current_price != 0:
  81. op_markt = Market2(authentication).info(resource)
  82. opslag = Storage(authentication).info(resource)
  83. totaal = opslag + op_markt
  84. mijn_prijs = (current_price - 10) / 100
  85. check = 0
  86. if mijn_prijs < minprice:
  87. mijn_prijs = minprice
  88. if resource == "helium-3":
  89. if totaal >= 153600:
  90. totaal = 153600
  91. check = 1
  92. if resource == "liquid_oxygen":
  93. if totaal >= 38400000:
  94. totaal = 38400000
  95. check = 1
  96. if resource == "oil":
  97. if totaal >= 614400000:
  98. totaal = 614400000
  99. check = 1
  100. if resource == "ore":
  101. if totaal >= 614400000:
  102. totaal = 614400000
  103. check = 1
  104. if resource == "uranium":
  105. if totaal >= 15360000:
  106. totaal = 15360000
  107. check = 1
  108. if resource == "diamonds":
  109. if totaal >= 153600:
  110. totaal = 153600
  111. check = 1
  112. if resource == "rivalium":
  113. if totaal >= 614400:
  114. totaal = 614400
  115. check = 1
  116. if resource == "antirad":
  117. if totaal >= 76800:
  118. totaal = 76800
  119. check = 1
  120. if resource == "spacerockets":
  121. if totaal >= 3840:
  122. totaal = 3840
  123. check = 1
  124. if resource == "lss":
  125. if totaal >= 15360000:
  126. totaal = 15360000
  127. check = 1
  128. if resource == "tanks":
  129. if totaal >= 4388571:
  130. totaal = 4388571
  131. check = 1
  132. if resource == "aircrafts":
  133. if totaal >= 640000:
  134. totaal = 640000
  135. check = 1
  136. if resource == "missiles":
  137. if totaal >= 256000:
  138. totaal = 256000
  139. check = 1
  140. if resource == "bombers":
  141. if totaal >= 128000:
  142. totaal = 128000
  143. check = 1
  144. if resource == "battleships":
  145. if totaal >= 128000:
  146. totaal = 128000
  147. check = 1
  148. if resource == "laser_drones":
  149. if totaal >= 256000:
  150. totaal = 256000
  151. check = 1
  152. if resource == "moon_tanks":
  153. if totaal >= 12800:
  154. totaal = 12800
  155. check = 1
  156. if resource == "space_stations":
  157. if totaal >= 1280:
  158. totaal = 1280
  159. check = 1
  160. if ((totaal == op_markt) and (mijn_prijs == minprice)) or (
  161. minprice == 500000000
  162. ):
  163. return True
  164. if totaal != 0:
  165. item = util.ITEM_KEYS[resource]
  166. self.middleware.post("storage/sell/{}".format(item))
  167. self.middleware.post(
  168. "storage/newsell/{}/{}/{}".format(item, totaal, mijn_prijs)
  169. )
  170. return True