async def do_work(self) -> int: await self.click(Work.selector(), 3) await self.browser.wait_for(".imp.yellow.tip") soup = await self.get_soup() energy, energy_cooldown_time = Status.check_energy(soup) gold = Work.check_region_gold(soup) if not Work.can_work(soup): LOG.info("Working is not possible") return 600 if gold > 0 and energy >= 10: try: await self.click(Work.work_selector(), 3) await self.click(utils.close_selector(), 3) LOG.info("Work is completed {} energys use to work".format(energy)) except Exception as err: LOG.debug(err) LOG.error("Can not work, maybe the factory owner doesn't have enough money?") return 600 elif gold > 0 and energy_cooldown_time == 0 and int(self.perks['END'][0]) >= 50: await self.click(Status.energy_bar_selector(), 3) else: if int(self.perks['END'][0]) < 50: return 600 elif gold == 0: LOG.info("Region lack of gold") return 600 elif energy >= 10 or energy_cooldown_time == 0: LOG.error("Some error occurred in work") return 600 return energy_cooldown_time return await self.do_work()
async def load_cookies(self): try: cookies = pickle.load(open("{}.pkl".format(self.profile), "rb")) for cookie in cookies: await self.browser.set_cookie(cookie) LOG.info("Cookies loaded!") except Exception: LOG.info('First Login') if self.headless: LOG.error('Please do not use headless mode!')
async def do_military_training(self) -> int: try: await self.click(War.selector(), 1) await self.click(War.military_training_selector(), 1) await self.click(War.send_ok_selector(), 1) await self.click(utils.close_selector(), 2) LOG.info("Military training completed") except Exception as err: LOG.debug(err) LOG.error("Military training failed") return 3598
async def __init__(self, login_method="GOOGLE", use_to_upgrade="RRCash", profile="default", upgrade_strategy="2:1:1", proxy=None, headless=None, poor=None, debug=False): self.profile = profile self.uri = "https://rivalregions.com" self.headless = headless if proxy: proxy = "--proxy-server={}".format(proxy) self.browser = await Browser(headless, proxy, dumpio=True) self.browser.set_default_navigation_timeout(30000) self.login_method = login_method if use_to_upgrade not in ['RRCash', 'GOLD', 'GOLD1']: self.use_to_upgrade = 'RRCash' else: self.use_to_upgrade = use_to_upgrade LOG.info(f"Will use {self.use_to_upgrade} upgrade perks.") try: self.upgrade_strategy = [ int(x) for x in upgrade_strategy.split(':') ] assert len(self.upgrade_strategy) == 3 except Exception: LOG.error("--upgrade_strategy invalid") self.perks = {'strategy': self.upgrade_strategy} await self.load_cookies() await self.browser.goto(self.uri, waitUntil='networkidle0') await self.check_login()
def add_error_to_logs(message, user): """ Method to important error messages to app logs. """ print(message, "User: {}".format(user)) LOG.error(message + " User: {}".format(user))