SellBot.py 4.8 KB

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