from rival_regions_wrapper.middleware import LocalAuthentication from rival_regions_wrapper import util from rival_regions_wrapper.wrapper.abstract_wrapper import AbstractWrapper import re from bs4 import BeautifulSoup authentication = LocalAuthentication(True) authentication.set_credentials("mail@gmail.com", "password", "google") class Market2(AbstractWrapper): def info(self, resource): """Get profile""" if isinstance(resource, str) and resource in util.ITEM_KEYS: resource = util.ITEM_KEYS[resource] path = "storage/listed/{}".format(resource) response = self.middleware.get(path) soup = BeautifulSoup(response, "html.parser") offers_tree = soup.find_all(class_="list_link") test = 0 i = 0 for offer_tree in offers_tree: if ( int( re.sub( r"^.*\/", "", offer_tree.select_one(".results_date")["action"], ) ) == 2000883512 ): test = int( offer_tree.select_one(".list_level.imp.small")["rat"] ) i = i + 1 return test class Storage(AbstractWrapper): """Wrapper class for storage""" def info(self, resource): """storage info""" path = "storage" resource = util.ITEM_KEYS[resource] response = self.middleware.get(path) soup = BeautifulSoup(response, "html.parser") storage = int( soup.find("span", {"urlbar": resource}).text.replace(".", "") ) return storage class Market(AbstractWrapper): def info(self, resource): """Get profile""" if isinstance(resource, str) and resource in util.ITEM_KEYS: resource = util.ITEM_KEYS[resource] path = "storage/listed/{}".format(resource) response = self.middleware.get(path) soup = BeautifulSoup(response, "html.parser") offers_tree = soup.find_all(class_="list_link") test = 0 prijs = 0 for offer_tree in offers_tree: if test == 0: test = 1 prijs = int( float(offer_tree.select(".list_level")[1]["rat"]) * 100 ) if ( int( re.sub( r"^.*\/", "", offer_tree.select_one(".results_date")["action"], ) ) == 2000883512 ): prijs = 0 return prijs class MarketBot(AbstractWrapper): def info(self, resource, minprice): test = 0 current_price = Market(authentication).info(resource) if current_price != 0: op_markt = Market2(authentication).info(resource) opslag = Storage(authentication).info(resource) totaal = opslag + op_markt mijn_prijs = (current_price - 10) / 100 check = 0 if mijn_prijs < minprice: mijn_prijs = minprice if resource == "helium-3": if totaal >= 153600: totaal = 153600 check = 1 if resource == "liquid_oxygen": if totaal >= 38400000: totaal = 38400000 check = 1 if resource == "oil": if totaal >= 614400000: totaal = 614400000 check = 1 if resource == "ore": if totaal >= 614400000: totaal = 614400000 check = 1 if resource == "uranium": if totaal >= 15360000: totaal = 15360000 check = 1 if resource == "diamonds": if totaal >= 153600: totaal = 153600 check = 1 if resource == "rivalium": if totaal >= 614400: totaal = 614400 check = 1 if resource == "antirad": if totaal >= 76800: totaal = 76800 check = 1 if resource == "spacerockets": if totaal >= 3840: totaal = 3840 check = 1 if resource == "lss": if totaal >= 15360000: totaal = 15360000 check = 1 if resource == "tanks": if totaal >= 4388571: totaal = 4388571 check = 1 if resource == "aircrafts": if totaal >= 640000: totaal = 640000 check = 1 if resource == "missiles": if totaal >= 256000: totaal = 256000 check = 1 if resource == "bombers": if totaal >= 128000: totaal = 128000 check = 1 if resource == "battleships": if totaal >= 128000: totaal = 128000 check = 1 if resource == "laser_drones": if totaal >= 256000: totaal = 256000 check = 1 if resource == "moon_tanks": if totaal >= 12800: totaal = 12800 check = 1 if resource == "space_stations": if totaal >= 1280: totaal = 1280 check = 1 if ((totaal == op_markt) and (mijn_prijs == minprice)) or ( minprice == 500000000 ): return True if totaal != 0: item = util.ITEM_KEYS[resource] self.middleware.post("storage/sell/{}".format(item)) self.middleware.post( "storage/newsell/{}/{}/{}".format(item, totaal, mijn_prijs) ) return True