diff --git a/erepublik/__init__.py b/erepublik/__init__.py index c08c5f1..2c46cf1 100644 --- a/erepublik/__init__.py +++ b/erepublik/__init__.py @@ -5,7 +5,7 @@ __author__ = """Eriks Karls""" __email__ = 'eriks@72.lv' __version__ = '0.20.0' -__commit_id__ = "ac4fc9b" +__commit_id__ = "3cac1cf" from erepublik import classes, utils from erepublik.citizen import Citizen diff --git a/erepublik/access_points.py b/erepublik/access_points.py index f7d3505..3c23c0d 100644 --- a/erepublik/access_points.py +++ b/erepublik/access_points.py @@ -15,20 +15,24 @@ 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/80.0.3987.106 Safari/537.36', - 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36', - 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36', + '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/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:72.0) Gecko/20100101 Firefox/72.0', - 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:71.0) Gecko/20100101 Firefox/71.0', - 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:70.0) Gecko/20100101 Firefox/70.0', - 'Mozilla/5.0 (X11; Linux x86_64; rv:72.0) Gecko/20100101 Firefox/72.0', - 'Mozilla/5.0 (X11; Linux x86_64; rv:71.0) Gecko/20100101 Firefox/71.0', - 'Mozilla/5.0 (X11; Linux x86_64; rv:70.0) Gecko/20100101 Firefox/70.0', + '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', ] debug = False diff --git a/erepublik/citizen.py b/erepublik/citizen.py index 2820eb4..2dee17b 100644 --- a/erepublik/citizen.py +++ b/erepublik/citizen.py @@ -495,8 +495,9 @@ class BaseCitizen(CitizenAPI): If Energy limit >= xp till levelup * 10 :return: bool """ - return (self.energy.recovered >= self.details.xp_till_level_up * 10 and # can reach next level - self.energy.recoverable + 2 * self.energy.interval >= self.energy.limit) # can do max amount of dmg + can_reach_next_level = self.energy.recovered >= self.details.xp_till_level_up * 10 + can_do_max_amount_of_dmg = self.energy.recoverable + 2 * self.energy.interval >= self.energy.limit + return can_reach_next_level and can_do_max_amount_of_dmg @property def available_industries(self) -> Dict[str, int]: @@ -1152,8 +1153,9 @@ class CitizenEconomy(CitizenTravel): self.write_log(f"Donate: {amount:4d}q{quality} {ind[industry_id]} to {citizen_id}") response = self._post_economy_donate_items_action(citizen_id, amount, industry_id, quality) if re.search(rf"Successfully transferred {amount} item\(s\) to", response.text): - self._report_action("DONATE_ITEMS", f"Successfully donated {amount}q{quality} {self.available_industries_by_id[industry_id]}" - f" to citizen with id {citizen_id}!", success=True) + msg = (f"Successfully donated {amount}q{quality} {self.available_industries_by_id[industry_id]} " + f"to citizen with id {citizen_id}!") + self._report_action("DONATE_ITEMS", msg, success=True) return amount elif re.search('You must wait 5 seconds before donating again', response.text): self.write_log(f"Previous donation failed! Must wait at least 5 seconds before next donation!") @@ -1162,8 +1164,8 @@ class CitizenEconomy(CitizenTravel): else: if re.search(r"You do not have enough items in your inventory to make this donation", response.text): self._report_action("DONATE_ITEMS", - f"Unable to donate {amount}q{quality} {self.available_industries_by_id[industry_id]}" - f", not enough left!", success=False) + f"Unable to donate {amount}q{quality} " + f"{self.available_industries_by_id[industry_id]}, not enough left!", success=False) return 0 available = re.search(rf"Cannot transfer the items because the user has only (\d+) free slots in (his|her) " rf"storage.", response.text).group(1) @@ -1185,8 +1187,8 @@ class CitizenEconomy(CitizenTravel): success=True) return True else: - self._report_action("CONTRIBUTE_CC", f"Unable to contribute {amount}cc to {utils.COUNTRIES[country_id]}'s treasury", - **r.json()) + self._report_action("CONTRIBUTE_CC", f"Unable to contribute {amount}cc to {utils.COUNTRIES[country_id]}'s" + f" treasury", **r.json()) return False def contribute_food_to_country(self, amount: int = 0, quality: int = 1, country_id: int = 71) -> bool: @@ -1198,12 +1200,12 @@ class CitizenEconomy(CitizenTravel): r = self._post_main_country_donate(**data) if r.json().get('status') or not r.json().get('error'): - self._report_action("CONTRIBUTE_FOOD", f"Contributed {amount}q{quality} food to {utils.COUNTRIES[country_id]}'s treasury", - success=True) + self._report_action("CONTRIBUTE_FOOD", f"Contributed {amount}q{quality} food to " + f"{utils.COUNTRIES[country_id]}'s treasury", success=True) return True else: - self._report_action("CONTRIBUTE_FOOD", f"Unable to contribute {amount}q{quality} food to {utils.COUNTRIES[country_id]}'s treasury", - **r.json()) + self._report_action("CONTRIBUTE_FOOD", f"Unable to contribute {amount}q{quality} food to " + f"{utils.COUNTRIES[country_id]}'s treasury", **r.json()) return False def contribute_gold_to_country(self, amount: int, country_id: int = 71) -> bool: @@ -1220,8 +1222,8 @@ class CitizenEconomy(CitizenTravel): success=True) return True else: - self._report_action("CONTRIBUTE_GOLD", f"Unable to contribute {amount}g to {utils.COUNTRIES[country_id]}'s treasury", - **r.json()) + self._report_action("CONTRIBUTE_GOLD", f"Unable to contribute {amount}g to {utils.COUNTRIES[country_id]}'s" + f" treasury", **r.json()) return False @@ -1492,10 +1494,10 @@ class CitizenMilitary(CitizenTravel): else: other_battles_ground.append(battle.id) - ret_battles += (cs_battles_air + cs_battles_ground + - deployed_battles_air + deployed_battles_ground + - ally_battles_air + ally_battles_ground + - other_battles_air + other_battles_ground) + cs_battles = cs_battles_priority_air + cs_battles_priority_ground + cs_battles_air + cs_battles_ground + deployed_battles = deployed_battles_air + deployed_battles_ground + other_battles = ally_battles_air + ally_battles_ground + other_battles_air + other_battles_ground + ret_battles = ret_battles + cs_battles + deployed_battles + other_battles return ret_battles @property diff --git a/erepublik/utils.py b/erepublik/utils.py index 0ecefc9..f03fb54 100644 --- a/erepublik/utils.py +++ b/erepublik/utils.py @@ -36,7 +36,23 @@ FOOD_ENERGY: Dict[str, int] = dict(q1=2, q2=4, q3=6, q4=8, q5=10, q6=12, q7=20) COMMIT_ID: str = __commit_id__ erep_tz = pytz.timezone('US/Pacific') -AIR_RANKS: Dict[int, str] = {1: "Airman", 2: "Airman 1st Class", 3: "Airman 1st Class*", 4: "Airman 1st Class**",5: "Airman 1st Class***", 6: "Airman 1st Class****", 7: "Airman 1st Class*****",8: "Senior Airman", 9: "Senior Airman*", 10: "Senior Airman**", 11: "Senior Airman***",12: "Senior Airman****", 13: "Senior Airman*****",14: "Staff Sergeant", 15: "Staff Sergeant*", 16: "Staff Sergeant**", 17: "Staff Sergeant***",18: "Staff Sergeant****", 19: "Staff Sergeant*****",20: "Aviator", 21: "Aviator*", 22: "Aviator**", 23: "Aviator***", 24: "Aviator****", 25: "Aviator*****",26: "Flight Lieutenant", 27: "Flight Lieutenant*", 28: "Flight Lieutenant**", 29: "Flight Lieutenant***",30: "Flight Lieutenant****", 31: "Flight Lieutenant*****",32: "Squadron Leader", 33: "Squadron Leader*", 34: "Squadron Leader**", 35: "Squadron Leader***",36: "Squadron Leader****", 37: "Squadron Leader*****",38: "Chief Master Sergeant", 39: "Chief Master Sergeant*", 40: "Chief Master Sergeant**",41: "Chief Master Sergeant***", 42: "Chief Master Sergeant****", 43: "Chief Master Sergeant*****",44: "Wing Commander", 45: "Wing Commander*", 46: "Wing Commander**", 47: "Wing Commander***",48: "Wing Commander****", 49: "Wing Commander*****",50: "Group Captain", 51: "Group Captain*", 52: "Group Captain**", 53: "Group Captain***",54: "Group Captain****", 55: "Group Captain*****",56: "Air Commodore", 57: "Air Commodore*", 58: "Air Commodore**", 59: "Air Commodore***",60: "Air Commodore****", 61: "Air Commodore*****", } +AIR_RANKS: Dict[int, str] = { + 1: "Airman", 2: "Airman 1st Class", 3: "Airman 1st Class*", 4: "Airman 1st Class**", 5: "Airman 1st Class***", + 6: "Airman 1st Class****", 7: "Airman 1st Class*****", 8: "Senior Airman", 9: "Senior Airman*", + 10: "Senior Airman**", 11: "Senior Airman***", 12: "Senior Airman****", 13: "Senior Airman*****", + 14: "Staff Sergeant", 15: "Staff Sergeant*", 16: "Staff Sergeant**", 17: "Staff Sergeant***", + 18: "Staff Sergeant****", 19: "Staff Sergeant*****", 20: "Aviator", 21: "Aviator*", 22: "Aviator**", + 23: "Aviator***", 24: "Aviator****", 25: "Aviator*****", 26: "Flight Lieutenant", 27: "Flight Lieutenant*", + 28: "Flight Lieutenant**", 29: "Flight Lieutenant***", 30: "Flight Lieutenant****", 31: "Flight Lieutenant*****", + 32: "Squadron Leader", 33: "Squadron Leader*", 34: "Squadron Leader**", 35: "Squadron Leader***", + 36: "Squadron Leader****", 37: "Squadron Leader*****", 38: "Chief Master Sergeant", 39: "Chief Master Sergeant*", + 40: "Chief Master Sergeant**", 41: "Chief Master Sergeant***", 42: "Chief Master Sergeant****", + 43: "Chief Master Sergeant*****", 44: "Wing Commander", 45: "Wing Commander*", 46: "Wing Commander**", + 47: "Wing Commander***", 48: "Wing Commander****", 49: "Wing Commander*****", 50: "Group Captain", + 51: "Group Captain*", 52: "Group Captain**", 53: "Group Captain***", 54: "Group Captain****", + 55: "Group Captain*****", 56: "Air Commodore", 57: "Air Commodore*", 58: "Air Commodore**", 59: "Air Commodore***", + 60: "Air Commodore****", 61: "Air Commodore*****", +} GROUND_RANKS: Dict[int, str] = { 1: "Recruit", 2: "Private", 3: "Private*", 4: "Private**", 5: "Private***", @@ -107,12 +123,12 @@ COUNTRY_LINK: Dict[int, str] = { } ISO_CC: Dict[int, str] = { - 1: 'ROU', 9: 'BRA', 10: 'ITA', 11: 'FRA', 12: 'DEU', 13: 'HUN', 14: 'CHN', 15: 'ESP', 23: 'CAN', 24: 'USA', - 26: 'MEX', 27: 'ARG', 28: 'VEN', 29: 'GBR', 30: 'CHE', 31: 'NLD', 32: 'BEL', 33: 'AUT', 34: 'CZE', 35: 'POL', - 36: 'SVK', 37: 'NOR', 38: 'SWE', 39: 'FIN', 40: 'UKR', 41: 'RUS', 42: 'BGR', 43: 'TUR', 44: 'GRC', 45: 'JPN', - 47: 'KOR', 48: 'IND', 49: 'IDN', 50: 'AUS', 51: 'ZAF', 52: 'MDA', 53: 'PRT', 54: 'IRL', 55: 'DNK', 56: 'IRN', - 57: 'PAK', 58: 'ISR', 59: 'THA', 61: 'SVN', 63: 'HRV', 64: 'CHL', 65: 'SRB', 66: 'MYS', 67: 'PHL', 68: 'SGP', - 69: 'BiH', 70: 'EST', 71: 'LVA', 72: 'LTU', 73: 'PRK', 74: 'URY', 75: 'PRY', 76: 'BOL', 77: 'PER', 78: 'COL', + 1: 'ROU', 9: 'BRA', 10: 'ITA', 11: 'FRA', 12: 'DEU', 13: 'HUN', 14: 'CHN', 15: 'ESP', 23: 'CAN', 24: 'USA', + 26: 'MEX', 27: 'ARG', 28: 'VEN', 29: 'GBR', 30: 'CHE', 31: 'NLD', 32: 'BEL', 33: 'AUT', 34: 'CZE', 35: 'POL', + 36: 'SVK', 37: 'NOR', 38: 'SWE', 39: 'FIN', 40: 'UKR', 41: 'RUS', 42: 'BGR', 43: 'TUR', 44: 'GRC', 45: 'JPN', + 47: 'KOR', 48: 'IND', 49: 'IDN', 50: 'AUS', 51: 'ZAF', 52: 'MDA', 53: 'PRT', 54: 'IRL', 55: 'DNK', 56: 'IRN', + 57: 'PAK', 58: 'ISR', 59: 'THA', 61: 'SVN', 63: 'HRV', 64: 'CHL', 65: 'SRB', 66: 'MYS', 67: 'PHL', 68: 'SGP', + 69: 'BiH', 70: 'EST', 71: 'LVA', 72: 'LTU', 73: 'PRK', 74: 'URY', 75: 'PRY', 76: 'BOL', 77: 'PER', 78: 'COL', 79: 'MKD', 80: 'MNE', 81: 'TWN', 82: 'CYP', 83: 'BLR', 84: 'NZL', 164: 'SAU', 165: 'EGY', 166: 'UAE', 167: 'ALB', 168: 'GEO', 169: 'ARM', 170: 'NGA', 171: 'CUB', }