buy_bot.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 CurrentPrice(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. prijs = 0
  19. for offer_tree in offers_tree:
  20. if test == 0:
  21. test = 1
  22. prijs = int(
  23. float(offer_tree.select('.list_level')[1]['rat']) * 100
  24. )
  25. return prijs
  26. class Amount(AbstractWrapper):
  27. def info(self, resource):
  28. """Get profile"""
  29. if isinstance(resource, str) and resource in util.ITEM_KEYS:
  30. resource = util.ITEM_KEYS[resource]
  31. path = 'storage/listed/{}'.format(resource)
  32. response = self.middleware.get(path)
  33. soup = BeautifulSoup(response, 'html.parser')
  34. offers_tree = soup.find_all(class_='list_link')
  35. test = 0
  36. for offer_tree in offers_tree:
  37. if test ==0:
  38. test =1
  39. amount = int(offer_tree.select_one('.list_level.imp.small')['rat'])
  40. return amount
  41. class Profile(AbstractWrapper):
  42. def info(self, resource):
  43. """Get profile"""
  44. if isinstance(resource, str) and resource in util.ITEM_KEYS:
  45. resource = util.ITEM_KEYS[resource]
  46. path = 'storage/listed/{}'.format(resource)
  47. response = self.middleware.get(path)
  48. soup = BeautifulSoup(response, 'html.parser')
  49. offers_tree = soup.find_all(class_='list_link')
  50. test = 0
  51. profiel = 0
  52. for offer_tree in offers_tree:
  53. if test ==0:
  54. test =1
  55. profiel = int(re.sub(
  56. r'^.*\/', '',
  57. offer_tree.select_one('.results_date')['action']))
  58. return profiel
  59. class BuyMarket(AbstractWrapper):
  60. def info(self, resource,price):
  61. current_price = CurrentPrice(authentication).info(resource)/100
  62. if current_price < price:
  63. profiel = Profile(authentication).info(resource)
  64. amount = Amount(authentication).info(resource)
  65. item = util.ITEM_KEYS[resource]
  66. self.middleware.post(
  67. 'storage/buy/{}/{}/{}/{}'.format(item,profiel,amount,current_price))
  68. return True