Compare commits

..

No commits in common. "master" and "v0.29.0.5" have entirely different histories.

10 changed files with 33 additions and 41 deletions

View File

@ -21,7 +21,7 @@ insert_final_newline = false
indent_style = tab indent_style = tab
[*.py] [*.py]
max_line_length = 120 max_line_length = 240
line_length=120 line_length=120
multi_line_output=0 multi_line_output=0
balanced_wrapping=True balanced_wrapping=True

View File

@ -4,7 +4,7 @@
__author__ = """Eriks Karls""" __author__ = """Eriks Karls"""
__email__ = "eriks@72.lv" __email__ = "eriks@72.lv"
__version__ = "0.29.2.3" __version__ = "0.29.0.5"
from erepublik.citizen import Citizen from erepublik.citizen import Citizen

View File

@ -327,7 +327,7 @@ class BaseCitizen(access_points.CitizenAPI):
r"((?P<amount>\d+) item\(s\) )?[eE]xpires? on Day (?P<eday>\d,\d{3}), (?P<time>\d\d:\d\d)", r"((?P<amount>\d+) item\(s\) )?[eE]xpires? on Day (?P<eday>\d,\d{3}), (?P<time>\d\d:\d\d)",
_expire_value, _expire_value,
).groupdict() ).groupdict()
eday = utils.date_from_eday(int(_data["eday"].replace(",", ""))).date() eday = utils.date_from_eday(int(_data["eday"].replace(",", "")))
dt = constants.erep_tz.localize(datetime.combine(eday, time(*[int(_) for _ in _data["time"].split(":")]))) dt = constants.erep_tz.localize(datetime.combine(eday, time(*[int(_) for _ in _data["time"].split(":")])))
return {"amount": _data.get("amount"), "expiration": dt} return {"amount": _data.get("amount"), "expiration": dt}
@ -1961,7 +1961,7 @@ class CitizenTasks(CitizenEconomy):
else: else:
self.reporter.report_action("WORK", json_val=js) self.reporter.report_action("WORK", json_val=js)
else: else:
seconds = 360 - self.now.timestamp() % 360 seconds = self.now.timestamp() % 360
self.write_warning(f"I don't have energy to work. Will sleep for {seconds}s") self.write_warning(f"I don't have energy to work. Will sleep for {seconds}s")
self.sleep(seconds) self.sleep(seconds)
self.work() self.work()
@ -2007,7 +2007,7 @@ class CitizenTasks(CitizenEconomy):
self.buy_food(120) self.buy_food(120)
self.reporter.report_action("WORK_OT", r.json()) self.reporter.report_action("WORK_OT", r.json())
elif self.energy.food_fights < 1 and self.ot_points >= 24: elif self.energy.food_fights < 1 and self.ot_points >= 24:
seconds = 360 - self.now.timestamp() % 360 seconds = self.now.timestamp() % 360
self.write_warning(f"I don't have energy to work OT. Will sleep for {seconds}s") self.write_warning(f"I don't have energy to work OT. Will sleep for {seconds}s")
self.sleep(seconds) self.sleep(seconds)
self.work_ot() self.work_ot()
@ -2281,9 +2281,9 @@ class _Citizen(
if data and kind in self.config.auto_sell: if data and kind in self.config.auto_sell:
if kind in ["food", "weapon", "house", "airplane"]: if kind in ["food", "weapon", "house", "airplane"]:
for quality, amount in data.items(): for quality, amount in data.items():
self.sell_produced_product(kind, quality, int(data)) self.sell_produced_product(kind, quality)
elif kind.endswith("Raw"): elif kind.endswith("Raw"):
self.sell_produced_product(kind, 1, int(data)) self.sell_produced_product(kind, 1)
else: else:
raise classes.ErepublikException(f"Unknown kind produced '{kind}'") raise classes.ErepublikException(f"Unknown kind produced '{kind}'")
elif self.config.auto_buy_raw and re.search(r"not_enough_[^_]*_raw", response.get("message")): elif self.config.auto_buy_raw and re.search(r"not_enough_[^_]*_raw", response.get("message")):
@ -2340,7 +2340,7 @@ class _Citizen(
def work_as_manager(self) -> bool: def work_as_manager(self) -> bool:
"""Does Work as Manager in all holdings with wam. If employees assigned - work them also """Does Work as Manager in all holdings with wam. If employees assigned - work them also
:return: if there is more wam work to do :return: if has more wam work to do
:rtype: bool :rtype: bool
""" """
if self.restricted_ip: if self.restricted_ip:
@ -2348,23 +2348,17 @@ class _Citizen(
return False return False
self.update_citizen_info() self.update_citizen_info()
self.update_companies() self.update_companies()
wam_holdings: List[classes.Holding] = [ regions: Dict[int, classes.Holding] = {}
holding for holding in self.my_companies.get_wam_holdings() if holding.wam_count for holding in self.my_companies.holdings.values():
] if holding.wam_count:
regions.update({holding.region: holding})
# Check for current region # Check for current region
for holding in wam_holdings: if self.details.current_region in regions:
if holding.region == self.details.current_region: self._wam(regions.pop(self.details.current_region))
self._wam(holding) self.update_companies()
self.update_companies()
wam_holdings: List[classes.Holding] = [
holding for holding in wam_holdings if not holding.region == self.details.current_region
]
for holding in wam_holdings: for holding in regions.values():
# Don't travel if not enough energy (either work in all holding factories or 2h energy worth)
if self.energy.energy < 2 * self.energy.interval * 10 < holding.wam_count * 10:
break
raw_usage = holding.get_wam_raw_usage() raw_usage = holding.get_wam_raw_usage()
free_storage = self.inventory.total - self.inventory.used free_storage = self.inventory.total - self.inventory.used
if (raw_usage["frm"] + raw_usage["wrm"]) * 100 > free_storage: if (raw_usage["frm"] + raw_usage["wrm"]) * 100 > free_storage:
@ -2375,6 +2369,9 @@ class _Citizen(
self.update_companies() self.update_companies()
wam_count = self.my_companies.get_total_wam_count() wam_count = self.my_companies.get_total_wam_count()
# if wam_count:
# self.logger.debug(f"Wam ff lockdown is now {wam_count}, was {self.my_companies.ff_lockdown}")
# self.my_companies.ff_lockdown = wam_count
self.travel_to_residence() self.travel_to_residence()
return bool(wam_count) return bool(wam_count)

View File

@ -388,11 +388,11 @@ class MyCompanies:
if raw > 0: if raw > 0:
to_remove = sorted(raw_factories, key=lambda c: (c.industry not in ids, c.raw_usage)) to_remove = sorted(raw_factories, key=lambda c: (c.industry not in ids, c.raw_usage))
if to_remove: if to_remove:
return raw_factories.pop(raw_factories.index(to_remove[0])) return raw_factories.pop(raw_factories.idex(to_remove[0]))
else: else:
to_remove = sorted(final_factories, key=lambda c: (c.industry != ids[0], c.raw_usage)) to_remove = sorted(final_factories, key=lambda c: (c.industry != ids[0], c.raw_usage))
if to_remove: if to_remove:
return final_factories.pop(final_factories.index(to_remove[0])) return final_factories.pop(final_factories.idex(to_remove[0]))
def get_raw_usage_for_companies(self, *companies: Company) -> Tuple[Decimal, Decimal, Decimal, Decimal]: def get_raw_usage_for_companies(self, *companies: Company) -> Tuple[Decimal, Decimal, Decimal, Decimal]:
frm = wrm = hrm = arm = Decimal("0.00") frm = wrm = hrm = arm = Decimal("0.00")
@ -411,12 +411,6 @@ class MyCompanies:
def companies(self) -> Generator[Company, None, None]: def companies(self) -> Generator[Company, None, None]:
return (c for c in self._companies) return (c for c in self._companies)
def get_wam_holdings(self) -> Generator[Holding, None, None]:
for holding in sorted(
self.holdings.values(), key=lambda h: (-len(h.get_wam_companies(False)), -len(h.get_wam_companies()))
):
yield holding
def __str__(self): def __str__(self):
return f"MyCompanies: {sum(1 for _ in self.companies)} companies in {len(self.holdings)} holdings" return f"MyCompanies: {sum(1 for _ in self.companies)} companies in {len(self.holdings)} holdings"

View File

@ -121,6 +121,7 @@ class Industries:
14: "WRM q3", 14: "WRM q3",
15: "WRM q4", 15: "WRM q4",
16: "WRM q5", 16: "WRM q5",
17: "houseRaw",
18: "houseRaw", 18: "houseRaw",
19: "HRM q2", 19: "HRM q2",
20: "HRM q3", 20: "HRM q3",

View File

@ -93,7 +93,7 @@ def eday_from_date(date: Union[datetime.date, datetime.datetime] = None) -> int:
return (date - datetime.datetime(2007, 11, 20, 0, 0, 0)).days return (date - datetime.datetime(2007, 11, 20, 0, 0, 0)).days
def date_from_eday(eday: int) -> datetime.datetime: def date_from_eday(eday: int) -> datetime.date:
return localize_dt(datetime.date(2007, 11, 20)) + datetime.timedelta(days=eday) return localize_dt(datetime.date(2007, 11, 20)) + datetime.timedelta(days=eday)

View File

@ -1,16 +1,16 @@
-r requirements.txt -r requirements.txt
-r requirements-tests.txt -r requirements-tests.txt
bump2version==1.0.1 bump2version==1.0.1
coverage==6.3.2 coverage==6.3
edx-sphinx-theme==3.0.0 edx-sphinx-theme==3.0.0
flake8==4.0.1 flake8==4.0.1
ipython>=8.1.1 ipython>=8.0.1
jedi!=0.18.0 jedi!=0.18.0
isort==5.10.1 isort==5.10.1
pre-commit==2.17.0 pre-commit==2.17.0
pur==6.0.1 pur==6.0.1
responses==0.18.0 responses==0.17.0
Sphinx==4.4.0 Sphinx==4.4.0
twine==3.8.0 twine==3.7.1
wheel==0.37.1 wheel==0.37.1
black==22.1.0 black==22.1.0

View File

@ -1,2 +1,2 @@
-r requirements.txt -r requirements.txt
pytest==7.0.1 pytest==6.2.5

View File

@ -1,5 +1,5 @@
[bumpversion] [bumpversion]
current_version = 0.29.2.3 current_version = 0.29.0.5
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+)?
@ -19,8 +19,8 @@ universal = 1
[flake8] [flake8]
exclude = docs,.git,log,debug,venv exclude = docs,.git,log,debug,venv
line_length = 120 line_length = 140
max-line-length = 120 max-line-length = 140
ignore = D100,D101,D102,D103,E203 ignore = D100,D101,D102,D103,E203
[pycodestyle] [pycodestyle]
@ -38,4 +38,4 @@ warn_unused_configs = True
[isort] [isort]
multi_line_output = 2 multi_line_output = 2
line_length = 120 line_length = 140

View File

@ -49,6 +49,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.29.2.3", version="0.29.0.5",
zip_safe=False, zip_safe=False,
) )