From cf797f2f60c722f20186c8b125add5369443ecb8 Mon Sep 17 00:00:00 2001 From: Eriks K Date: Tue, 18 Aug 2020 13:14:41 +0300 Subject: [PATCH] Fixes and updates --- erepublik/access_points.py | 26 ++++++++++++++------------ erepublik/citizen.py | 17 +++++++++++++---- erepublik/classes.py | 4 ++-- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/erepublik/access_points.py b/erepublik/access_points.py index 324061c..73392e6 100644 --- a/erepublik/access_points.py +++ b/erepublik/access_points.py @@ -15,24 +15,26 @@ class SlowRequests(Session): timeout = datetime.timedelta(milliseconds=500) uas = [ # Chrome + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36', # noqa 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36', # noqa 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.106 Safari/537.36', # noqa - 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36', # noqa - 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36', # noqa + 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.106 Safari/537.36', - 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36', - 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36', # FireFox - 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0', - 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:75.0) Gecko/20100101 Firefox/75.0', - 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:74.0) Gecko/20100101 Firefox/74.0', - 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:73.0) Gecko/20100101 Firefox/73.0', - 'Mozilla/5.0 (X11; Linux x86_64; rv:76.0) Gecko/20100101 Firefox/76.0', - 'Mozilla/5.0 (X11; Linux x86_64; rv:75.0) Gecko/20100101 Firefox/75.0', - 'Mozilla/5.0 (X11; Linux x86_64; rv:74.0) Gecko/20100101 Firefox/74.0', - 'Mozilla/5.0 (X11; Linux x86_64; rv:73.0) Gecko/20100101 Firefox/73.0', + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0', + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:82.0) Gecko/20100101 Firefox/82.0', + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0', + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:80.0) Gecko/20100101 Firefox/80.0', + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:79.0) Gecko/20100101 Firefox/79.0', + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0', + 'Mozilla/5.0 (X11; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0', + 'Mozilla/5.0 (X11; Linux x86_64; rv:82.0) Gecko/20100101 Firefox/82.0', + 'Mozilla/5.0 (X11; Linux x86_64; rv:81.0) Gecko/20100101 Firefox/81.0', + 'Mozilla/5.0 (X11; Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0', + 'Mozilla/5.0 (X11; Linux x86_64; rv:79.0) Gecko/20100101 Firefox/79.0', + 'Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0', ] debug = False diff --git a/erepublik/citizen.py b/erepublik/citizen.py index 8817150..26050ad 100644 --- a/erepublik/citizen.py +++ b/erepublik/citizen.py @@ -1540,8 +1540,8 @@ class CitizenMilitary(CitizenTravel): else: ground_divs.append((medal.get('1').get('raw_value'), division)) - air_divs.sort(key=lambda z: (z[0],z[1].battle.start)) - ground_divs.sort(key=lambda z:(z[0],z[1].battle.start)) + air_divs.sort(key=lambda z: (z[0], z[1].battle.start)) + ground_divs.sort(key=lambda z: (z[0], z[1].battle.start)) return {'air': air_divs, 'ground': ground_divs} @property @@ -1609,7 +1609,8 @@ class CitizenMilitary(CitizenTravel): self.travel_to_residence() break - def fight(self, battle: classes.Battle, division: classes.BattleDivision, side: classes.BattleSide = None, count: int = None) -> int: + def fight(self, battle: classes.Battle, division: classes.BattleDivision, side: classes.BattleSide = None, + count: int = None) -> int: """Fight in a battle. Will auto activate booster and travel if allowed to do it. @@ -1763,7 +1764,8 @@ class CitizenMilitary(CitizenTravel): if resp.json().get('error'): self.write_log(resp.json().get('message')) return False - self._report_action("MILITARY_DIV_SWITCH", f"Switched to d{division.div} in battle {battle.id}", kwargs=resp.json()) + self._report_action("MILITARY_DIV_SWITCH", f"Switched to d{division.div} in battle {battle.id}", + kwargs=resp.json()) return True def get_ground_hit_dmg_value(self, rang: int = None, strength: float = None, elite: bool = None, ne: bool = False, @@ -1963,6 +1965,13 @@ class CitizenMilitary(CitizenTravel): return member.get('panelContents', {}).get('members', [{}])[0].get('dailyOrdersCompleted') return 0 + def get_possibly_empty_medals(self): + self.update_war_info() + for battle in self.all_battles.values(): + for division in battle.div.values(): + if division.wall['dom'] == 50 or division.wall['dom'] > 98: + yield division, division.wall['for'] == battle.invader.country.id + class CitizenPolitics(BaseCitizen): def get_country_parties(self, country: constants.Country = None) -> dict: diff --git a/erepublik/classes.py b/erepublik/classes.py index dbc1c1a..7a2dfb9 100644 --- a/erepublik/classes.py +++ b/erepublik/classes.py @@ -569,8 +569,8 @@ class Reporter: def __bot_update(self, data: dict) -> Response: if self.__to_update: for unreported_data in self.__to_update: - unreported_data.update(player_id=self.citizen.id, key=self.key) - unreported_data = utils.json.load(utils.json.dumps(unreported_data, cls=MyJSONEncoder)) + unreported_data.update(player_id=self.citizen_id, key=self.key) + unreported_data = utils.json.loads(utils.json.dumps(unreported_data, cls=MyJSONEncoder)) self._req.post("{}/bot/update".format(self.url), json=unreported_data) self.__to_update.clear() data = utils.json.loads(utils.json.dumps(data, cls=MyJSONEncoder))