Compare commits

...

21 Commits

Author SHA1 Message Date
c0122eccdf Bump version: 0.23.2.9 → 0.23.2.10 2020-12-08 18:05:21 +02:00
2524173da0 Telegram bot's token can be reused 2020-12-08 18:05:18 +02:00
4a4b991faf Telegram bot's token can be reused 2020-12-08 18:05:01 +02:00
e87c48124c Bump version: 0.23.2.8 → 0.23.2.9 2020-12-07 14:10:52 +02:00
f0f47566a0 Bugfix: Don't travel to renew house if You can't afford the house 2020-12-07 14:10:40 +02:00
f88eaccf67 Bump version: 0.23.2.7 → 0.23.2.8 2020-12-07 14:01:29 +02:00
7be129a781 Quickfix for forbidding Dictatorship/Liberation wars 2020-12-07 14:01:22 +02:00
32546505b9 Bump version: 0.23.2.6 → 0.23.2.7 2020-12-04 13:13:17 +02:00
00ceabf8e3 cleanup 2020-12-04 13:13:10 +02:00
19113da8e6 cleanup 2020-12-04 13:11:11 +02:00
3ad7172925 cleanup 2020-12-04 13:08:42 +02:00
179f1a0892 Only init TelegramReporter if both chat id and token have been supplied 2020-12-04 13:08:16 +02:00
65adf707e2 Only init TelegramReporter if both chat id and token have been supplied 2020-12-04 13:08:04 +02:00
29f9ce5ccc Bump version: 0.23.2.5 → 0.23.2.6 2020-12-02 18:40:41 +02:00
fa3881bf10 Updated classes.OfferItem default price to be higher considerably higher than max price for cheapest most expensive items on sale (Q5 houses), Updated house renewal 2020-12-02 18:40:33 +02:00
c1e8e94cba Bump version: 0.23.2.4 → 0.23.2.5 2020-12-02 13:00:51 +02:00
8133461fd7 pep8 2020-12-02 13:00:33 +02:00
c87333411a Hotfix 2020-12-02 12:56:06 +02:00
d679006b34 small fix 2020-12-01 18:56:14 +02:00
fa308db074 Bump version: 0.23.2.3 → 0.23.2.4 2020-12-01 18:49:35 +02:00
a080163af9 Bugfix 2020-12-01 18:49:33 +02:00
7 changed files with 40 additions and 37 deletions

View File

@ -4,7 +4,7 @@
__author__ = """Eriks Karls""" __author__ = """Eriks Karls"""
__email__ = 'eriks@72.lv' __email__ = 'eriks@72.lv'
__version__ = '0.23.2.3' __version__ = '0.23.2.10'
from erepublik import classes, utils, constants from erepublik import classes, utils, constants
from erepublik.citizen import Citizen 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: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: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: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: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: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: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: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 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"), body = "[{dt}]\tURL: '{url}'\tMETHOD: {met}\tARGS: {args}\n".format(dt=utils.now().strftime("%F %T"),
url=url, met=method, args=args) 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): def _log_response(self, url, resp, redirect: bool = False):
from erepublik import Citizen from erepublik import Citizen
@ -111,8 +109,7 @@ class SlowRequests(Session):
file_data.update({"ext": "html"}) file_data.update({"ext": "html"})
filename = 'debug/requests/{time}_{name}{extra}.{ext}'.format(**file_data) filename = 'debug/requests/{time}_{name}{extra}.{ext}'.format(**file_data)
with open(utils.get_file(filename), 'wb') as f: utils.write_file(filename, resp.text)
f.write(resp.text.encode('utf-8'))
pass pass

View File

@ -417,7 +417,6 @@ class BaseCitizen(access_points.CitizenAPI):
else: else:
utils.process_error(msg, self.name, sys.exc_info(), self, None, None) utils.process_error(msg, self.name, sys.exc_info(), self, None, None)
@utils.wait_for_lock
def sleep(self, seconds: int): def sleep(self, seconds: int):
if seconds < 0: if seconds < 0:
seconds = 0 seconds = 0
@ -1027,7 +1026,6 @@ class CitizenEconomy(CitizenTravel):
ret.update({house_quality: till}) ret.update({house_quality: till})
return ret return ret
@utils.wait_for_lock
def buy_and_activate_house(self, q: int) -> Optional[Dict[int, datetime]]: def buy_and_activate_house(self, q: int) -> Optional[Dict[int, datetime]]:
original_region = self.details.current_country, self.details.current_region original_region = self.details.current_country, self.details.current_region
ok_to_activate = False ok_to_activate = False
@ -1041,14 +1039,22 @@ class CitizenEconomy(CitizenTravel):
global_cheapest = self.get_market_offers("House", q)[f"q{q}"] global_cheapest = self.get_market_offers("House", q)[f"q{q}"]
if global_cheapest.price + 200 < local_cheapest.price: if global_cheapest.price + 200 < local_cheapest.price:
if global_cheapest.price + 2000 < self.details.cc:
if self.travel_to_country(global_cheapest.country): 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: else:
buy = {'error': True, 'message': 'Unable to travel!'} buy = dict(error=True, message='Unable to travel!')
else: else:
buy = self.buy_from_market(local_cheapest.offer_id, 1) buy = dict(error=True, message='Not enough money to buy house!')
if buy["error"]: else:
msg = f"Unable to buy q{q} house! \n{buy['message']}" if local_cheapest.price < self.details.cc:
buy = self.buy_market_offer(local_cheapest, 1)
else:
buy = dict(error=True, message='Not enough money to buy house!')
if buy is None:
pass
elif buy["error"]:
msg = f'Unable to buy q{q} house! \n{buy["message"]}'
self.write_log(msg) self.write_log(msg)
else: else:
ok_to_activate = True ok_to_activate = True
@ -1152,11 +1158,13 @@ class CitizenEconomy(CitizenTravel):
return False return False
def post_market_offer(self, industry: int, quality: int, amount: int, price: float) -> bool: def post_market_offer(self, industry: int, quality: int, amount: int, price: float) -> bool:
if isinstance(industry, str):
industry = constants.INDUSTRIES[industry]
if not constants.INDUSTRIES[industry]: if not constants.INDUSTRIES[industry]:
self.write_log(f"Trying to sell unsupported industry {industry}") self.write_log(f"Trying to sell unsupported industry {industry}")
_inv_qlt = quality if industry in [1, 2, 3, 4, 23] else 0 _inv_qlt = quality if industry in [1, 2, 3, 4, 23] else 0
_kind = 'final' if industry in [1, 2, 4, 4, 23] else 'raw' _kind = 'final' if industry in [1, 2, 4, 23] else 'raw'
inventory = self.get_inventory() inventory = self.get_inventory()
items = inventory[_kind].get(constants.INDUSTRIES[industry], {_inv_qlt: {'amount': 0}}) items = inventory[_kind].get(constants.INDUSTRIES[industry], {_inv_qlt: {'amount': 0}})
if items[_inv_qlt]['amount'] < amount: if items[_inv_qlt]['amount'] < amount:
@ -1181,7 +1189,7 @@ class CitizenEconomy(CitizenTravel):
self._report_action("ECONOMY_SELL_PRODUCTS", message, kwargs=ret) self._report_action("ECONOMY_SELL_PRODUCTS", message, kwargs=ret)
return not bool(ret.get('error', True)) return not bool(ret.get('error', True))
def buy_from_market(self, offer: int, amount: int) -> dict: def buy_from_market(self, offer: int, amount: int) -> Dict[str, Any]:
ret = self._post_economy_marketplace_actions('buy', offer=offer, amount=amount) ret = self._post_economy_marketplace_actions('buy', offer=offer, amount=amount)
json_ret = ret.json() json_ret = ret.json()
if not json_ret.get('error', True): if not json_ret.get('error', True):
@ -1199,13 +1207,7 @@ class CitizenEconomy(CitizenTravel):
if not self.details.current_country == offer.country: if not self.details.current_country == offer.country:
traveled = True traveled = True
self.travel_to_country(offer.country) self.travel_to_country(offer.country)
ret = self._post_economy_marketplace_actions('buy', offer=offer.offer_id, amount=amount) json_ret = self.buy_from_market(offer.offer_id, amount)
json_ret = ret.json()
if not json_ret.get('error', True):
self.details.cc = ret.json()['currency']
self.details.gold = ret.json()['gold']
json_ret.pop("offerUpdate", None)
self._report_action("BOUGHT_PRODUCTS", json_ret.get('message'), kwargs=json_ret)
if traveled: if traveled:
self.travel_to_residence() self.travel_to_residence()
return json_ret return json_ret
@ -1688,21 +1690,24 @@ class CitizenMilitary(CitizenTravel):
return bool(self.__last_war_update_data.get("citizen_contribution", [])) return bool(self.__last_war_update_data.get("citizen_contribution", []))
def find_battle_to_fight(self, silent: bool = False) -> Tuple[ 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() self.update_war_info()
for battle in self.sorted_battles(self.config.sort_battles_time): for battle in self.sorted_battles(self.config.sort_battles_time):
if not isinstance(battle, classes.Battle): if not isinstance(battle, classes.Battle):
continue continue
if battle.is_dict_lib:
continue
battle_zone: Optional[classes.BattleDivision] = None battle_zone: Optional[classes.BattleDivision] = None
for div in battle.div.values(): for div in battle.div.values():
if div.terrain == 0: if div.terrain == 0:
if div.div_end: if div.div_end:
continue continue
maverick_ok = self.maverick and self.config.maverick
if self.config.air and div.is_air: if self.config.air and div.is_air:
battle_zone = div battle_zone = div
break break
elif self.config.ground and not div.is_air and ( elif self.config.ground and not div.is_air and (div.div == self.division or maverick_ok):
div.div == self.division or (self.maverick and self.config.maverick)):
battle_zone = div battle_zone = div
break break
else: else:
@ -1844,6 +1849,9 @@ class CitizenMilitary(CitizenTravel):
elif r_json.get("message") == "ZONE_INACTIVE": elif r_json.get("message") == "ZONE_INACTIVE":
self.write_log("Wrong division!!") self.write_log("Wrong division!!")
return 0, 10, 0 return 0, 10, 0
elif r_json.get("message") == "NON_BELLIGERENT":
self.write_log("Dictatorship/Liberation wars are not supported!")
return 0, 10, 0
elif r_json.get("message") in ["FIGHT_DISABLED", "DEPLOYMENT_MODE"]: elif r_json.get("message") in ["FIGHT_DISABLED", "DEPLOYMENT_MODE"]:
self._post_main_profile_update('options', self._post_main_profile_update('options',
params='{"optionName":"enable_web_deploy","optionValue":"off"}') params='{"optionName":"enable_web_deploy","optionValue":"off"}')
@ -2440,11 +2448,10 @@ class Citizen(CitizenAnniversary, CitizenCompanies, CitizenEconomy, CitizenLeade
self.update_citizen_info() self.update_citizen_info()
self.reporter.do_init() self.reporter.do_init()
if self.config.telegram: if self.config.telegram and self.config.telegram_chat_id:
# noinspection SpellCheckingInspection self.telegram.do_init(self.config.telegram_chat_id,
self.telegram.do_init(self.config.telegram_chat_id or 620981703,
self.config.telegram_token or "864251270:AAFzZZdjspI-kIgJVk4gF3TViGFoHnf8H4o", self.config.telegram_token or "864251270:AAFzZZdjspI-kIgJVk4gF3TViGFoHnf8H4o",
"" if self.config.telegram_chat_id or self.config.telegram_token else self.name) self.name)
self.telegram.send_message(f"*Started* {utils.now():%F %T}") self.telegram.send_message(f"*Started* {utils.now():%F %T}")
self.update_all(True) self.update_all(True)
@ -2465,7 +2472,6 @@ class Citizen(CitizenAnniversary, CitizenCompanies, CitizenEconomy, CitizenLeade
if self.details.gold >= 54: if self.details.gold >= 54:
self.buy_tg_contract() self.buy_tg_contract()
else: else:
self.write_log(f"Training ground contract active but " self.write_log(f"Training ground contract active but "
f"don't have enough gold ({self.details.gold}g {self.details.cc}cc)") f"don't have enough gold ({self.details.gold}g {self.details.cc}cc)")
if self.energy.is_energy_full and self.config.telegram: if self.energy.is_energy_full and self.config.telegram:

View File

@ -1016,7 +1016,7 @@ class TelegramBot:
class OfferItem(NamedTuple): class OfferItem(NamedTuple):
price: float = 99_999. price: float = 999_999_999.
country: constants.Country = constants.Country(0, "", "", "") country: constants.Country = constants.Country(0, "", "", "")
amount: int = 0 amount: int = 0
offer_id: 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', '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', 'interactive_sleep', 'json', 'localize_dt', 'localize_timestamp', 'normalize_html_json', 'now',
'process_error', 'process_warning', 'send_email', 'silent_sleep', 'slugify', 'write_file', '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): if not sys.version_info >= (3, 6):
raise AssertionError('This script requires Python version 3.6 and higher\n' raise AssertionError('This script requires Python version 3.6 and higher\n'

View File

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

View File

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