From 8b9ee5042df784da999d706d8606e8355b23be92 Mon Sep 17 00:00:00 2001 From: Eriks K Date: Tue, 5 Jan 2021 15:41:51 +0200 Subject: [PATCH] Bugfixes and inventory redone --- HISTORY.rst | 9 ++- erepublik/citizen.py | 187 +++++++++++++++++++++++++++---------------- erepublik/classes.py | 43 +++++++--- erepublik/types.py | 7 ++ erepublik/utils.py | 10 ++- requirements_dev.txt | 14 ++-- setup.py | 2 +- 7 files changed, 182 insertions(+), 90 deletions(-) create mode 100644 erepublik/types.py diff --git a/HISTORY.rst b/HISTORY.rst index d7359e6..bd286b3 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -2,6 +2,13 @@ History ======= +0.23.4 (2021-01-05) +------------------- +* Added expiration data to inventory items +* Inventory is now based on `classes.Inventory` +* Requirement update to make them more flexible regarding versions required +* Restructured inventory + 0.23.3 (2020-12-17) ------------------- * Fixed carpet bombing @@ -29,7 +36,7 @@ History 0.23.0 (2020-11-26) ------------------- -* ***0.23 - last supported version for Python 3.7.*** +* ***0.23 - last officially supported version for Python 3.7.*** * Added `Config.maverick` switch, to allow/deny automated fighting in non native divisions if the player has MaverickPack * Added `CitizenMedia.get_article(article_id:int)` method to get article data * Added `CitizenMedia.delete_article(article_id:int)` method to delete article diff --git a/erepublik/citizen.py b/erepublik/citizen.py index a95e380..f762f51 100644 --- a/erepublik/citizen.py +++ b/erepublik/citizen.py @@ -2,7 +2,7 @@ import re import sys import warnings import weakref -from datetime import datetime, timedelta +from datetime import datetime, timedelta, time from decimal import Decimal from itertools import product from threading import Event @@ -11,7 +11,7 @@ from typing import Any, Dict, List, NoReturn, Optional, Set, Tuple, Union from requests import HTTPError, RequestException, Response -from . import access_points, classes, constants, utils +from . import access_points, classes, constants, utils, types from .classes import OfferItem @@ -20,9 +20,7 @@ class BaseCitizen(access_points.CitizenAPI): _last_inventory_update: datetime = constants.min_datetime promos: Dict[str, datetime] = None - inventory: Dict[str, Dict[str, Dict[int, Dict[str, Union[str, int, float]]]]] - inventory_status: Dict[str, int] - boosters: Dict[int, Dict[int, int]] = {50: {}, 100: {}} + inventory: classes.Inventory ot_points: int = 0 food: Dict[str, int] = {"q1": 0, "q2": 0, "q3": 0, "q4": 0, "q5": 0, "q6": 0, "q7": 0, "total": 0} @@ -65,8 +63,7 @@ class BaseCitizen(access_points.CitizenAPI): self.config.email = email self.config.password = password - self.inventory = {} - self.inventory_status = dict(used=0, total=0) + self.inventory = classes.Inventory() self.wheel_of_fortune = False def get_csrf_token(self): @@ -248,7 +245,7 @@ class BaseCitizen(access_points.CitizenAPI): """ self._update_inventory_data(self._get_economy_inventory_items().json()) - def get_inventory(self, force: bool = False): + def get_inventory(self, force: bool = False) -> classes.Inventory: if utils.good_timedelta(self._last_inventory_update, timedelta(minutes=2)) < self.now or force: self.update_inventory() return self.inventory @@ -257,17 +254,25 @@ class BaseCitizen(access_points.CitizenAPI): if not isinstance(inv_data, dict): raise TypeError("Parameter `inv_data` must be dict not '{type(data)}'!") + def _expire_value_to_python(_expire_value: str) -> Dict[str, Union[int, datetime]]: + _data = re.search( + r'((?P\d+) item\(s\) )?[eE]xpires? on Day (?P\d,\d{3}), (?P