Compare commits

..

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

18 changed files with 242 additions and 288 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

@ -19,15 +19,7 @@ jobs:
- name: Install dependencies - name: Install dependencies
run: | run: |
python -m pip install --upgrade pip python -m pip install --upgrade pip
pip install -r requirements-dev.txt pip install -r requirements_dev.txt
- name: Lint with isort
run: |
pip install -U isort
isort --check erepublik
- name: Lint with Black
run: |
pip install -U black
black --check erepublik
- name: Lint with flake8 - name: Lint with flake8
run: | run: |
pip install flake8 pip install flake8
@ -35,7 +27,7 @@ jobs:
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
# - name: Test with pytest - name: Test with pytest
# run: | run: |
# pip install pytest pip install pytest
# pytest pytest

13
.pre-commit-config.yaml Normal file
View File

@ -0,0 +1,13 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
default_language_version:
python: python3.8

View File

@ -1,15 +0,0 @@
version: 2
build:
os: "ubuntu-20.04"
tools:
python: "3.9"
# Build from the docs/ directory with Sphinx
sphinx:
configuration: docs/conf.py
# Explicitly set the version of Python and its requirements
python:
install:
- requirements: requirements-dev.txt

View File

@ -10,13 +10,16 @@ eRepublik script
:target: https://erepublik.readthedocs.io/en/latest/?badge=latest :target: https://erepublik.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status :alt: Documentation Status
.. image:: https://api.codacy.com/project/badge/Grade/eaa7ae43d23f4c0abab65c3bde89475a
:target: https://app.codacy.com/manual/eeriks/erepublik?utm_source=github.com&utm_medium=referral&utm_content=eeriks/erepublik&utm_campaign=Badge_Grade_Dashboard
:alt: Codacy Badge
Python package for automated eRepublik playing Python package for automated eRepublik playing
* Free software: GPLv3.0 * Free software: MIT license
* Documentation: https://erepublik.readthedocs.io/en/latest/ * Documentation: https://erepublik.readthedocs.io/en/latest/
* Source code: https://github.com/eeriks/erepublik
Features Features

View File

@ -101,7 +101,7 @@ html_theme_path = [edx_theme.get_html_theme_path()]
# Add any paths that contain custom static files (such as style sheets) here, # Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files, # relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css". # so a file named "default.css" will overwrite the builtin "default.css".
# html_static_path = ["_static"] html_static_path = ["_static"]
# -- Options for HTMLHelp output --------------------------------------- # -- Options for HTMLHelp output ---------------------------------------

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.28.0.1"
from erepublik.citizen import Citizen from erepublik.citizen import Citizen

View File

@ -23,7 +23,7 @@ class SlowRequests(Session):
if proxies: if proxies:
self.proxies = proxies self.proxies = proxies
if user_agent is None: if user_agent is None:
user_agent = self.get_random_user_agent() user_agent = random.choice(self.get_random_user_agent())
self.request_log_name = utils.get_file(utils.now().strftime("debug/requests_%Y-%m-%d.log")) self.request_log_name = utils.get_file(utils.now().strftime("debug/requests_%Y-%m-%d.log"))
self.last_time = utils.now() self.last_time = utils.now()
self.headers.update({"User-Agent": user_agent}) self.headers.update({"User-Agent": user_agent})
@ -110,15 +110,24 @@ class SlowRequests(Session):
def get_random_user_agent() -> str: def get_random_user_agent() -> str:
windows_x64 = "Windows NT 10.0; Win64; x64" windows_x64 = "Windows NT 10.0; Win64; x64"
linux_x64 = "X11; Linux x86_64" linux_x64 = "X11; Linux x86_64"
android = [] # [f"Android {version}; Mobile" for version in range(10, 13)] android = [f"Android {version}; Mobile" for version in range(8, 12)]
firefox_template = "Mozilla/5.0 ({osystem}; rv:{version}.0) Gecko/20100101 Firefox/{version}.0" firefox_template = "Mozilla/5.0 ({osystem}; rv:{version}.0) Gecko/20100101 Firefox/{version}.0"
firefox_versions = range(92, 97) firefox_versions = range(85, 92)
chrome_template = ( chrome_template = (
"Mozilla/5.0 ({osystem}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/{version} Safari/537.36" "Mozilla/5.0 ({osystem}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/{version} Safari/537.36"
) )
chrome_versions = ["92.0.4515.159", "93.0.4577.82", "94.0.4606.81", "95.0.4638.54", "96.0.4664.110"] chrome_versions = [
"85.0.4183.121",
"86.0.4240.183",
"87.0.4280.141",
"88.0.4324.182",
"89.0.4389.128",
"90.0.4430.18",
"91.0.4472.73",
"92.0.4515.159",
]
uas = [] uas = []
for osystem in [windows_x64, linux_x64, *android]: for osystem in [windows_x64, linux_x64, *android]:

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}
@ -1172,27 +1172,23 @@ class CitizenCompanies(BaseCitizen):
if self.restricted_ip: if self.restricted_ip:
return None return None
self.update_companies() self.update_companies()
self.update_inventory()
data = {"action_type": "production"} data = {"action_type": "production"}
extra = {} extra = {}
raw_factories = wam_holding.get_wam_companies(raw_factory=True) raw_factories = wam_holding.get_wam_companies(raw_factory=True)
fin_factories = wam_holding.get_wam_companies(raw_factory=False) fin_factories = wam_holding.get_wam_companies(raw_factory=False)
free_inventory = self.inventory.total - self.inventory.used free_inventory = self.inventory.total - self.inventory.used
for _ in range(len(fin_factories + raw_factories) - self.energy.food_fights): wam_list = raw_factories + fin_factories
if not self.my_companies.remove_factory_from_wam_list(raw_factories, fin_factories): wam_list = wam_list[: self.energy.food_fights]
raise classes.ErepublikException("Nothing removed from WAM list!")
if int(free_inventory * 0.75) < self.my_companies.get_needed_inventory_usage(fin_factories + raw_factories): if int(free_inventory * 0.75) < self.my_companies.get_needed_inventory_usage(wam_list):
self.update_inventory()
free_inventory = self.inventory.total - self.inventory.used free_inventory = self.inventory.total - self.inventory.used
while (fin_factories + raw_factories) and free_inventory < self.my_companies.get_needed_inventory_usage( while wam_list and free_inventory < self.my_companies.get_needed_inventory_usage(wam_list):
fin_factories + raw_factories wam_list.pop(-1)
):
if not self.my_companies.remove_factory_from_wam_list(raw_factories, fin_factories):
raise classes.ErepublikException("Nothing removed from WAM list!")
if fin_factories + raw_factories: if wam_list:
data.update(extra) data.update(extra)
if not self.details.current_region == wam_holding.region: if not self.details.current_region == wam_holding.region:
self.write_warning("Unable to work as manager because of location - please travel!") self.write_warning("Unable to work as manager because of location - please travel!")
@ -1203,7 +1199,7 @@ class CitizenCompanies(BaseCitizen):
employ_factories = {} employ_factories = {}
response = self._post_economy_work( response = self._post_economy_work(
"production", wam=[c.id for c in (fin_factories + raw_factories)], employ=employ_factories "production", wam=[c.id for c in wam_list], employ=employ_factories
).json() ).json()
return response return response
@ -1961,7 +1957,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 +2003,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 +2277,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 +2336,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,41 +2344,46 @@ 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] = [ # Prevent messing up levelup with wam
holding for holding in self.my_companies.get_wam_holdings() if holding.wam_count if not (self.is_levelup_close and self.config.fight) or self.config.force_wam:
] regions: Dict[int, classes.Holding] = {}
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.update_companies()
for holding in regions.values():
raw_usage = holding.get_wam_raw_usage()
free_storage = self.inventory.total - self.inventory.used
if (raw_usage["frm"] + raw_usage["wrm"]) * 100 > free_storage:
self._report_action("WAM_UNAVAILABLE", "Not enough storage!")
continue
self.travel_to_holding(holding)
self._wam(holding) 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: wam_count = self.my_companies.get_total_wam_count()
# Don't travel if not enough energy (either work in all holding factories or 2h energy worth) if wam_count:
if self.energy.energy < 2 * self.energy.interval * 10 < holding.wam_count * 10: self.logger.debug(f"Wam ff lockdown is now {wam_count}, was {self.my_companies.ff_lockdown}")
break self.my_companies.ff_lockdown = wam_count
raw_usage = holding.get_wam_raw_usage() self.travel_to_residence()
free_storage = self.inventory.total - self.inventory.used return bool(wam_count)
if (raw_usage["frm"] + raw_usage["wrm"]) * 100 > free_storage: else:
self._report_action("WAM_UNAVAILABLE", "Not enough storage!") self.write_warning("Did not WAM because I would mess up levelup!")
continue self.my_companies.ff_lockdown = 0
self.travel_to_holding(holding)
self._wam(holding)
self.update_companies()
wam_count = self.my_companies.get_total_wam_count() self.update_companies()
self.travel_to_residence() return bool(self.my_companies.get_total_wam_count())
return bool(wam_count)
class Citizen(_Citizen): class Citizen(_Citizen):
_concurrency_lock: Event _concurrency_lock: Event
_update_lock: Event _update_lock: Event
_update_timeout: int = 30 _update_timeout: int = 10
_concurrency_timeout: int = 600 _concurrency_timeout: int = 600
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):

View File

@ -22,8 +22,6 @@ __all__ = [
"Energy", "Energy",
"ErepublikException", "ErepublikException",
"ErepublikNetworkException", "ErepublikNetworkException",
"CloudFlareSessionError",
"CaptchaSessionError",
"EnergyToFight", "EnergyToFight",
"Holding", "Holding",
"Inventory", "Inventory",
@ -298,10 +296,6 @@ class MyCompanies:
_companies: weakref.WeakSet _companies: weakref.WeakSet
_citizen: weakref.ReferenceType _citizen: weakref.ReferenceType
companies: Generator[Company, None, None] companies: Generator[Company, None, None]
_frm_fab_ids = (1, 7, 8, 9, 10, 11)
_wrm_fab_ids = (2, 12, 13, 14, 15, 16)
_hrm_fab_ids = (4, 18, 19, 20, 21, 22)
_arm_fab_ids = (23, 24, 25, 26, 27, 28)
def __init__(self, citizen): def __init__(self, citizen):
self._citizen = weakref.ref(citizen) self._citizen = weakref.ref(citizen)
@ -365,58 +359,14 @@ class MyCompanies:
@staticmethod @staticmethod
def get_needed_inventory_usage(companies: Union[Company, Iterable[Company]]) -> Decimal: def get_needed_inventory_usage(companies: Union[Company, Iterable[Company]]) -> Decimal:
if isinstance(companies, list): if isinstance(companies, list):
return sum(company.products_made * (100 if company.is_raw else 1) for company in companies) return sum(company.products_made * 100 if company.is_raw else 1 for company in companies)
else: else:
return companies.products_made return companies.products_made
def remove_factory_from_wam_list(self, raw_factories, final_factories):
frm, wrm, *_ = self.get_raw_usage_for_companies(*final_factories, *raw_factories)
inv_raw = self.citizen.inventory.raw
for raw, ids, exc in [(frm, self._frm_fab_ids, False), (wrm, self._wrm_fab_ids, False), (None, None, True)]:
if exc:
if final_factories:
final_factories.sort(key=lambda c: c.raw_usage)
return final_factories.pop(-1)
elif raw_factories:
raw_factories.sort(key=lambda c: c.raw_usage)
return raw_factories.pop(-1)
else:
if raw:
raw += Decimal(
inv_raw.get(constants.INDUSTRIES[ids[1]], {}).get(0, {}).get("amount", Decimal("0.0"))
)
if raw > 0:
to_remove = sorted(raw_factories, key=lambda c: (c.industry not in ids, c.raw_usage))
if to_remove:
return raw_factories.pop(raw_factories.index(to_remove[0]))
else:
to_remove = sorted(final_factories, key=lambda c: (c.industry != ids[0], c.raw_usage))
if to_remove:
return final_factories.pop(final_factories.index(to_remove[0]))
def get_raw_usage_for_companies(self, *companies: Company) -> Tuple[Decimal, Decimal, Decimal, Decimal]:
frm = wrm = hrm = arm = Decimal("0.00")
for company in companies:
if company.industry in self._frm_fab_ids:
frm += company.raw_usage
elif company.industry in self._wrm_fab_ids:
wrm += company.raw_usage
elif company.industry in self._hrm_fab_ids:
hrm += company.raw_usage
elif company.industry in self._arm_fab_ids:
arm += company.raw_usage
return frm, wrm, hrm, arm
@property @property
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"
@ -466,13 +416,6 @@ class Config:
auto_sell: List[str] = None auto_sell: List[str] = None
auto_sell_all = False auto_sell_all = False
employees = False employees = False
interactive = True
auto_buy_raw = False
force_wam = False
telegram = True
telegram_chat_id = 0
telegram_token = ""
spin_wheel_of_fortune = False
# fight = False # fight = False
# air = False # air = False
# ground = False # ground = False
@ -484,10 +427,17 @@ class Config:
# epic_hunt = False # epic_hunt = False
# epic_hunt_ebs = False # epic_hunt_ebs = False
# rw_def_side = False # rw_def_side = False
# interactive = True
# continuous_fighting = False # continuous_fighting = False
auto_buy_raw = False
force_wam = False
# sort_battles_time = True # sort_battles_time = True
# force_travel = False # force_travel = False
telegram = True
telegram_chat_id = 0
telegram_token = ""
# maverick = False # maverick = False
spin_wheel_of_fortune = False
def __init__(self): def __init__(self):
self.auto_sell = [] self.auto_sell = []
@ -500,13 +450,6 @@ class Config:
self.auto_sell = list() self.auto_sell = list()
self.auto_sell_all = False self.auto_sell_all = False
self.employees = False self.employees = False
self.interactive = True
self.auto_buy_raw = False
self.force_wam = False
self.telegram = True
self.telegram_chat_id = 0
self.telegram_token = ""
self.spin_wheel_of_fortune = False
# self.fight = False # self.fight = False
# self.air = False # self.air = False
# self.ground = False # self.ground = False
@ -518,10 +461,17 @@ class Config:
# self.epic_hunt = False # self.epic_hunt = False
# self.epic_hunt_ebs = False # self.epic_hunt_ebs = False
# self.rw_def_side = False # self.rw_def_side = False
# self.interactive = True
# self.continuous_fighting = False # self.continuous_fighting = False
self.auto_buy_raw = False
self.force_wam = False
# self.sort_battles_time = True # self.sort_battles_time = True
# self.force_travel = False # self.force_travel = False
self.telegram = True
self.telegram_chat_id = 0
self.telegram_token = ""
# self.maverick = False # self.maverick = False
self.spin_wheel_of_fortune = False
@property @property
def as_dict(self) -> Dict[str, Union[bool, int, str, List[str]]]: def as_dict(self) -> Dict[str, Union[bool, int, str, List[str]]]:
@ -534,13 +484,6 @@ class Config:
auto_sell=self.auto_sell, auto_sell=self.auto_sell,
auto_sell_all=self.auto_sell_all, auto_sell_all=self.auto_sell_all,
employees=self.employees, employees=self.employees,
interactive=self.interactive,
auto_buy_raw=self.auto_buy_raw,
force_wam=self.force_wam,
telegram=self.telegram,
telegram_chat_id=self.telegram_chat_id,
telegram_token=self.telegram_token,
spin_wheel_of_fortune=self.spin_wheel_of_fortune,
# fight=self.fight, # fight=self.fight,
# air=self.air, # air=self.air,
# ground=self.ground, # ground=self.ground,
@ -551,10 +494,17 @@ class Config:
# epic_hunt=self.epic_hunt, # epic_hunt=self.epic_hunt,
# epic_hunt_ebs=self.epic_hunt_ebs, # epic_hunt_ebs=self.epic_hunt_ebs,
# rw_def_side=self.rw_def_side, # rw_def_side=self.rw_def_side,
# interactive=self.interactive,
# maverick=self.maverick, # maverick=self.maverick,
# continuous_fighting=self.continuous_fighting, # continuous_fighting=self.continuous_fighting,
auto_buy_raw=self.auto_buy_raw,
force_wam=self.force_wam,
# sort_battles_time=self.sort_battles_time, # sort_battles_time=self.sort_battles_time,
# force_travel=self.force_travel, # force_travel=self.force_travel,
telegram=self.telegram,
telegram_chat_id=self.telegram_chat_id,
telegram_token=self.telegram_token,
spin_wheel_of_fortune=self.spin_wheel_of_fortune,
) )
@ -774,14 +724,20 @@ class Reporter:
self._citizen = weakref.ref(citizen) self._citizen = weakref.ref(citizen)
self._req = Session() self._req = Session()
self.url = "https://erep.lv" self.url = "https://erep.lv"
self._req.headers.update({"user-agent": "eRepublik Script Reporter v3", "erep-version": utils.__version__}) self._req.headers.update(
{
"user-agent": "eRepublik Script Reporter v3",
"erep-version": utils.__version__,
"erep-user-id": str(self.citizen_id),
"erep-user-name": self.citizen.name,
}
)
self.__to_update = [] self.__to_update = []
self.__registered: bool = False self.__registered: bool = False
def do_init(self): def do_init(self):
self.key: str = "" self.key: str = ""
self.__update_key() self.__update_key()
self._req.headers.update({"erep-user-id": str(self.citizen_id), "erep-user-name": self.name})
self.register_account() self.register_account()
self.allowed = True self.allowed = True

View File

@ -8,15 +8,12 @@ __all__ = [
"min_datetime", "min_datetime",
"max_datetime", "max_datetime",
"Country", "Country",
"Industries",
"Rank", "Rank",
"AIR_RANKS", "AIR_RANKS",
"AIR_RANK_NAMES",
"AIR_RANK_POINTS", "AIR_RANK_POINTS",
"COUNTRIES", "COUNTRIES",
"FOOD_ENERGY", "FOOD_ENERGY",
"GROUND_RANKS", "GROUND_RANKS",
"GROUND_RANK_NAMES",
"GROUND_RANK_POINTS", "GROUND_RANK_POINTS",
"INDUSTRIES", "INDUSTRIES",
"TERRAINS", "TERRAINS",
@ -121,6 +118,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",
@ -133,7 +131,7 @@ class Industries:
28: "ARM q5", 28: "ARM q5",
} }
def __getitem__(self, item: Union[int, str]) -> Optional[Union[int, str]]: def __getitem__(self, item) -> Optional[Union[int, str]]:
if isinstance(item, int): if isinstance(item, int):
return self.__by_id.get(item, None) return self.__by_id.get(item, None)
elif isinstance(item, str): elif isinstance(item, str):

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.1.1
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>=7.29.0
jedi!=0.18.0 jedi!=0.18.0
isort==5.10.1 isort==5.9.3
pre-commit==2.17.0 pre-commit==2.15.0
pur==6.0.1 pur==5.4.2
responses==0.18.0 responses==0.15.0
Sphinx==4.4.0 Sphinx==4.2.0
twine==3.8.0 twine==3.4.2
wheel==0.37.1 wheel==0.37.0
black==22.1.0 black==21.7b0

View File

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

View File

@ -1,4 +1,4 @@
PySocks==1.7.1 PySocks==1.7.1
pytz>2021.0 pytz==2021.3
requests>2.25.0,!=2.27.0 requests==2.26.0
requests-toolbelt==0.9.1 requests-toolbelt==0.9.1

View File

@ -1,5 +1,5 @@
[bumpversion] [bumpversion]
current_version = 0.29.2.3 current_version = 0.28.0.1
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.28.0.1",
zip_safe=False, zip_safe=False,
) )

View File

@ -26,114 +26,111 @@ class TestErepublik(unittest.TestCase):
self.citizen.energy.energy = 1000 self.citizen.energy.energy = 1000
self.assertFalse(self.citizen.should_do_levelup) self.assertFalse(self.citizen.should_do_levelup)
# def deprecated_test_should_travel_to_fight(self): def test_should_travel_to_fight(self):
# self.citizen.config.always_travel = True self.citizen.config.always_travel = True
# self.assertTrue(self.citizen.should_travel_to_fight()) self.assertTrue(self.citizen.should_travel_to_fight())
# self.citizen.config.always_travel = False self.citizen.config.always_travel = False
# self.assertFalse(self.citizen.should_travel_to_fight()) self.assertFalse(self.citizen.should_travel_to_fight())
#
# self.citizen.energy.energy = 5960 self.citizen.energy.energy = 5960
# self.citizen.energy.interval = 30 self.citizen.energy.interval = 30
# self.citizen.energy.limit = 6000 self.citizen.energy.limit = 6000
# self.citizen.details.xp = 14850 self.citizen.details.xp = 14850
# self.assertTrue(self.citizen.should_travel_to_fight()) self.assertTrue(self.citizen.should_travel_to_fight())
# self.citizen.details.xp = 15000 self.citizen.details.xp = 15000
# self.citizen.energy.energy = 5000 self.citizen.energy.energy = 5000
# self.assertFalse(self.citizen.should_travel_to_fight()) self.assertFalse(self.citizen.should_travel_to_fight())
#
# self.citizen.energy.energy = 5910 self.citizen.energy.energy = 5910
# self.assertTrue(self.citizen.should_travel_to_fight()) self.assertTrue(self.citizen.should_travel_to_fight())
# self.citizen.energy.energy = 5900 self.citizen.energy.energy = 5900
# self.assertFalse(self.citizen.should_travel_to_fight()) self.assertFalse(self.citizen.should_travel_to_fight())
#
# # self.citizen.next_reachable_energy and self.citizen.config.next_energy # self.citizen.next_reachable_energy and self.citizen.config.next_energy
# self.citizen.config.next_energy = True self.citizen.config.next_energy = True
# self.citizen.energy.limit = 10000 self.citizen.energy.limit = 10000
# self.citizen.details.next_pp = [5000, 5250, 5750, 6250, 6750] self.citizen.details.next_pp = [5000, 5250, 5750, 6250, 6750]
# self.citizen.details.pp = 4900 self.citizen.details.pp = 4900
# self.citizen.energy.energy = 8510 self.citizen.energy.energy = 8510
# self.assertEqual(self.citizen.next_reachable_energy, 850) self.assertEqual(self.citizen.next_reachable_energy, 850)
# self.citizen.energy.energy = 8490 self.citizen.energy.energy = 8490
# self.assertTrue(self.citizen.should_travel_to_fight()) self.assertTrue(self.citizen.should_travel_to_fight())
# self.assertEqual(self.citizen.next_reachable_energy, 350) self.assertEqual(self.citizen.next_reachable_energy, 350)
# self.citizen.energy.energy = 250 self.citizen.energy.energy = 250
# self.assertFalse(self.citizen.should_travel_to_fight()) self.assertFalse(self.citizen.should_travel_to_fight())
# self.assertEqual(self.citizen.next_reachable_energy, 0) self.assertEqual(self.citizen.next_reachable_energy, 0)
#
# def deprecated_test_should_fight(self): def test_should_fight(self):
# def is_wc_close(): def is_wc_close():
# return self.citizen.max_time_till_full_ff > self.citizen.time_till_week_change return self.citizen.max_time_till_full_ff > self.citizen.time_till_week_change
#
# self.citizen.config.fight = False self.citizen.config.fight = False
# self.assertEqual(self.citizen.should_fight(), (0, "Fighting not allowed!", False)) self.assertEqual(self.citizen.should_fight(), (0, "Fighting not allowed!", False))
#
# self.citizen.config.fight = True self.citizen.config.fight = True
#
# # Level up # Level up
# self.citizen.energy.limit = 3000 self.citizen.energy.limit = 3000
# self.citizen.details.xp = 24705 self.citizen.details.xp = 24705
# if not is_wc_close: if not is_wc_close:
# self.assertEqual(self.citizen.should_fight(), (0, "Level up", False)) self.assertEqual(self.citizen.should_fight(), (0, "Level up", False))
#
# self.citizen.energy.energy = 5950 self.citizen.energy.energy = 5950
# self.citizen.energy.interval = 30 self.citizen.energy.interval = 30
# self.assertEqual(self.citizen.should_fight(), (900, "Level up", True)) self.assertEqual(self.citizen.should_fight(), (900, "Level up", True))
# self.citizen.my_companies.ff_lockdown = 160 self.citizen.my_companies.ff_lockdown = 160
# self.assertEqual(self.citizen.should_fight(), (900, "Level up", True)) self.assertEqual(self.citizen.should_fight(), (900, "Level up", True))
# self.citizen.my_companies.ff_lockdown = 0 self.citizen.my_companies.ff_lockdown = 0
#
# # Level up reachable # Level up reachable
# self.citizen.details.xp = 24400 self.citizen.details.xp = 24400
# self.assertEqual(self.citizen.should_fight(), (305, "Fighting for close Levelup. Doing 305 hits", True)) self.assertEqual(self.citizen.should_fight(), (305, "Fighting for close Levelup. Doing 305 hits", True))
# self.citizen.my_companies.ff_lockdown = 160 self.citizen.my_companies.ff_lockdown = 160
# self.assertEqual(self.citizen.should_fight(), (305, "Fighting for close Levelup. Doing 305 hits", True)) self.assertEqual(self.citizen.should_fight(), (305, "Fighting for close Levelup. Doing 305 hits", True))
# self.citizen.my_companies.ff_lockdown = 0 self.citizen.my_companies.ff_lockdown = 0
#
# self.citizen.details.xp = 21000 self.citizen.details.xp = 21000
# self.assertEqual(self.citizen.should_fight(), (75, "Obligatory fighting for at least 75pp", True)) self.assertEqual(self.citizen.should_fight(), (75, "Obligatory fighting for at least 75pp", True))
# self.citizen.my_companies.ff_lockdown = 160 self.citizen.my_companies.ff_lockdown = 160
# self.assertEqual(self.citizen.should_fight(), (75, "Obligatory fighting for at least 75pp", True)) self.assertEqual(self.citizen.should_fight(), (75, "Obligatory fighting for at least 75pp", True))
# self.citizen.my_companies.ff_lockdown = 0 self.citizen.my_companies.ff_lockdown = 0
# self.citizen.details.pp = 80 self.citizen.details.pp = 80
#
# # All-in (type = all-in and full ff) # All-in (type = all-in and full ff)
# self.citizen.config.all_in = True self.citizen.config.all_in = True
# self.assertEqual(self.citizen.should_fight(), (595, "Fighting all-in. Doing 595 hits", False)) self.assertEqual(self.citizen.should_fight(), (595, "Fighting all-in. Doing 595 hits", False))
# self.citizen.my_companies.ff_lockdown = 160 self.citizen.my_companies.ff_lockdown = 160
# self.assertEqual( self.assertEqual(
# self.citizen.should_fight(), self.citizen.should_fight(),
# (435, "Fight count modified (old count: 595 | FF: 595 (435, "Fight count modified (old count: 595 | FF: 595 | WAM ff_lockdown: 160 | New count: 435)", False),
# | WAM ff_lockdown: 160 | New count: 435)", False), )
# ) self.citizen.my_companies.ff_lockdown = 0
# self.citizen.my_companies.ff_lockdown = 0
# self.citizen.config.air = True
# self.citizen.config.air = True self.citizen.energy.energy = 4000
# self.citizen.energy.energy = 4000 self.assertEqual(self.citizen.should_fight(), (400, "Fighting all-in in AIR. Doing 400 hits", False))
# self.assertEqual(self.citizen.should_fight(), (400, "Fighting all-in in AIR. Doing 400 hits", False)) self.citizen.my_companies.ff_lockdown = 160
# self.citizen.my_companies.ff_lockdown = 160 self.assertEqual(
# self.assertEqual( self.citizen.should_fight(),
# self.citizen.should_fight(), (240, "Fight count modified (old count: 400 | FF: 400 | WAM ff_lockdown: 160 | New count: 240)", False),
# (240, "Fight count modified (old count: 400 | FF: 400 )
# | WAM ff_lockdown: 160 | New count: 240)", False), self.citizen.my_companies.ff_lockdown = 0
# ) self.citizen.config.all_in = False
# self.citizen.my_companies.ff_lockdown = 0
# self.citizen.config.all_in = False self.citizen.config.next_energy = True
# self.citizen.energy.limit = 10000
# self.citizen.config.next_energy = True self.citizen.details.next_pp = [100, 150, 250, 400, 500]
# self.citizen.energy.limit = 10000 self.assertEqual(self.citizen.should_fight(), (320, "Fighting for +1 energy. Doing 320 hits", False))
# self.citizen.details.next_pp = [100, 150, 250, 400, 500] self.citizen.my_companies.ff_lockdown = 160
# self.assertEqual(self.citizen.should_fight(), (320, "Fighting for +1 energy. Doing 320 hits", False)) self.assertEqual(
# self.citizen.my_companies.ff_lockdown = 160 self.citizen.should_fight(),
# self.assertEqual( (160, "Fight count modified (old count: 320 | FF: 400 | WAM ff_lockdown: 160 | New count: 160)", False),
# self.citizen.should_fight(), )
# (160, "Fight count modified (old count: 320 | FF: 400 self.citizen.my_companies.ff_lockdown = 0
# | WAM ff_lockdown: 160 | New count: 160)", False), self.citizen.energy.limit = 3000
# ) self.citizen.details.next_pp = [19250, 20000]
# self.citizen.my_companies.ff_lockdown = 0 self.citizen.config.next_energy = False
# self.citizen.energy.limit = 3000
# self.citizen.details.next_pp = [19250, 20000] # 1h worth of energy
# self.citizen.config.next_energy = False self.citizen.energy.energy = 5910
# self.assertEqual(self.citizen.should_fight(), (30, "Fighting for 1h energy. Doing 30 hits", True))
# # 1h worth of energy
# self.citizen.energy.energy = 5910
# self.assertEqual(self.citizen.should_fight(), (30, "Fighting for 1h energy. Doing 30 hits", True))