Compare commits

...

8 Commits

7 changed files with 18 additions and 20 deletions

View File

@ -4,7 +4,7 @@
__author__ = """Eriks Karls"""
__email__ = 'eriks@72.lv'
__version__ = '0.23.2.3'
__version__ = '0.23.2.6'
from erepublik import classes, utils, constants
from erepublik.citizen import Citizen

View File

@ -29,14 +29,10 @@ class SlowRequests(Session):
'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: bool = False
@ -87,7 +83,9 @@ class SlowRequests(Session):
body = "[{dt}]\tURL: '{url}'\tMETHOD: {met}\tARGS: {args}\n".format(dt=utils.now().strftime("%F %T"),
url=url, met=method, args=args)
utils.write_file(self.request_log_name, body)
with open(self.request_log_name, 'ab') as file:
file.write(body.encode("UTF-8"))
pass
def _log_response(self, url, resp, redirect: bool = False):
from erepublik import Citizen
@ -111,8 +109,7 @@ class SlowRequests(Session):
file_data.update({"ext": "html"})
filename = 'debug/requests/{time}_{name}{extra}.{ext}'.format(**file_data)
with open(utils.get_file(filename), 'wb') as f:
f.write(resp.text.encode('utf-8'))
utils.write_file(filename, resp.text)
pass

View File

@ -417,7 +417,6 @@ class BaseCitizen(access_points.CitizenAPI):
else:
utils.process_error(msg, self.name, sys.exc_info(), self, None, None)
@utils.wait_for_lock
def sleep(self, seconds: int):
if seconds < 0:
seconds = 0
@ -1027,7 +1026,6 @@ class CitizenEconomy(CitizenTravel):
ret.update({house_quality: till})
return ret
@utils.wait_for_lock
def buy_and_activate_house(self, q: int) -> Optional[Dict[int, datetime]]:
original_region = self.details.current_country, self.details.current_region
ok_to_activate = False
@ -1042,12 +1040,14 @@ class CitizenEconomy(CitizenTravel):
global_cheapest = self.get_market_offers("House", q)[f"q{q}"]
if global_cheapest.price + 200 < local_cheapest.price:
if self.travel_to_country(global_cheapest.country):
buy = self.buy_from_market(global_cheapest.offer_id, 1)
buy = self.buy_market_offer(global_cheapest, 1)
else:
buy = {'error': True, 'message': 'Unable to travel!'}
else:
buy = self.buy_from_market(local_cheapest.offer_id, 1)
if buy["error"]:
buy = self.buy_market_offer(local_cheapest, 1)
if buy is None:
pass
elif buy["error"]:
msg = f"Unable to buy q{q} house! \n{buy['message']}"
self.write_log(msg)
else:
@ -1688,7 +1688,8 @@ class CitizenMilitary(CitizenTravel):
return bool(self.__last_war_update_data.get("citizen_contribution", []))
def find_battle_to_fight(self, silent: bool = False) -> Tuple[
classes.Battle, classes.BattleDivision, classes.BattleSide]:
classes.Battle, classes.BattleDivision, classes.BattleSide
]:
self.update_war_info()
for battle in self.sorted_battles(self.config.sort_battles_time):
if not isinstance(battle, classes.Battle):
@ -1698,11 +1699,11 @@ class CitizenMilitary(CitizenTravel):
if div.terrain == 0:
if div.div_end:
continue
maverick_ok = self.maverick and self.config.maverick
if self.config.air and div.is_air:
battle_zone = div
break
elif self.config.ground and not div.is_air and (
div.div == self.division or (self.maverick and self.config.maverick)):
elif self.config.ground and not div.is_air and (div.div == self.division or maverick_ok):
battle_zone = div
break
else:

View File

@ -1016,7 +1016,7 @@ class TelegramBot:
class OfferItem(NamedTuple):
price: float = 99_999.
price: float = 999_999_999.
country: constants.Country = constants.Country(0, "", "", "")
amount: int = 0
offer_id: int = 0

View File

@ -25,7 +25,7 @@ __all__ = ['VERSION', 'calculate_hit', 'caught_error', 'date_from_eday', 'eday_f
'get_air_hit_dmg_value', 'get_file', 'get_ground_hit_dmg_value', 'get_sleep_seconds', 'good_timedelta',
'interactive_sleep', 'json', 'localize_dt', 'localize_timestamp', 'normalize_html_json', 'now',
'process_error', 'process_warning', 'send_email', 'silent_sleep', 'slugify', 'write_file',
'write_interactive_log', 'write_silent_log']
'write_interactive_log', 'write_silent_log', 'get_final_hit_dmg', 'wait_for_lock']
if not sys.version_info >= (3, 6):
raise AssertionError('This script requires Python version 3.6 and higher\n'

View File

@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.23.2.3
current_version = 0.23.2.6
commit = True
tag = True
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)\.?(?P<dev>\d+)?

View File

@ -50,6 +50,6 @@ setup(
test_suite='tests',
tests_require=test_requirements,
url='https://github.com/eeriks/erepublik/',
version='0.23.2.3',
version='0.23.2.6',
zip_safe=False,
)