Compare commits
48 Commits
Author | SHA1 | Date | |
---|---|---|---|
e798859105 | |||
241f1642ce | |||
a4128b5d89 | |||
22c2a0ffd2 | |||
38f0335354 | |||
889435b94e | |||
bb16c27674 | |||
963d7ca11a | |||
36c7fefdf7 | |||
d9fa30b06e | |||
b53dc447f4 | |||
233d8d83f8 | |||
ec62d90aa2 | |||
0c433a56da | |||
ad24338f4d | |||
6f4bc65d1b | |||
cc09ba7ee7 | |||
9e1166a460 | |||
fb0042c00d | |||
bb800578e7 | |||
7025f750dc | |||
bf77f21b60 | |||
6b7639d7fb | |||
3b1c1928fd | |||
2e26c2db79 | |||
78c055fee2 | |||
fe41c4cdc6 | |||
123b6cf4ed | |||
f652b02443 | |||
73537e4742 | |||
955432e0d2 | |||
1d93864dca | |||
c472d688be | |||
bff9a2bec9 | |||
973ea40e00 | |||
52c85fdf28 | |||
a889e9efa1 | |||
a9a0cdc6d5 | |||
1c102488b6 | |||
c38acef2a0 | |||
48b5e473aa | |||
7fadeb1a49 | |||
b723660f23 | |||
f10eeec498 | |||
230167f93d | |||
d5ed989e80 | |||
6fc24b8adf | |||
cf797f2f60 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -104,3 +104,4 @@ ENV/
|
||||
debug/
|
||||
log/
|
||||
docs/
|
||||
*dump.json
|
||||
|
@ -2,6 +2,15 @@
|
||||
History
|
||||
=======
|
||||
|
||||
0.22.0 (2020-10-22)
|
||||
-------------------
|
||||
* Ability to dump session and restore from file
|
||||
* Proxy support
|
||||
* Inventory updates
|
||||
* Remove market offers
|
||||
* Memory and network optimizations
|
||||
* Python 3.6 supported
|
||||
|
||||
0.20.0 (2020-06-15)
|
||||
-------------------
|
||||
* Massive restructuring
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
__author__ = """Eriks Karls"""
|
||||
__email__ = 'eriks@72.lv'
|
||||
__version__ = '0.21.2.2'
|
||||
__version__ = '0.22.1'
|
||||
|
||||
from erepublik import classes, utils, constants
|
||||
from erepublik.citizen import Citizen
|
||||
|
@ -12,32 +12,36 @@ __all__ = ['SlowRequests', 'CitizenAPI']
|
||||
|
||||
class SlowRequests(Session):
|
||||
last_time: datetime.datetime
|
||||
timeout = datetime.timedelta(milliseconds=500)
|
||||
uas = [
|
||||
timeout: datetime.timedelta = datetime.timedelta(milliseconds=500)
|
||||
uas: List[str] = [
|
||||
# Chrome
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36', # noqa
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36', # noqa
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.106 Safari/537.36', # noqa
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36', # noqa
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36', # noqa
|
||||
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36',
|
||||
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36',
|
||||
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.106 Safari/537.36',
|
||||
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36',
|
||||
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36',
|
||||
|
||||
# FireFox
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0',
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:75.0) Gecko/20100101 Firefox/75.0',
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:74.0) Gecko/20100101 Firefox/74.0',
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:73.0) Gecko/20100101 Firefox/73.0',
|
||||
'Mozilla/5.0 (X11; Linux x86_64; rv:76.0) Gecko/20100101 Firefox/76.0',
|
||||
'Mozilla/5.0 (X11; Linux x86_64; rv:75.0) Gecko/20100101 Firefox/75.0',
|
||||
'Mozilla/5.0 (X11; Linux x86_64; rv:74.0) Gecko/20100101 Firefox/74.0',
|
||||
'Mozilla/5.0 (X11; Linux x86_64; rv:73.0) Gecko/20100101 Firefox/73.0',
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.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: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 = False
|
||||
debug: bool = False
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, proxies: Dict[str, str] = None):
|
||||
super().__init__()
|
||||
if proxies:
|
||||
self.proxies = proxies
|
||||
self.request_log_name = utils.get_file(utils.now().strftime("debug/requests_%Y-%m-%d.log"))
|
||||
self.last_time = utils.now()
|
||||
self.headers.update({
|
||||
@ -113,12 +117,13 @@ class SlowRequests(Session):
|
||||
|
||||
class CitizenBaseAPI:
|
||||
url: str = "https://www.erepublik.com/en"
|
||||
_req: SlowRequests = None
|
||||
token: str = ""
|
||||
_req: SlowRequests
|
||||
token: str
|
||||
|
||||
def __init__(self):
|
||||
""" Class for unifying eRepublik known endpoints and their required/optional parameters """
|
||||
self._req = SlowRequests()
|
||||
self.token = ""
|
||||
|
||||
def post(self, url: str, data=None, json=None, **kwargs) -> Response:
|
||||
return self._req.post(url, data, json, **kwargs)
|
||||
@ -129,6 +134,14 @@ class CitizenBaseAPI:
|
||||
def _get_main(self) -> Response:
|
||||
return self.get(self.url)
|
||||
|
||||
def set_socks_proxy(self, host: str, port: int, username: str = None, password: str = None):
|
||||
url = f'socks5://{username}:{password}@{host}:{port}' if username and password else f'socks5://{host}:{port}'
|
||||
self._req.proxies = dict(http=url, https=url)
|
||||
|
||||
def set_http_proxy(self, host: str, port: int, username: str = None, password: str = None):
|
||||
url = f'http://{username}:{password}@{host}:{port}' if username and password else f'socks5://{host}:{port}'
|
||||
self._req.proxies = dict(http=url)
|
||||
|
||||
|
||||
class ErepublikAnniversaryAPI(CitizenBaseAPI):
|
||||
def _post_main_collect_anniversary_reward(self) -> Response:
|
||||
@ -151,10 +164,10 @@ class ErepublikAnniversaryAPI(CitizenBaseAPI):
|
||||
return self.post(f"{self.url}/main/map-rewards-claim", data=data)
|
||||
|
||||
def _post_main_wheel_of_fortune_spin(self, cost) -> Response:
|
||||
return self.post(f"{self.url}/wheeloffortune-spin", data={'_token': self.token, "cost": cost})
|
||||
return self.post(f"{self.url}/main/wheeloffortune-spin", data={'_token': self.token, "_currentCost": cost})
|
||||
|
||||
def _post_main_wheel_of_fortune_build(self) -> Response:
|
||||
return self.post(f"{self.url}/wheeloffortune-build", data={'_token': self.token})
|
||||
return self.post(f"{self.url}/main/wheeloffortune-build", data={'_token': self.token})
|
||||
|
||||
|
||||
class ErepublikArticleAPI(CitizenBaseAPI):
|
||||
@ -331,13 +344,17 @@ class ErepublikEconomyAPI(CitizenBaseAPI):
|
||||
orderBy="price_asc" if order_asc else "price_desc", _token=self.token)
|
||||
return self.post(f"{self.url}/economy/marketplaceAjax", data=data)
|
||||
|
||||
def _post_economy_marketplace_actions(self, amount: int, buy: bool = False, **kwargs) -> Response:
|
||||
if buy:
|
||||
data = dict(_token=self.token, offerId=kwargs['offer'], amount=amount, orderBy="price_asc", currentPage=1,
|
||||
def _post_economy_marketplace_actions(self, action: str, **kwargs) -> Response:
|
||||
if action == 'buy':
|
||||
data = dict(_token=self.token, offerId=kwargs['offer'], amount=kwargs['amount'], orderBy="price_asc", currentPage=1,
|
||||
buyAction=1)
|
||||
else:
|
||||
elif action == 'sell':
|
||||
data = dict(_token=self.token, countryId=kwargs["country_id"], price=kwargs["price"],
|
||||
industryId=kwargs["industry"], quality=kwargs["quality"], amount=amount, sellAction='postOffer')
|
||||
industryId=kwargs["industry"], quality=kwargs["quality"], amount=kwargs['amount'], sellAction='postOffer')
|
||||
elif action == 'delete':
|
||||
data = dict(_token=self.token, offerId=kwargs["offer_id"], sellAction='deleteOffer')
|
||||
else:
|
||||
raise ValueError(f"Action '{action}' is not supported! Only 'buy/sell/delete' actions are available")
|
||||
return self.post(f"{self.url}/economy/marketplaceActions", data=data)
|
||||
|
||||
|
||||
|
@ -1,12 +1,13 @@
|
||||
import re
|
||||
import sys
|
||||
import warnings
|
||||
import weakref
|
||||
from datetime import datetime, timedelta
|
||||
from decimal import Decimal
|
||||
from itertools import product
|
||||
from threading import Event
|
||||
from time import sleep
|
||||
from typing import Any, Callable, Dict, List, NoReturn, Optional, Set, Tuple, Union
|
||||
from typing import Any, Dict, List, NoReturn, Optional, Set, Tuple, Union
|
||||
|
||||
from requests import HTTPError, RequestException, Response
|
||||
|
||||
@ -14,10 +15,12 @@ from . import utils, classes, access_points, constants
|
||||
|
||||
|
||||
class BaseCitizen(access_points.CitizenAPI):
|
||||
_last_full_update: datetime = utils.now().min
|
||||
_last_full_update: datetime = constants.min_datetime
|
||||
_last_inventory_update: datetime = constants.min_datetime
|
||||
|
||||
promos: Dict[str, datetime] = None
|
||||
inventory: Dict[str, int] = {'used': 0, 'total': 0}
|
||||
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: {}}
|
||||
ot_points: int = 0
|
||||
|
||||
@ -56,6 +59,8 @@ class BaseCitizen(access_points.CitizenAPI):
|
||||
|
||||
self.config.email = email
|
||||
self.config.password = password
|
||||
self.inventory = {}
|
||||
self.inventory_status = dict(used=0, total=0)
|
||||
|
||||
def get_csrf_token(self):
|
||||
"""
|
||||
@ -224,153 +229,165 @@ class BaseCitizen(access_points.CitizenAPI):
|
||||
self.politics.is_party_president = bool(party.get('is_party_president'))
|
||||
self.politics.party_slug = f"{party.get('stripped_title')}-{party.get('party_id')}"
|
||||
|
||||
def update_inventory(self) -> Dict[str, Any]:
|
||||
def update_inventory(self):
|
||||
"""
|
||||
Updates class properties and returns structured inventory.
|
||||
Return structure: {status: {used: int, total: int}, items: {active/final/raw: {item_token:{quality: data}}}
|
||||
If item kind is damageBoosters or aircraftDamageBoosters then kind is renamed to kind+quality and duration is
|
||||
used as quality.
|
||||
:return: dict
|
||||
"""
|
||||
self._update_inventory_data(self._get_economy_inventory_items().json())
|
||||
|
||||
def get_inventory(self, force: bool = False):
|
||||
if utils.good_timedelta(self._last_inventory_update, timedelta(minutes=2)) < self.now or force:
|
||||
self.update_inventory()
|
||||
return self.inventory
|
||||
|
||||
def _update_inventory_data(self, inv_data: Dict[str, Any]):
|
||||
if not isinstance(inv_data, dict):
|
||||
raise TypeError("Parameter `inv_data` must be dict not '{type(data)}'!")
|
||||
|
||||
status = inv_data.get("inventoryStatus", {})
|
||||
if status:
|
||||
self.inventory_status.clear()
|
||||
self.inventory_status.update(used=status.get("usedStorage"), total=status.get("totalStorage"))
|
||||
data = inv_data.get('inventoryItems', {})
|
||||
if not data:
|
||||
return
|
||||
self._last_inventory_update = self.now
|
||||
self.food.update({"q1": 0, "q2": 0, "q3": 0, "q4": 0, "q5": 0, "q6": 0, "q7": 0})
|
||||
self.eb_small = self.eb_double = self.eb_normal = 0
|
||||
|
||||
j = self._get_economy_inventory_items().json()
|
||||
active_items = {}
|
||||
if j.get("inventoryItems", {}).get("activeEnhancements", {}).get("items", {}):
|
||||
for item in j.get("inventoryItems", {}).get("activeEnhancements", {}).get("items", {}).values():
|
||||
if item.get('token'):
|
||||
kind = re.sub(r'_q\d\d*', "", item.get('token'))
|
||||
active_items: Dict[str, Dict[int, Dict[str, Union[str, int]]]] = {}
|
||||
if data.get("activeEnhancements", {}).get("items", {}):
|
||||
for item_data in data.get("activeEnhancements", {}).get("items", {}).values():
|
||||
if item_data.get('token'):
|
||||
kind = re.sub(r'_q\d\d*', "", item_data.get('token'))
|
||||
else:
|
||||
kind = item.get('type')
|
||||
kind = item_data.get('type')
|
||||
if kind not in active_items:
|
||||
active_items[kind] = {}
|
||||
icon = item['icon'] if item['icon'] else "//www.erepublik.net/images/modules/manager/tab_storage.png"
|
||||
item_data = dict(name=item.get("name"), time_left=item['active']['time_left'], icon=icon, kind=kind,
|
||||
quality=item.get("quality", 0))
|
||||
icon = item_data['icon'] if item_data[
|
||||
'icon'] else "//www.erepublik.net/images/modules/manager/tab_storage.png"
|
||||
item_data = dict(name=item_data.get("name"), time_left=item_data['active']['time_left'], icon=icon,
|
||||
kind=kind,
|
||||
quality=item_data.get("quality", 0))
|
||||
|
||||
if item.get('isPackBooster'):
|
||||
if item_data.get('isPackBooster'):
|
||||
active_items[kind].update({0: item_data})
|
||||
else:
|
||||
active_items[kind].update({item.get("quality"): item_data})
|
||||
active_items[kind].update({item_data.get("quality"): item_data})
|
||||
|
||||
final_items = {}
|
||||
for item in j.get("inventoryItems", {}).get("finalProducts", {}).get("items", {}).values():
|
||||
name = item['name']
|
||||
final_items: Dict[str, Dict[int, Dict[str, Union[str, int]]]] = {}
|
||||
if data.get("finalProducts", {}).get("items", {}):
|
||||
for item_data in data.get("finalProducts", {}).get("items", {}).values():
|
||||
name = item_data['name']
|
||||
|
||||
if item.get('type'):
|
||||
if item.get('type') in ['damageBoosters', "aircraftDamageBoosters"]:
|
||||
kind = f"{item['type']}{item['quality']}"
|
||||
if item['quality'] == 5:
|
||||
self.boosters[50].update({item['duration']: item['amount']})
|
||||
elif item['quality'] == 10:
|
||||
self.boosters[100].update({item['duration']: item['amount']})
|
||||
if item_data.get('type'):
|
||||
if item_data.get('type') in ['damageBoosters', "aircraftDamageBoosters"]:
|
||||
kind = f"{item_data['type']}{item_data['quality']}"
|
||||
if item_data['quality'] == 5:
|
||||
self.boosters[50].update({item_data['duration']: item_data['amount']})
|
||||
elif item_data['quality'] == 10:
|
||||
self.boosters[100].update({item_data['duration']: item_data['amount']})
|
||||
|
||||
delta = item['duration']
|
||||
if delta // 3600:
|
||||
name += f" {delta // 3600}h"
|
||||
if delta // 60 % 60:
|
||||
name += f" {delta // 60 % 60}m"
|
||||
if delta % 60:
|
||||
name += f" {delta % 60}s"
|
||||
else:
|
||||
kind = item.get('type')
|
||||
else:
|
||||
if item['industryId'] == 1:
|
||||
amount = item['amount']
|
||||
q = item['quality']
|
||||
if 1 <= q <= 7:
|
||||
self.food.update({f"q{q}": amount})
|
||||
delta = item_data['duration']
|
||||
if delta // 3600:
|
||||
name += f" {delta // 3600}h"
|
||||
if delta // 60 % 60:
|
||||
name += f" {delta // 60 % 60}m"
|
||||
if delta % 60:
|
||||
name += f" {delta % 60}s"
|
||||
else:
|
||||
if q == 10:
|
||||
self.eb_normal = amount
|
||||
elif q == 11:
|
||||
self.eb_double = amount
|
||||
elif q == 13:
|
||||
self.eb_small += amount
|
||||
elif q == 14:
|
||||
self.eb_small += amount
|
||||
elif q == 15:
|
||||
self.eb_small += amount
|
||||
kind = re.sub(r'_q\d\d*', "", item.get('token'))
|
||||
|
||||
if item.get('token', "") == "house_q100":
|
||||
self.ot_points = item['amount']
|
||||
|
||||
if kind not in final_items:
|
||||
final_items[kind] = {}
|
||||
|
||||
if item['icon']:
|
||||
icon = item['icon']
|
||||
else:
|
||||
if item['type'] == 'damageBoosters':
|
||||
icon = "/images/modules/pvp/damage_boosters/damage_booster.png"
|
||||
elif item['type'] == 'aircraftDamageBoosters':
|
||||
icon = "/images/modules/pvp/damage_boosters/air_damage_booster.png"
|
||||
elif item['type'] == 'prestigePointsBoosters':
|
||||
icon = "/images/modules/pvp/prestige_points_boosters/prestige_booster.png"
|
||||
elif item['type'] == 'speedBoosters':
|
||||
icon = "/images/modules/pvp/speed_boosters/speed_booster.png"
|
||||
elif item['type'] == 'catchupBoosters':
|
||||
icon = "/images/modules/pvp/ghost_boosters/icon_booster_30_60.png"
|
||||
kind = item_data.get('type')
|
||||
else:
|
||||
icon = "//www.erepublik.net/images/modules/manager/tab_storage.png"
|
||||
data = dict(kind=kind, quality=item.get('quality', 0), amount=item.get('amount', 0),
|
||||
durability=item.get('duration', 0), icon=icon, name=name)
|
||||
if item.get('type') in ('damageBoosters', "aircraftDamageBoosters"):
|
||||
data = {data['durability']: data}
|
||||
else:
|
||||
if item.get('type') == 'bomb':
|
||||
firepower = 0
|
||||
try:
|
||||
firepower = item.get('attributes').get('firePower').get('value', 0)
|
||||
except AttributeError:
|
||||
pass
|
||||
finally:
|
||||
data.update(fire_power=firepower)
|
||||
data = {data['quality']: data}
|
||||
final_items[kind].update(data)
|
||||
if item_data['industryId'] == 1:
|
||||
amount = item_data['amount']
|
||||
q = item_data['quality']
|
||||
if 1 <= q <= 7:
|
||||
self.food.update({f"q{q}": amount})
|
||||
else:
|
||||
if q == 10:
|
||||
self.eb_normal = amount
|
||||
elif q == 11:
|
||||
self.eb_double = amount
|
||||
elif q == 13:
|
||||
self.eb_small += amount
|
||||
elif q == 14:
|
||||
self.eb_small += amount
|
||||
elif q == 15:
|
||||
self.eb_small += amount
|
||||
kind = re.sub(r'_q\d\d*', "", item_data.get('token'))
|
||||
|
||||
raw_materials = {}
|
||||
if j.get("inventoryItems", {}).get("rawMaterials", {}).get("items", {}):
|
||||
for item in j.get("inventoryItems", {}).get("rawMaterials", {}).get("items", {}).values():
|
||||
if item['isPartial']:
|
||||
if item_data.get('token', "") == "house_q100":
|
||||
self.ot_points = item_data['amount']
|
||||
|
||||
if kind not in final_items:
|
||||
final_items[kind] = {}
|
||||
|
||||
if item_data['icon']:
|
||||
icon = item_data['icon']
|
||||
else:
|
||||
if item_data['type'] == 'damageBoosters':
|
||||
icon = "/images/modules/pvp/damage_boosters/damage_booster.png"
|
||||
elif item_data['type'] == 'aircraftDamageBoosters':
|
||||
icon = "/images/modules/pvp/damage_boosters/air_damage_booster.png"
|
||||
elif item_data['type'] == 'prestigePointsBoosters':
|
||||
icon = "/images/modules/pvp/prestige_points_boosters/prestige_booster.png"
|
||||
elif item_data['type'] == 'speedBoosters':
|
||||
icon = "/images/modules/pvp/speed_boosters/speed_booster.png"
|
||||
elif item_data['type'] == 'catchupBoosters':
|
||||
icon = "/images/modules/pvp/ghost_boosters/icon_booster_30_60.png"
|
||||
else:
|
||||
icon = "//www.erepublik.net/images/modules/manager/tab_storage.png"
|
||||
item_data = dict(kind=kind, quality=item_data.get('quality', 0), amount=item_data.get('amount', 0),
|
||||
durability=item_data.get('duration', 0), icon=icon, name=name)
|
||||
if item_data.get('type') in ('damageBoosters', "aircraftDamageBoosters"):
|
||||
item_data = {item_data['durability']: item_data}
|
||||
else:
|
||||
if item_data.get('type') == 'bomb':
|
||||
firepower = 0
|
||||
try:
|
||||
firepower = item_data.get('attributes').get('firePower').get('value', 0)
|
||||
except AttributeError:
|
||||
pass
|
||||
finally:
|
||||
item_data.update(fire_power=firepower)
|
||||
item_data = {item_data['quality']: item_data}
|
||||
final_items[kind].update(item_data)
|
||||
|
||||
raw_materials: Dict[str, Dict[int, Dict[str, Union[str, int]]]] = {}
|
||||
if data.get("rawMaterials", {}).get("items", {}):
|
||||
for item_data in data.get("rawMaterials", {}).get("items", {}).values():
|
||||
if item_data['isPartial']:
|
||||
continue
|
||||
kind = re.sub(r'_q\d\d*', "", item.get('token'))
|
||||
if kind == "magnesium":
|
||||
kind = "raw_aircraft"
|
||||
elif kind == "sand":
|
||||
kind = "raw_house"
|
||||
kind = constants.INDUSTRIES[item_data['industryId']]
|
||||
if kind not in raw_materials:
|
||||
raw_materials[kind] = []
|
||||
if item['icon'].startswith('//www.erepublik.net/'):
|
||||
icon = item['icon']
|
||||
raw_materials[kind] = {}
|
||||
if item_data['icon'].startswith('//www.erepublik.net/'):
|
||||
icon = item_data['icon']
|
||||
else:
|
||||
icon = "//www.erepublik.net/" + item['icon']
|
||||
icon = "//www.erepublik.net/" + item_data['icon']
|
||||
|
||||
raw_materials[kind].append(
|
||||
dict(name=item.get("name"), amount=item['amount'] + (item.get('underCostruction', 0) / 100),
|
||||
icon=icon)
|
||||
)
|
||||
raw_materials[constants.INDUSTRIES[item_data.get('industryId')]].update({
|
||||
0: dict(name=item_data.get("name"),
|
||||
amount=item_data['amount'] + (item_data.get('underCostruction', 0) / 100),
|
||||
icon=icon)
|
||||
})
|
||||
|
||||
offers = {}
|
||||
offers: Dict[str, Dict[int, Dict[str, Union[str, int]]]] = {}
|
||||
for offer in self._get_economy_my_market_offers().json():
|
||||
kind = constants.INDUSTRIES[offer['industryId']]
|
||||
data = dict(quality=offer.get('quality', 0), amount=offer.get('amount', 0), icon=offer.get('icon'),
|
||||
kind=kind, name=kind)
|
||||
data = {data['quality']: data}
|
||||
offer_data = dict(quality=offer.get('quality', 0), amount=offer.get('amount', 0), icon=offer.get('icon'),
|
||||
kind=kind, name=kind)
|
||||
offer_data = {offer_data['quality']: offer_data}
|
||||
|
||||
if kind not in offers:
|
||||
offers[kind] = {}
|
||||
|
||||
offers[kind].update(data)
|
||||
|
||||
self.inventory.update({"used": j.get("inventoryStatus").get("usedStorage"),
|
||||
"total": j.get("inventoryStatus").get("totalStorage")})
|
||||
inventory = dict(items=dict(active=active_items, final=final_items,
|
||||
raw=raw_materials, offers=offers), status=self.inventory)
|
||||
offers[kind].update(offer_data)
|
||||
self.inventory.clear()
|
||||
self.inventory.update(active=active_items, final=final_items, raw=raw_materials, offers=offers)
|
||||
self.food["total"] = sum([self.food[q] * constants.FOOD_ENERGY[q] for q in constants.FOOD_ENERGY])
|
||||
return inventory
|
||||
|
||||
def write_log(self, *args, **kwargs):
|
||||
if self.config.interactive:
|
||||
@ -403,6 +420,43 @@ class BaseCitizen(access_points.CitizenAPI):
|
||||
return_set.add(constants.COUNTRIES[country_data['id']])
|
||||
return return_set
|
||||
|
||||
def dump_instance(self):
|
||||
filename = f"{self.__class__.__name__}__dump.json"
|
||||
with open(filename, 'w') as f:
|
||||
utils.json.dump(dict(config=self.config, cookies=self._req.cookies.get_dict(),
|
||||
user_agent=self._req.headers.get("User-Agent")), f, cls=classes.MyJSONEncoder)
|
||||
self.write_log(f"Session saved to: '{filename}'")
|
||||
|
||||
@classmethod
|
||||
def load_from_dump(cls, dump_name: str):
|
||||
with open(dump_name) as f:
|
||||
data = utils.json.load(f)
|
||||
player = cls(data['config']['email'], "")
|
||||
player._req.cookies.update(data['cookies'])
|
||||
player._req.headers.update({"User-Agent": data['user_agent']})
|
||||
for k, v in data.get('config', {}).items():
|
||||
if hasattr(player.config, k):
|
||||
setattr(player.config, k, v)
|
||||
player._resume_session()
|
||||
return player
|
||||
|
||||
def _resume_session(self):
|
||||
resp = self._req.get(self.url)
|
||||
re_name_id = re.search(r'<a data-fblog="profile_avatar" href="/en/citizen/profile/(\d+)" '
|
||||
r'class="user_avatar" title="(.*?)">', resp.text)
|
||||
if re_name_id:
|
||||
self.name = re_name_id.group(2)
|
||||
self.details.citizen_id = re_name_id.group(1)
|
||||
self.write_log(f"Resumed as: {self.name}")
|
||||
if re.search('<div id="accountSecurity" class="it-hurts-when-ip">', resp.text):
|
||||
self.restricted_ip = True
|
||||
self.report_error("eRepublik has blacklisted IP. Limited functionality!", True)
|
||||
|
||||
self.logged_in = True
|
||||
self.get_csrf_token()
|
||||
else:
|
||||
self._login()
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"Citizen {self.name}"
|
||||
|
||||
@ -624,8 +678,16 @@ class BaseCitizen(access_points.CitizenAPI):
|
||||
self.sleep(5 * 60)
|
||||
else:
|
||||
raise classes.ErepublikException(f"HTTP {response.status_code} error!")
|
||||
|
||||
if re.search(r'Occasionally there are a couple of things which we need to check or to implement in order make '
|
||||
r'your experience in eRepublik more pleasant. <strong>Don\'t worry about ongoing battles, timer '
|
||||
r'will be stopped during maintenance.</strong>', response.text):
|
||||
self.write_log("eRepublik ss having maintenance. Sleeping for 5 minutes")
|
||||
self.sleep(5 * 60)
|
||||
return True
|
||||
return bool(re.search(r'body id="error"|Internal Server Error|'
|
||||
r'CSRF attack detected|meta http-equiv="refresh"|not_authenticated', response.text))
|
||||
r'CSRF attack detected|meta http-equiv="refresh"|'
|
||||
r'not_authenticated', response.text))
|
||||
|
||||
def _report_action(self, action: str, msg: str, **kwargs: Optional[Dict[str, Any]]):
|
||||
""" Report action to all available reporting channels
|
||||
@ -675,9 +737,7 @@ class CitizenAnniversary(BaseCitizen):
|
||||
_write_spin_data(current_cost, r.get('account'),
|
||||
base.get('prizes').get('prizes').get(str(r.get('result'))).get('tooltip'))
|
||||
else:
|
||||
is_cost: Callable[[], bool] = lambda: (max_cost != current_cost if max_cost else True)
|
||||
is_count: Callable[[], bool] = lambda: (spin_count != current_count if spin_count else True)
|
||||
while is_cost() or is_count():
|
||||
while max_cost >= current_cost if max_cost else spin_count >= current_count if spin_count else False:
|
||||
r = self._spin_wheel_of_loosing(current_cost)
|
||||
current_count += 1
|
||||
current_cost = r.get('cost')
|
||||
@ -686,8 +746,8 @@ class CitizenAnniversary(BaseCitizen):
|
||||
|
||||
def _spin_wheel_of_loosing(self, current_cost: int) -> Dict[str, Any]:
|
||||
r = self._post_main_wheel_of_fortune_spin(current_cost).json()
|
||||
self.details.cc = r.get('account')
|
||||
return r.get('result')
|
||||
self.details.cc = float(Decimal(r.get('account')))
|
||||
return r
|
||||
|
||||
|
||||
class CitizenTravel(BaseCitizen):
|
||||
@ -833,23 +893,24 @@ class CitizenCompanies(BaseCitizen):
|
||||
def work_as_manager_in_holding(self, holding: classes.Holding) -> Optional[Dict[str, Any]]:
|
||||
return self._work_as_manager(holding)
|
||||
|
||||
def _work_as_manager(self, wam_holding: classes.Holding = None) -> Optional[Dict[str, Any]]:
|
||||
def _work_as_manager(self, wam_holding: classes.Holding) -> Optional[Dict[str, Any]]:
|
||||
if self.restricted_ip:
|
||||
return None
|
||||
self.update_companies()
|
||||
self.update_inventory()
|
||||
data = {"action_type": "production"}
|
||||
extra = {}
|
||||
wam_list = []
|
||||
if wam_holding:
|
||||
raw_factories = wam_holding.get_wam_companies(raw_factory=True)
|
||||
fin_factories = wam_holding.get_wam_companies(raw_factory=False)
|
||||
raw_factories = wam_holding.get_wam_companies(raw_factory=True)
|
||||
fin_factories = wam_holding.get_wam_companies(raw_factory=False)
|
||||
|
||||
free_inventory = self.inventory["total"] - self.inventory["used"]
|
||||
wam_list = raw_factories + fin_factories
|
||||
wam_list = wam_list[:self.energy.food_fights]
|
||||
while wam_list and free_inventory < self.my_companies.get_needed_inventory_usage(wam_list):
|
||||
wam_list.pop(-1)
|
||||
free_inventory = self.inventory_status["total"] - self.inventory_status["used"]
|
||||
wam_list = raw_factories + fin_factories
|
||||
wam_list = wam_list[:self.energy.food_fights]
|
||||
|
||||
if int(free_inventory * 0.75) < self.my_companies.get_needed_inventory_usage(wam_list):
|
||||
self.update_inventory()
|
||||
|
||||
while wam_list and free_inventory < self.my_companies.get_needed_inventory_usage(wam_list):
|
||||
wam_list.pop(-1)
|
||||
|
||||
if wam_list:
|
||||
data.update(extra)
|
||||
@ -881,6 +942,7 @@ class CitizenCompanies(BaseCitizen):
|
||||
Assigns factory to new holding
|
||||
"""
|
||||
self.write_log(f"{company} moved to {holding}")
|
||||
company._holding = weakref.ref(holding)
|
||||
return self._post_economy_assign_to_holding(company.id, holding.id)
|
||||
|
||||
def create_factory(self, industry_id: int, building_type: int = 1) -> Response:
|
||||
@ -913,17 +975,17 @@ class CitizenEconomy(CitizenTravel):
|
||||
|
||||
def check_house_durability(self) -> Dict[int, datetime]:
|
||||
ret = {}
|
||||
inv = self.update_inventory()
|
||||
for house_quality, active_house in inv['items']['active'].get('house', {}).items():
|
||||
inv = self.get_inventory()
|
||||
for house_quality, active_house in inv['active'].get('house', {}).items():
|
||||
till = utils.good_timedelta(self.now, timedelta(seconds=active_house['time_left']))
|
||||
ret.update({house_quality: till})
|
||||
return ret
|
||||
|
||||
def buy_and_activate_house(self, q: int) -> Dict[int, datetime]:
|
||||
inventory = self.update_inventory()
|
||||
original_region = self.details.current_country, self.details.current_region
|
||||
ok_to_activate = False
|
||||
if not inventory['items']['final'].get('house', {}).get(q, {}):
|
||||
inv = self.get_inventory()
|
||||
if not inv['final'].get('house', {}).get(q, {}):
|
||||
countries = [self.details.citizenship, ]
|
||||
if self.details.current_country != self.details.citizenship:
|
||||
countries.append(self.details.current_country)
|
||||
@ -932,8 +994,10 @@ class CitizenEconomy(CitizenTravel):
|
||||
|
||||
global_cheapest = self.get_market_offers("house", q)[f"q{q}"]
|
||||
if global_cheapest.price + 200 < local_cheapest.price:
|
||||
self._travel(global_cheapest.country)
|
||||
buy = self.buy_from_market(global_cheapest.offer_id, 1)
|
||||
if self.travel_to_country(global_cheapest.country):
|
||||
buy = self.buy_from_market(global_cheapest.offer_id, 1)
|
||||
else:
|
||||
buy = {'error': True, 'message': 'Unable to travel!'}
|
||||
else:
|
||||
buy = self.buy_from_market(local_cheapest.offer_id, 1)
|
||||
if buy["error"]:
|
||||
@ -961,13 +1025,19 @@ class CitizenEconomy(CitizenTravel):
|
||||
house_durability = self.buy_and_activate_house(q)
|
||||
return house_durability
|
||||
|
||||
def activate_house(self, quality: int) -> datetime:
|
||||
active_until = self.now
|
||||
r = self._post_economy_activate_house(quality)
|
||||
if r.json().get("status") and not r.json().get("error"):
|
||||
house = r.json()["inventoryItems"]["activeEnhancements"]["items"]["4_%i_active" % quality]
|
||||
active_until = utils.good_timedelta(active_until, timedelta(seconds=house["active"]["time_left"]))
|
||||
return active_until
|
||||
def activate_house(self, quality: int) -> bool:
|
||||
r = self._post_economy_activate_house(quality).json()
|
||||
self._update_inventory_data(r)
|
||||
if r.get("status") and not r.json().get("error"):
|
||||
house: Dict[str, Union[int, str]] = self.get_inventory()['active']['house'][quality]
|
||||
time_left = timedelta(seconds=house["time_left"])
|
||||
active_until = utils.good_timedelta(self.now, time_left)
|
||||
self._report_action(
|
||||
'ACTIVATE_HOUSE',
|
||||
f"Activated {house['name']}. Expires at {active_until.strftime('%F %T')} (after {time_left})"
|
||||
)
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_game_token_offers(self):
|
||||
r = self._post_economy_game_tokens_market('retrieve').json()
|
||||
@ -1011,26 +1081,57 @@ class CitizenEconomy(CitizenTravel):
|
||||
ret.append(line)
|
||||
return ret
|
||||
|
||||
def post_market_offer(self, industry: int, quality: int, amount: int, price: float) -> Response:
|
||||
def delete_my_market_offer(self, offer_id: int) -> bool:
|
||||
offers = self.get_my_market_offers()
|
||||
for offer in offers:
|
||||
if offer['id'] == offer_id:
|
||||
industry = constants.INDUSTRIES[offer['industry']]
|
||||
amount = offer['amount']
|
||||
q = offer['quality']
|
||||
price = offer['price']
|
||||
ret = self._post_economy_marketplace_actions('delete', offer_id=offer_id).json()
|
||||
if ret.get('error'):
|
||||
self._report_action("ECONOMY_DELETE_OFFER", f"Unable to delete offer: '{ret.get('message')}'",
|
||||
kwargs=offer)
|
||||
else:
|
||||
self._report_action("ECONOMY_DELETE_OFFER",
|
||||
f"Removed offer for {amount} x {industry} q{q} for {price}cc/each",
|
||||
kwargs=offer)
|
||||
return ret.get('error')
|
||||
else:
|
||||
self._report_action("ECONOMY_DELETE_OFFER", f"Unable to find offer id{offer_id}", kwargs={'offers': offers})
|
||||
return False
|
||||
|
||||
def post_market_offer(self, industry: int, quality: int, amount: int, price: float) -> bool:
|
||||
if not constants.INDUSTRIES[industry]:
|
||||
self.write_log(f"Trying to sell unsupported industry {industry}")
|
||||
|
||||
final = industry in [1, 2, 4, 23]
|
||||
items = self.inventory['final' if final else 'raw'][constants.INDUSTRIES[industry]]
|
||||
if items[quality if final else 0]['amount'] < amount:
|
||||
self.update_inventory()
|
||||
items = self.inventory['final' if final else 'raw'][constants.INDUSTRIES[industry]]
|
||||
if items[quality if final else 0]['amount'] < amount:
|
||||
self._report_action("ECONOMY_SELL_PRODUCTS", "Unable to sell! Not enough items in storage!",
|
||||
kwargs=dict(inventory=items[quality if final else 0], amount=amount))
|
||||
return False
|
||||
|
||||
data = {
|
||||
"country_id": self.details.citizenship,
|
||||
"country_id": self.details.citizenship.id,
|
||||
"industry": industry,
|
||||
"quality": quality,
|
||||
"amount": amount,
|
||||
"price": price,
|
||||
"buy": False,
|
||||
}
|
||||
ret = self._post_economy_marketplace_actions(**data)
|
||||
ret = self._post_economy_marketplace_actions('sell', **data).json()
|
||||
message = (f"Posted market offer for {amount}q{quality} "
|
||||
f"{constants.INDUSTRIES[industry]} for price {price}cc")
|
||||
self._report_action("ECONOMY_SELL_PRODUCTS", message, kwargs=ret.json())
|
||||
return ret
|
||||
self._report_action("ECONOMY_SELL_PRODUCTS", message, kwargs=ret)
|
||||
return bool(ret.get('error', True))
|
||||
|
||||
def buy_from_market(self, offer: int, amount: int) -> dict:
|
||||
ret = self._post_economy_marketplace_actions(amount, True, offer=offer)
|
||||
ret = self._post_economy_marketplace_actions('buy', offer=offer, amount=amount)
|
||||
json_ret = ret.json()
|
||||
if json_ret.get('error'):
|
||||
return json_ret
|
||||
@ -1071,7 +1172,7 @@ class CitizenEconomy(CitizenTravel):
|
||||
start_dt = self.now
|
||||
iterable = [countries, [quality] if quality else range(1, max_quality + 1)]
|
||||
for country, q in product(*iterable):
|
||||
r = self._post_economy_marketplace(country, constants.INDUSTRIES[product_name], q).json()
|
||||
r = self._post_economy_marketplace(country.id, constants.INDUSTRIES[product_name], q).json()
|
||||
obj = offers[f"q{q}"]
|
||||
if not r.get("error", False):
|
||||
for offer in r["offers"]:
|
||||
@ -1140,7 +1241,6 @@ class CitizenEconomy(CitizenTravel):
|
||||
self.details.gold = float(response.json().get("gold").get("value"))
|
||||
if response.json().get('error'):
|
||||
self._report_action("BUY_GOLD", "Unable to buy gold!", kwargs=response.json())
|
||||
self.stop_threads.wait()
|
||||
return False
|
||||
else:
|
||||
self._report_action('BUY_GOLD', f'New amount {self.details.cc}cc, {self.details.gold}g',
|
||||
@ -1338,10 +1438,10 @@ class CitizenMilitary(CitizenTravel):
|
||||
all_battles = {}
|
||||
for battle_data in r_json.get("battles", {}).values():
|
||||
all_battles[battle_data.get('id')] = classes.Battle(battle_data)
|
||||
old_all_battles = self.all_battles
|
||||
# old_all_battles = self.all_battles
|
||||
self.all_battles = all_battles
|
||||
for battle in old_all_battles.values():
|
||||
utils._clear_up_battle_memory(battle)
|
||||
# for battle in old_all_battles.values():
|
||||
# utils._clear_up_battle_memory(battle)
|
||||
|
||||
def get_battle_for_war(self, war_id: int) -> Optional[classes.Battle]:
|
||||
self.update_war_info()
|
||||
@ -1382,6 +1482,7 @@ class CitizenMilitary(CitizenTravel):
|
||||
try:
|
||||
if weapon['weaponQuantity'] > 30 and weapon['weaponInfluence'] > weapon_damage:
|
||||
weapon_quality = int(weapon['weaponId'])
|
||||
weapon_damage = weapon['weaponInfluence']
|
||||
except ValueError:
|
||||
pass
|
||||
return self.change_weapon(battle, weapon_quality, division)
|
||||
@ -1540,8 +1641,8 @@ class CitizenMilitary(CitizenTravel):
|
||||
else:
|
||||
ground_divs.append((medal.get('1').get('raw_value'), division))
|
||||
|
||||
air_divs.sort(key=lambda z: (z[0],z[1].battle.start))
|
||||
ground_divs.sort(key=lambda z:(z[0],z[1].battle.start))
|
||||
air_divs.sort(key=lambda z: (z[0], z[1].battle.start))
|
||||
ground_divs.sort(key=lambda z: (z[0], z[1].battle.start))
|
||||
return {'air': air_divs, 'ground': ground_divs}
|
||||
|
||||
@property
|
||||
@ -1609,14 +1710,15 @@ class CitizenMilitary(CitizenTravel):
|
||||
self.travel_to_residence()
|
||||
break
|
||||
|
||||
def fight(self, battle: classes.Battle, division: classes.BattleDivision, side: classes.BattleSide = None, count: int = None) -> int:
|
||||
def fight(self, battle: classes.Battle, division: classes.BattleDivision, side: classes.BattleSide = None,
|
||||
count: int = None) -> int:
|
||||
"""Fight in a battle.
|
||||
|
||||
Will auto activate booster and travel if allowed to do it.
|
||||
:param battle: Battle battle to fight in
|
||||
:type battle: Battle
|
||||
:param side: BattleSide or None. Battle side to fight in, If side not == invader id or not in invader deployed
|
||||
allies list, then defender's side is chosen
|
||||
allies list, then defender's side is chosen
|
||||
:type side: BattleSide
|
||||
:param count: How many hits to do, if not specified self.should_fight() is called.
|
||||
:type count: int
|
||||
@ -1655,8 +1757,11 @@ class CitizenMilitary(CitizenTravel):
|
||||
self.write_log("Hits: {:>4} | Damage: {}".format(total_hits, total_damage))
|
||||
ok_to_fight = False
|
||||
if total_damage:
|
||||
self.reporter.report_action("FIGHT", dict(battle=str(battle), side=str(side), dmg=total_damage,
|
||||
air=battle.has_air, hits=total_hits))
|
||||
self.reporter.report_fighting(battle, not side.is_defender, division, total_damage, total_hits)
|
||||
# self.reporter.report_action('FIGHT', dict(battle_id=battle.id, side=side, dmg=total_damage,
|
||||
# air=battle.has_air, hits=total_hits,
|
||||
# round=battle.zone_id,
|
||||
# extra=dict(battle=battle, side=side)))
|
||||
return error_count
|
||||
|
||||
def _shoot(self, battle: classes.Battle, division: classes.BattleDivision, side: classes.BattleSide):
|
||||
@ -1676,14 +1781,17 @@ class CitizenMilitary(CitizenTravel):
|
||||
damage = 0
|
||||
err = False
|
||||
if r_json.get("error"):
|
||||
if r_json.get("message") == "SHOOT_LOCKOUT" or r_json.get("message") == "ZONE_INACTIVE":
|
||||
if r_json.get("message") == "SHOOT_LOCKOUT":
|
||||
pass
|
||||
elif r_json.get("message") == "NOT_ENOUGH_WEAPONS":
|
||||
self.set_default_weapon(battle, division)
|
||||
elif r_json.get("message") == "Cannot activate a zone with a non-native division":
|
||||
self.write_log("Wrong division!!")
|
||||
return 0, 10, 0
|
||||
elif r_json.get("message") == "FIGHT_DISABLED":
|
||||
elif r_json.get("message") == "ZONE_INACTIVE":
|
||||
self.write_log("Wrong division!!")
|
||||
return 0, 10, 0
|
||||
elif r_json.get("message") in ["FIGHT_DISABLED", "DEPLOYMENT_MODE"]:
|
||||
self._post_main_profile_update('options',
|
||||
params='{"optionName":"enable_web_deploy","optionValue":"off"}')
|
||||
self.set_default_weapon(battle, division)
|
||||
@ -1763,7 +1871,8 @@ class CitizenMilitary(CitizenTravel):
|
||||
if resp.json().get('error'):
|
||||
self.write_log(resp.json().get('message'))
|
||||
return False
|
||||
self._report_action("MILITARY_DIV_SWITCH", f"Switched to d{division.div} in battle {battle.id}", kwargs=resp.json())
|
||||
self._report_action("MILITARY_DIV_SWITCH", f"Switched to d{division.div} in battle {battle.id}",
|
||||
kwargs=resp.json())
|
||||
return True
|
||||
|
||||
def get_ground_hit_dmg_value(self, rang: int = None, strength: float = None, elite: bool = None, ne: bool = False,
|
||||
@ -1804,12 +1913,12 @@ class CitizenMilitary(CitizenTravel):
|
||||
self._report_action("MILITARY_BOOSTER", f"Activated 50% {duration / 60}h damage booster")
|
||||
self._post_economy_activate_booster(5, duration, "damage")
|
||||
|
||||
def get_active_ground_damage_booster(self):
|
||||
inventory = self.update_inventory()
|
||||
def get_active_ground_damage_booster(self) -> int:
|
||||
inventory = self.get_inventory()
|
||||
quality = 0
|
||||
if inventory['items']['active'].get('damageBoosters', {}).get(10):
|
||||
if inventory['active'].get('damageBoosters', {}).get(10):
|
||||
quality = 100
|
||||
elif inventory['items']['active'].get('damageBoosters', {}).get(5):
|
||||
elif inventory['active'].get('damageBoosters', {}).get(5):
|
||||
quality = 50
|
||||
return quality
|
||||
|
||||
@ -1963,6 +2072,13 @@ class CitizenMilitary(CitizenTravel):
|
||||
return member.get('panelContents', {}).get('members', [{}])[0].get('dailyOrdersCompleted')
|
||||
return 0
|
||||
|
||||
def get_possibly_empty_medals(self):
|
||||
self.update_war_info()
|
||||
for battle in self.all_battles.values():
|
||||
for division in battle.div.values():
|
||||
if division.wall['dom'] == 50 or division.wall['dom'] > 98:
|
||||
yield division, division.wall['for'] == battle.invader.country.id
|
||||
|
||||
|
||||
class CitizenPolitics(BaseCitizen):
|
||||
def get_country_parties(self, country: constants.Country = None) -> dict:
|
||||
@ -1980,15 +2096,16 @@ class CitizenPolitics(BaseCitizen):
|
||||
self._report_action('POLITIC_PARTY_PRESIDENT', 'Applied for party president elections')
|
||||
return self._get_candidate_party(self.politics.party_slug)
|
||||
|
||||
def get_country_president_election_result(self, country: constants.Country, year: int, month: int) -> Dict[str, int]:
|
||||
def get_country_president_election_result(
|
||||
self, country: constants.Country, year: int, month: int
|
||||
) -> Dict[str, int]:
|
||||
timestamp = int(constants.erep_tz.localize(datetime(year, month, 5)).timestamp())
|
||||
resp = self._get_presidential_elections(country.id, timestamp)
|
||||
candidates = re.findall(r'class="candidate_info">(.*?)</li>', resp.text, re.S | re.M)
|
||||
ret = {}
|
||||
for candidate in candidates:
|
||||
name = re.search(
|
||||
r'<a hovercard=1 class="candidate_name" href="//www.erepublik.com/en/citizen/profile/\d+" title="(.*)">',
|
||||
candidate)
|
||||
name = re.search(r'<a hovercard=1 class="candidate_name" href="//www.erepublik.com/en/citizen/profile/\d+"'
|
||||
r' title="(.*)">', candidate)
|
||||
name = name.group(1)
|
||||
votes = re.search(r'<span class="votes">(\d+) votes</span>', candidate).group(1)
|
||||
ret.update({name: int(votes)})
|
||||
@ -1996,17 +2113,7 @@ class CitizenPolitics(BaseCitizen):
|
||||
|
||||
|
||||
class CitizenSocial(BaseCitizen):
|
||||
def send_mail_to_owner(self):
|
||||
if not self.details.citizen_id == 1620414:
|
||||
self.send_mail('Started', f'time {self.now.strftime("%Y-%m-%d %H-%M-%S")}', [1620414, ])
|
||||
self.sleep(1)
|
||||
msg_id = re.search(r'<input type="hidden" value="(\d+)" '
|
||||
r'id="delete_message_(\d+)" name="delete_message\[]">', self.r.text).group(1)
|
||||
self._post_delete_message([msg_id])
|
||||
|
||||
def send_mail(self, subject: str, msg: str, ids: List[int] = None):
|
||||
if ids is None:
|
||||
ids = [1620414, ]
|
||||
def send_mail(self, subject: str, msg: str, ids: List[int]):
|
||||
for player_id in ids:
|
||||
self._report_action('SOCIAL_MESSAGE', f'Sent a message to {player_id}',
|
||||
kwargs=dict(subject=subject, msg=msg, id=player_id))
|
||||
@ -2061,20 +2168,23 @@ class CitizenSocial(BaseCitizen):
|
||||
def get_report_notifications(self, page: int = 1) -> List[Dict[str, Any]]:
|
||||
return self._get_main_notifications_ajax_report(page).json().get('alertsList', [])
|
||||
|
||||
def delete_community_notification(self, notification_id: Union[int, List[int]]):
|
||||
if not isinstance(notification_id, list):
|
||||
notification_id = [notification_id]
|
||||
self._post_main_notifications_ajax_community(notification_id)
|
||||
def delete_community_notification(self, *notification_ids: int):
|
||||
ids = []
|
||||
for _id in sorted(notification_ids):
|
||||
ids.append(int(_id))
|
||||
self._post_main_notifications_ajax_community(ids)
|
||||
|
||||
def delete_system_notification(self, notification_id: Union[int, List[int]]):
|
||||
if not isinstance(notification_id, list):
|
||||
notification_id = [notification_id]
|
||||
self._post_main_notifications_ajax_system(notification_id)
|
||||
def delete_system_notification(self, *notification_ids: int):
|
||||
ids = []
|
||||
for _id in sorted(notification_ids):
|
||||
ids.append(int(_id))
|
||||
self._post_main_notifications_ajax_system(ids)
|
||||
|
||||
def delete_report_notification(self, notification_id: Union[int, List[int]]):
|
||||
if not isinstance(notification_id, list):
|
||||
notification_id = [notification_id]
|
||||
self._post_main_notifications_ajax_report(notification_id)
|
||||
def delete_report_notification(self, *notification_ids: int):
|
||||
ids = []
|
||||
for _id in sorted(notification_ids):
|
||||
ids.append(int(_id))
|
||||
self._post_main_notifications_ajax_report(ids)
|
||||
|
||||
def get_all_notifications(self, page: int = 1) -> Dict[str, List[Dict[str, Any]]]:
|
||||
return dict(community=self.get_community_notifications(),
|
||||
@ -2085,11 +2195,11 @@ class CitizenSocial(BaseCitizen):
|
||||
for kind, notifications in self.get_all_notifications():
|
||||
if notifications:
|
||||
if kind == "community":
|
||||
self.delete_community_notification([n['id'] for n in notifications])
|
||||
self.delete_community_notification(*[n['id'] for n in notifications])
|
||||
elif kind == "report":
|
||||
self.delete_report_notification([n['id'] for n in notifications])
|
||||
self.delete_report_notification(*[n['id'] for n in notifications])
|
||||
elif kind == "system":
|
||||
self.delete_system_notification([n['id'] for n in notifications])
|
||||
self.delete_system_notification(*[n['id'] for n in notifications])
|
||||
else:
|
||||
self.report_error(f"Unsupported notification kind: \"{kind}\"!")
|
||||
|
||||
@ -2162,10 +2272,9 @@ class CitizenTasks(BaseCitizen):
|
||||
self._eat("blue")
|
||||
if self.energy.food_fights < len(tgs):
|
||||
large = max(self.energy.reference_time, self.now)
|
||||
small = min(self.energy.reference_time, self.now)
|
||||
self.write_log("I don't have energy to train. Will sleep for {} seconds".format(
|
||||
(large - small).seconds))
|
||||
self.sleep(int((large - small).total_seconds()))
|
||||
sleep_seconds = utils.get_sleep_seconds(large)
|
||||
self.write_log(f"I don't have energy to train. Will sleep for {sleep_seconds} seconds")
|
||||
self.sleep(sleep_seconds)
|
||||
self._eat("blue")
|
||||
self.train()
|
||||
|
||||
@ -2185,14 +2294,14 @@ class CitizenTasks(BaseCitizen):
|
||||
self._eat("blue")
|
||||
if self.energy.food_fights < 1:
|
||||
large = max(self.energy.reference_time, self.now)
|
||||
small = min(self.energy.reference_time, self.now)
|
||||
self.write_log("I don't have energy to work OT. Will sleep for {}s".format((large - small).seconds))
|
||||
self.sleep(int((large - small).total_seconds()))
|
||||
sleep_seconds = utils.get_sleep_seconds(large)
|
||||
self.write_log(f"I don't have energy to work OT. Will sleep for {sleep_seconds}s")
|
||||
self.sleep(sleep_seconds)
|
||||
self._eat("blue")
|
||||
self.work_ot()
|
||||
|
||||
def resign_from_employer(self) -> bool:
|
||||
r = self.update_job_info()
|
||||
r = self._get_main_job_data()
|
||||
if r.json().get("isEmployee"):
|
||||
self._report_action('ECONOMY_RESIGN', 'Resigned from employer!', kwargs=r.json())
|
||||
self._post_economy_resign()
|
||||
@ -2234,20 +2343,26 @@ class CitizenTasks(BaseCitizen):
|
||||
if ot:
|
||||
self.next_ot_time = utils.localize_timestamp(int(ot.get("nextOverTime", 0)))
|
||||
self.ot_points = ot.get("points", 0)
|
||||
return resp
|
||||
|
||||
|
||||
class Citizen(CitizenAnniversary, CitizenCompanies, CitizenEconomy, CitizenLeaderBoard,
|
||||
CitizenMedia, CitizenMilitary, CitizenPolitics, CitizenSocial, CitizenTasks):
|
||||
debug: bool = False
|
||||
|
||||
def __init__(self, email: str = "", password: str = "", auto_login: bool = True):
|
||||
def __init__(self, email: str = "", password: str = "", auto_login: bool = False):
|
||||
super().__init__(email, password)
|
||||
self._last_full_update = utils.good_timedelta(self.now, - timedelta(minutes=5))
|
||||
self._last_full_update = constants.min_datetime
|
||||
self.set_debug(True)
|
||||
if auto_login:
|
||||
self.login()
|
||||
|
||||
@classmethod
|
||||
def load_from_dump(cls, dump_name: str = ""):
|
||||
filename = dump_name if dump_name else f"{cls.__name__}__dump.json"
|
||||
player: Citizen = super().load_from_dump(filename) # noqa
|
||||
player.login()
|
||||
return player
|
||||
|
||||
def config_setup(self, **kwargs):
|
||||
self.config.reset()
|
||||
for key, value in kwargs.items():
|
||||
@ -2268,7 +2383,6 @@ class Citizen(CitizenAnniversary, CitizenCompanies, CitizenEconomy, CitizenLeade
|
||||
"" if self.config.telegram_chat_id or self.config.telegram_token else self.name)
|
||||
self.telegram.send_message(f"*Started* {utils.now():%F %T}")
|
||||
|
||||
self._last_full_update = utils.good_timedelta(self.now, - timedelta(minutes=5))
|
||||
self.update_all(True)
|
||||
|
||||
def update_citizen_info(self, html: str = None):
|
||||
@ -2335,26 +2449,24 @@ class Citizen(CitizenAnniversary, CitizenCompanies, CitizenEconomy, CitizenLeade
|
||||
self.reporter.report_action("NEW_MEDAL", info)
|
||||
|
||||
def set_debug(self, debug: bool):
|
||||
self.debug = debug
|
||||
self._req.debug = debug
|
||||
self.debug = bool(debug)
|
||||
self._req.debug = bool(debug)
|
||||
|
||||
def set_pin(self, pin: int):
|
||||
self.details.pin = pin
|
||||
def set_pin(self, pin: str):
|
||||
self.details.pin = str(pin[:4])
|
||||
|
||||
def update_all(self, force_update=False):
|
||||
# Do full update max every 5 min
|
||||
if utils.good_timedelta(self._last_full_update, timedelta(minutes=5)) > self.now and not force_update:
|
||||
return
|
||||
else:
|
||||
if utils.good_timedelta(self._last_full_update, timedelta(minutes=5)) < self.now or force_update:
|
||||
self._last_full_update = self.now
|
||||
self.update_citizen_info()
|
||||
self.update_war_info()
|
||||
self.update_inventory()
|
||||
self.update_companies()
|
||||
self.update_money()
|
||||
self.update_weekly_challenge()
|
||||
self.send_state_update()
|
||||
self.check_for_notification_medals()
|
||||
self.update_citizen_info()
|
||||
self.update_war_info()
|
||||
self.update_inventory()
|
||||
self.update_companies()
|
||||
self.update_money()
|
||||
self.update_weekly_challenge()
|
||||
self.send_state_update()
|
||||
self.check_for_notification_medals()
|
||||
|
||||
def update_weekly_challenge(self):
|
||||
data = self._get_main_weekly_challenge_data().json()
|
||||
@ -2396,6 +2508,7 @@ class Citizen(CitizenAnniversary, CitizenCompanies, CitizenEconomy, CitizenLeade
|
||||
return count, log_msg, force_fight
|
||||
|
||||
def collect_weekly_reward(self):
|
||||
utils.deprecation(f"Logic moved to {self.__class__.__name__}.update_weekly_challenge()!")
|
||||
self.update_weekly_challenge()
|
||||
|
||||
def collect_daily_task(self):
|
||||
@ -2415,6 +2528,7 @@ class Citizen(CitizenAnniversary, CitizenCompanies, CitizenEconomy, CitizenLeade
|
||||
start_time = utils.good_timedelta(start_time, timedelta(minutes=30))
|
||||
self.send_state_update()
|
||||
self.send_inventory_update()
|
||||
self.reporter.report_action('COMPANIES', json_val=self.my_companies.as_dict)
|
||||
sleep_seconds = (start_time - self.now).total_seconds()
|
||||
self.stop_threads.wait(sleep_seconds if sleep_seconds > 0 else 0)
|
||||
except: # noqa
|
||||
@ -2422,13 +2536,13 @@ class Citizen(CitizenAnniversary, CitizenCompanies, CitizenEconomy, CitizenLeade
|
||||
|
||||
def send_state_update(self):
|
||||
data = dict(xp=self.details.xp, cc=self.details.cc, gold=self.details.gold, pp=self.details.pp,
|
||||
inv_total=self.inventory['total'], inv=self.inventory['used'], hp_limit=self.energy.limit,
|
||||
inv_total=self.inventory_status['total'], inv=self.inventory_status['used'],
|
||||
hp_limit=self.energy.limit,
|
||||
hp_interval=self.energy.interval, hp_available=self.energy.available, food=self.food['total'], )
|
||||
self.reporter.send_state_update(**data)
|
||||
|
||||
def send_inventory_update(self):
|
||||
to_report = self.update_inventory()
|
||||
self.reporter.report_action("INVENTORY", json_val=to_report)
|
||||
self.reporter.report_action("INVENTORY", json_val=self.get_inventory(True))
|
||||
|
||||
def eat(self):
|
||||
"""
|
||||
@ -2512,7 +2626,8 @@ class Citizen(CitizenAnniversary, CitizenCompanies, CitizenEconomy, CitizenLeade
|
||||
else:
|
||||
if not start_place == (self.details.current_country, self.details.current_region):
|
||||
self.travel_to_holding(holding)
|
||||
return self._wam(holding)
|
||||
self._wam(holding)
|
||||
return
|
||||
elif response.get("message") == "not_enough_health_food":
|
||||
self.buy_food()
|
||||
self._wam(holding)
|
||||
@ -2528,7 +2643,7 @@ class Citizen(CitizenAnniversary, CitizenCompanies, CitizenEconomy, CitizenLeade
|
||||
:rtype: bool
|
||||
"""
|
||||
if self.restricted_ip:
|
||||
self._report_action("IP_BLACKLISTED", "Fighting is not allowed from restricted IP!")
|
||||
self._report_action("IP_BLACKLISTED", "Work as manager is not allowed from restricted IP!")
|
||||
return False
|
||||
self.update_citizen_info()
|
||||
self.update_companies()
|
||||
@ -2545,6 +2660,11 @@ class Citizen(CitizenAnniversary, CitizenCompanies, CitizenEconomy, CitizenLeade
|
||||
self.update_companies()
|
||||
|
||||
for holding in regions.values():
|
||||
raw_usage = holding.get_wam_raw_usage()
|
||||
free_storage = self.inventory_status['total'] - self.inventory_status['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.update_companies()
|
||||
|
@ -3,7 +3,7 @@ import hashlib
|
||||
import threading
|
||||
import weakref
|
||||
from decimal import Decimal
|
||||
from typing import Any, Dict, List, NamedTuple, Optional, Tuple, Union
|
||||
from typing import Any, Dict, List, NamedTuple, Optional, Tuple, Union, NoReturn, Generator, Iterable
|
||||
|
||||
from requests import Response, Session, post
|
||||
|
||||
@ -28,27 +28,38 @@ class Holding:
|
||||
id: int
|
||||
region: int
|
||||
companies: List["Company"]
|
||||
name: str
|
||||
_citizen = weakref.ReferenceType
|
||||
|
||||
def __init__(self, _id: int, region: int, citizen):
|
||||
def __init__(self, _id: int, region: int, citizen, name: str = None):
|
||||
self._citizen = weakref.ref(citizen)
|
||||
self.id: int = _id
|
||||
self.region: int = region
|
||||
self.companies: List["Company"] = list()
|
||||
if name:
|
||||
self.name = name
|
||||
else:
|
||||
comp_sum = len(self.companies)
|
||||
name = f"Holding (#{self.id}) with {comp_sum} "
|
||||
if comp_sum == 1:
|
||||
name += "company"
|
||||
else:
|
||||
name += "companies"
|
||||
self.name = name
|
||||
|
||||
@property
|
||||
def wam_count(self) -> int:
|
||||
return sum([company.wam_enabled and not company.already_worked for company in self.companies])
|
||||
return len([1 for company in self.companies if company.wam_enabled and not company.already_worked])
|
||||
|
||||
@property
|
||||
def wam_companies(self) -> List["Company"]:
|
||||
def wam_companies(self) -> Iterable["Company"]:
|
||||
return [company for company in self.companies if company.wam_enabled]
|
||||
|
||||
@property
|
||||
def employable_companies(self) -> List["Company"]:
|
||||
def employable_companies(self) -> Iterable["Company"]:
|
||||
return [company for company in self.companies if company.preset_works]
|
||||
|
||||
def add_company(self, company: "Company"):
|
||||
def add_company(self, company: "Company") -> NoReturn:
|
||||
self.companies.append(company)
|
||||
self.companies.sort()
|
||||
|
||||
@ -62,7 +73,7 @@ class Holding:
|
||||
wrm += company.raw_usage
|
||||
return dict(frm=frm, wrm=wrm)
|
||||
|
||||
def get_wam_companies(self, raw_factory: bool = None):
|
||||
def get_wam_companies(self, raw_factory: bool = None) -> List["Company"]:
|
||||
raw = []
|
||||
factory = []
|
||||
for company in self.wam_companies:
|
||||
@ -71,18 +82,15 @@ class Holding:
|
||||
raw.append(company)
|
||||
else:
|
||||
factory.append(company)
|
||||
if raw_factory is not None and not raw_factory:
|
||||
return factory
|
||||
elif raw_factory is not None and raw_factory:
|
||||
return raw
|
||||
elif raw_factory is None:
|
||||
if raw_factory is None:
|
||||
return raw + factory
|
||||
else:
|
||||
raise ErepublikException("raw_factory should be True/False/None")
|
||||
return raw if raw_factory else factory
|
||||
|
||||
def __str__(self):
|
||||
name = f"Holding (#{self.id}) with {len(self.companies)} "
|
||||
if len(self.companies) % 10 == 1:
|
||||
def __str__(self) -> str:
|
||||
comp = len(self.companies)
|
||||
name = f"Holding (#{self.id}) with {comp} "
|
||||
if comp == 1:
|
||||
name += "company"
|
||||
else:
|
||||
name += "companies"
|
||||
@ -92,8 +100,9 @@ class Holding:
|
||||
return str(self)
|
||||
|
||||
@property
|
||||
def as_dict(self):
|
||||
return dict(name=str(self), id=self.id, region=self.region, companies=self.companies, wam_count=self.wam_count)
|
||||
def as_dict(self) -> Dict[str, Union[str, int, List[Dict[str, Union[str, int, bool, float, Decimal]]]]]:
|
||||
return dict(name=self.name, id=self.id, region=self.region,
|
||||
companies=[c.as_dict for c in self.companies], wam_count=self.wam_count)
|
||||
|
||||
@property
|
||||
def citizen(self):
|
||||
@ -170,7 +179,7 @@ class Company:
|
||||
|
||||
@property
|
||||
def _sort_keys(self):
|
||||
return not self.is_raw, self._internal_industry, -self.quality, self.id
|
||||
return not self.is_raw, self._internal_industry, self.quality, self.id
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self._sort_keys)
|
||||
@ -203,7 +212,7 @@ class Company:
|
||||
return str(self)
|
||||
|
||||
@property
|
||||
def as_dict(self):
|
||||
def as_dict(self) -> Dict[str, Union[str, int, bool, float, Decimal]]:
|
||||
return dict(name=str(self), holding=self.holding.id, id=self.id, quality=self.quality, is_raw=self.is_raw,
|
||||
raw_usage=self.raw_usage, products_made=self.products_made, wam_enabled=self.wam_enabled,
|
||||
can_wam=self.can_wam, cannot_wam_reason=self.cannot_wam_reason, industry=self.industry,
|
||||
@ -219,7 +228,7 @@ class Company:
|
||||
return self.holding.citizen._post_economy_upgrade_company(self.id, level, self.holding.citizen.details.pin)
|
||||
|
||||
@property
|
||||
def holding(self):
|
||||
def holding(self) -> Holding:
|
||||
return self._holding()
|
||||
|
||||
|
||||
@ -229,13 +238,14 @@ class MyCompanies:
|
||||
ff_lockdown: int = 0
|
||||
|
||||
holdings: Dict[int, Holding]
|
||||
companies: weakref.WeakSet
|
||||
_companies: weakref.WeakSet
|
||||
_citizen: weakref.ReferenceType
|
||||
companies: Generator[Company, None, None]
|
||||
|
||||
def __init__(self, citizen):
|
||||
self._citizen = weakref.ref(citizen)
|
||||
self.holdings: Dict[int, Holding] = dict()
|
||||
self.companies: weakref.WeakSet = weakref.WeakSet()
|
||||
self.holdings = dict()
|
||||
self._companies = weakref.WeakSet()
|
||||
self.next_ot_time = utils.now()
|
||||
|
||||
def prepare_holdings(self, holdings: Dict[str, Dict[str, Any]]):
|
||||
@ -245,10 +255,10 @@ class MyCompanies:
|
||||
for holding in holdings.values():
|
||||
if holding.get('id') not in self.holdings:
|
||||
self.holdings.update({
|
||||
int(holding.get('id')): Holding(holding['id'], holding['region_id'], self.citizen)
|
||||
int(holding.get('id')): Holding(holding['id'], holding['region_id'], self.citizen, holding['name'])
|
||||
})
|
||||
if not self.holdings.get(0):
|
||||
self.holdings.update({0: Holding(0, 0, self.citizen)}) # unassigned
|
||||
self.holdings.update({0: Holding(0, 0, self.citizen, 'Unassigned')}) # unassigned
|
||||
|
||||
def prepare_companies(self, companies: Dict[str, Dict[str, Any]]):
|
||||
"""
|
||||
@ -270,7 +280,7 @@ class MyCompanies:
|
||||
company_dict.get('can_work_as_manager'), company_dict.get('cannot_work_as_manager_reason'),
|
||||
company_dict.get('industry_id'), company_dict.get('already_worked'), company_dict.get('preset_works')
|
||||
)
|
||||
self.companies.add(company)
|
||||
self._companies.add(company)
|
||||
holding.add_company(company)
|
||||
|
||||
def get_employable_factories(self) -> Dict[int, int]:
|
||||
@ -280,29 +290,35 @@ class MyCompanies:
|
||||
return sum([holding.wam_count for holding in self.holdings.values()])
|
||||
|
||||
@staticmethod
|
||||
def get_needed_inventory_usage(companies: Union[Company, List[Company]]) -> Decimal:
|
||||
def get_needed_inventory_usage(companies: Union[Company, Iterable[Company]]) -> Decimal:
|
||||
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:
|
||||
return companies.products_made
|
||||
|
||||
@property
|
||||
def companies(self) -> Generator[Company, None, None]:
|
||||
return (c for c in self._companies)
|
||||
|
||||
def __str__(self):
|
||||
return f"MyCompanies: {len(self.companies)} companies in {len(self.holdings)} holdings"
|
||||
return f"MyCompanies: {sum(1 for _ in self.companies)} companies in {len(self.holdings)} holdings"
|
||||
|
||||
def __repr__(self):
|
||||
return str(self)
|
||||
|
||||
def __clear_data(self):
|
||||
for holding in self.holdings.values():
|
||||
for company in holding.companies:
|
||||
for company in holding.companies: # noqa
|
||||
del company
|
||||
holding.companies.clear()
|
||||
self.companies.clear()
|
||||
self._companies.clear()
|
||||
|
||||
@property
|
||||
def as_dict(self):
|
||||
def as_dict(self) -> Dict[str, Union[str, int, datetime.datetime, Dict[str, Dict[str, Union[str, int, List[Dict[str, Union[str, int, bool, float, Decimal]]]]]]]]:
|
||||
return dict(name=str(self), work_units=self.work_units, next_ot_time=self.next_ot_time,
|
||||
ff_lockdown=self.ff_lockdown, holdings=self.holdings, company_count=len(self.companies))
|
||||
ff_lockdown=self.ff_lockdown,
|
||||
holdings={str(hi): h.as_dict for hi, h in self.holdings.items()},
|
||||
company_count=sum(1 for _ in self.companies))
|
||||
|
||||
@property
|
||||
def citizen(self):
|
||||
@ -438,24 +454,25 @@ class Energy:
|
||||
|
||||
|
||||
class Details:
|
||||
xp = 0
|
||||
cc = 0
|
||||
pp = 0
|
||||
pin = None
|
||||
gold = 0
|
||||
xp: int = 0
|
||||
cc: float = 0
|
||||
pp: int = 0
|
||||
pin: str = None
|
||||
gold: float = 0
|
||||
next_pp: List[int] = None
|
||||
citizen_id = 0
|
||||
citizen_id: int = 0
|
||||
citizenship: constants.Country
|
||||
current_region = 0
|
||||
current_region: int = 0
|
||||
current_country: constants.Country
|
||||
residence_region = 0
|
||||
residence_region: int = 0
|
||||
residence_country: constants.Country
|
||||
daily_task_done = False
|
||||
daily_task_reward = False
|
||||
mayhem_skills = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 0, 9: 0, 10: 0, 11: 0, 12: 0, 13: 0, 14: 0, }
|
||||
daily_task_done: bool = False
|
||||
daily_task_reward: bool = False
|
||||
mayhem_skills: Dict[int, int]
|
||||
|
||||
def __init__(self):
|
||||
self.next_pp = []
|
||||
self.mayhem_skills = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 0, 9: 0, 10: 0, 11: 0, 12: 0, 13: 0, 14: 0}
|
||||
|
||||
@property
|
||||
def xp_till_level_up(self):
|
||||
@ -549,7 +566,10 @@ class Reporter:
|
||||
self._citizen = weakref.ref(citizen)
|
||||
self._req = Session()
|
||||
self.url = "https://api.erep.lv"
|
||||
self._req.headers.update({"user-agent": "Bot reporter v2"})
|
||||
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.__registered: bool = False
|
||||
|
||||
@ -569,8 +589,8 @@ class Reporter:
|
||||
def __bot_update(self, data: dict) -> Response:
|
||||
if self.__to_update:
|
||||
for unreported_data in self.__to_update:
|
||||
unreported_data.update(player_id=self.citizen.id, key=self.key)
|
||||
unreported_data = utils.json.load(utils.json.dumps(unreported_data, cls=MyJSONEncoder))
|
||||
unreported_data.update(player_id=self.citizen_id, key=self.key)
|
||||
unreported_data = utils.json.loads(utils.json.dumps(unreported_data, cls=MyJSONEncoder))
|
||||
self._req.post("{}/bot/update".format(self.url), json=unreported_data)
|
||||
self.__to_update.clear()
|
||||
data = utils.json.loads(utils.json.dumps(data, cls=MyJSONEncoder))
|
||||
@ -615,6 +635,12 @@ class Reporter:
|
||||
else:
|
||||
self.__to_update.append(json_data)
|
||||
|
||||
def report_fighting(self, battle: "Battle", invader: bool, division: "BattleDivision", damage: float, hits: int):
|
||||
side = battle.invader if invader else battle.defender
|
||||
self.report_action('FIGHT', dict(battle_id=battle.id, side=side, dmg=damage,
|
||||
air=battle.has_air, hits=hits,
|
||||
round=battle.zone_id, extra=dict(battle=battle, side=side, division=division)))
|
||||
|
||||
def report_promo(self, kind: str, time_until: datetime.datetime):
|
||||
self._req.post(f"{self.url}/promos/add/", data=dict(kind=kind, time_untill=time_until))
|
||||
|
||||
@ -626,13 +652,13 @@ class Reporter:
|
||||
except: # noqa
|
||||
return []
|
||||
|
||||
def fetch_tasks(self) -> Optional[Tuple[str, Tuple[Any]]]:
|
||||
def fetch_tasks(self) -> List[Union[str, Tuple[Any]]]:
|
||||
try:
|
||||
task_response = self._req.get(f'{self.url}/api/v1/command',
|
||||
params=dict(citizen=self.citizen_id, key=self.key))
|
||||
return task_response.json().get('task_collection')
|
||||
except: # noqa
|
||||
return
|
||||
return []
|
||||
|
||||
|
||||
class MyJSONEncoder(utils.json.JSONEncoder):
|
||||
@ -669,7 +695,7 @@ class BattleSide:
|
||||
battle: "Battle"
|
||||
_battle: weakref.ReferenceType
|
||||
country: constants.Country
|
||||
defender: bool
|
||||
is_defender: bool
|
||||
|
||||
def __init__(self, battle: "Battle", country: constants.Country, points: int, allies: List[constants.Country],
|
||||
deployed: List[constants.Country], defender: bool):
|
||||
@ -678,18 +704,18 @@ class BattleSide:
|
||||
self.points = points
|
||||
self.allies = allies
|
||||
self.deployed = deployed
|
||||
self.defender = defender
|
||||
self.is_defender = defender
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
return self.country.id
|
||||
|
||||
def __repr__(self):
|
||||
side_text = "Defender" if self.defender else "Invader "
|
||||
side_text = "Defender" if self.is_defender else "Invader "
|
||||
return f"<BattleSide: {side_text} {self.country.name}|{self.points:02d}p>"
|
||||
|
||||
def __str__(self):
|
||||
side_text = "Defender" if self.defender else "Invader "
|
||||
side_text = "Defender" if self.is_defender else "Invader "
|
||||
return f"{side_text} {self.country.name} - {self.points:02d} points"
|
||||
|
||||
def __format__(self, format_spec):
|
||||
@ -697,8 +723,8 @@ class BattleSide:
|
||||
|
||||
@property
|
||||
def as_dict(self):
|
||||
return dict(points=self.points, country=self.country, defender=self.defender, allies=self.allies,
|
||||
deployed=self.deployed, battle=repr(self.battle))
|
||||
return dict(points=self.points, country=self.country, is_defender=self.is_defender, allies=self.allies,
|
||||
deployed=self.deployed)
|
||||
|
||||
@property
|
||||
def battle(self):
|
||||
@ -721,7 +747,7 @@ class BattleDivision:
|
||||
@property
|
||||
def as_dict(self):
|
||||
return dict(id=self.id, division=self.div, terrain=(self.terrain, self.terrain_display), wall=self.wall,
|
||||
epic=self.epic, battle=str(self.battle), end=self.div_end)
|
||||
epic=self.epic, end=self.div_end)
|
||||
|
||||
@property
|
||||
def is_air(self):
|
||||
@ -788,7 +814,7 @@ class Battle:
|
||||
def as_dict(self):
|
||||
return dict(id=self.id, war_id=self.war_id, divisions=self.div, zone=self.zone_id, rw=self.is_rw,
|
||||
dict_lib=self.is_dict_lib, start=self.start, sides={'inv': self.invader, 'def': self.defender},
|
||||
region=[self.region_id, self.region_name])
|
||||
region=[self.region_id, self.region_name], link=self.link)
|
||||
|
||||
@property
|
||||
def has_air(self) -> bool:
|
||||
@ -797,6 +823,10 @@ class Battle:
|
||||
return True
|
||||
return not bool(self.zone_id % 4)
|
||||
|
||||
@property
|
||||
def has_started(self) -> bool:
|
||||
return self.start <= utils.now()
|
||||
|
||||
@property
|
||||
def has_ground(self) -> bool:
|
||||
for div in self.div.values():
|
||||
@ -842,7 +872,7 @@ class Battle:
|
||||
if data.get('end'):
|
||||
end = datetime.datetime.fromtimestamp(data.get('end'), tz=constants.erep_tz)
|
||||
else:
|
||||
end = utils.localize_dt(datetime.datetime.max - datetime.timedelta(days=1))
|
||||
end = constants.max_datetime
|
||||
|
||||
battle_div = BattleDivision(self, div_id=data.get('id'), div=data.get('div'), end=end,
|
||||
epic=data.get('epic_type') in [1, 5],
|
||||
@ -920,7 +950,7 @@ class TelegramBot:
|
||||
def as_dict(self):
|
||||
return {'chat_id': self.chat_id, 'api_url': self.api_url, 'player': self.player_name,
|
||||
'last_time': self._last_time, 'next_time': self._next_time, 'queue': self.__queue,
|
||||
'initialized': self.__initialized, 'has_threads': bool(len(self._threads))}
|
||||
'initialized': self.__initialized, 'has_threads': not self._threads}
|
||||
|
||||
def do_init(self, chat_id: int, token: str, player_name: str = ""):
|
||||
self.chat_id = chat_id
|
||||
|
@ -1,10 +1,14 @@
|
||||
import datetime
|
||||
from typing import Dict, Optional, Union
|
||||
|
||||
import pytz
|
||||
|
||||
__all__ = ["erep_tz", "Country", "AIR_RANKS", "COUNTRIES", "FOOD_ENERGY", "GROUND_RANKS", "GROUND_RANK_POINTS", "INDUSTRIES", "TERRAINS"]
|
||||
__all__ = ["erep_tz", 'min_datetime', "max_datetime", "Country", "AIR_RANKS", "COUNTRIES", "FOOD_ENERGY",
|
||||
"GROUND_RANKS", "GROUND_RANK_POINTS", "INDUSTRIES", "TERRAINS"]
|
||||
|
||||
erep_tz = pytz.timezone('US/Pacific')
|
||||
min_datetime = erep_tz.localize(datetime.datetime(2007, 11, 20))
|
||||
max_datetime = erep_tz.localize(datetime.datetime(2281, 9, 4))
|
||||
|
||||
|
||||
class Country:
|
||||
@ -59,7 +63,7 @@ class Industries:
|
||||
__by_id = {1: "Food", 2: "Weapon", 4: "House", 23: "Aircraft",
|
||||
7: "foodRaw", 8: "FRM q2", 9: "FRM q3", 10: "FRM q4", 11: "FRM q5",
|
||||
12: "weaponRaw", 13: "WRM q2", 14: "WRM q3", 15: "WRM q4", 16: "WRM q5",
|
||||
18: "houseRaw", 19: "HRM q2", 20: "HRM q3", 21: "HRM q4", 22: "HRM q5",
|
||||
17: "houseRaw", 18: "houseRaw", 19: "HRM q2", 20: "HRM q3", 21: "HRM q4", 22: "HRM q5",
|
||||
24: "aircraftRaw", 25: "ARM q2", 26: "ARM q3", 27: "ARM q4", 28: "ARM q5"}
|
||||
|
||||
def __getitem__(self, item) -> Optional[Union[int, str]]:
|
||||
|
@ -1,4 +1,3 @@
|
||||
import copy
|
||||
import datetime
|
||||
import inspect
|
||||
import os
|
||||
@ -8,9 +7,10 @@ import textwrap
|
||||
import time
|
||||
import traceback
|
||||
import unicodedata
|
||||
import warnings
|
||||
from decimal import Decimal
|
||||
from pathlib import Path
|
||||
from typing import Any, List, Mapping, Optional, Union, Dict
|
||||
from typing import Any, List, Optional, Union, Dict
|
||||
|
||||
import requests
|
||||
|
||||
@ -27,8 +27,8 @@ __all__ = ['VERSION', 'calculate_hit', 'caught_error', 'date_from_eday', 'eday_f
|
||||
'process_error', 'process_warning', 'send_email', 'silent_sleep', 'slugify', 'write_file',
|
||||
'write_interactive_log', 'write_silent_log']
|
||||
|
||||
if not sys.version_info >= (3, 7):
|
||||
raise AssertionError('This script requires Python version 3.7 and higher\n'
|
||||
if not sys.version_info >= (3, 6):
|
||||
raise AssertionError('This script requires Python version 3.6 and higher\n'
|
||||
'But Your version is v{}.{}.{}'.format(*sys.version_info))
|
||||
|
||||
VERSION: str = __version__
|
||||
@ -43,13 +43,12 @@ def localize_timestamp(timestamp: int) -> datetime.datetime:
|
||||
|
||||
|
||||
def localize_dt(dt: Union[datetime.date, datetime.datetime]) -> datetime.datetime:
|
||||
try:
|
||||
try:
|
||||
return constants.erep_tz.localize(dt)
|
||||
except AttributeError:
|
||||
return constants.erep_tz.localize(datetime.datetime.combine(dt, datetime.time(0, 0, 0)))
|
||||
except ValueError:
|
||||
return dt.astimezone(constants.erep_tz)
|
||||
if isinstance(dt, datetime.datetime):
|
||||
return constants.erep_tz.localize(dt)
|
||||
elif isinstance(dt, datetime.date):
|
||||
return constants.erep_tz.localize(datetime.datetime.combine(dt, datetime.time(0, 0, 0)))
|
||||
else:
|
||||
raise TypeError(f"Argument dt must be and instance of datetime.datetime or datetime.date not {type(dt)}")
|
||||
|
||||
|
||||
def good_timedelta(dt: datetime.datetime, td: datetime.timedelta) -> datetime.datetime:
|
||||
@ -117,10 +116,12 @@ def _write_log(msg, timestamp: bool = True, should_print: bool = False):
|
||||
|
||||
|
||||
def write_interactive_log(*args, **kwargs):
|
||||
kwargs.pop("should_print", None)
|
||||
_write_log(should_print=True, *args, **kwargs)
|
||||
|
||||
|
||||
def write_silent_log(*args, **kwargs):
|
||||
kwargs.pop("should_print", None)
|
||||
_write_log(should_print=False, *args, **kwargs)
|
||||
|
||||
|
||||
@ -279,15 +280,15 @@ def process_error(log_info: str, name: str, exc_info: tuple, citizen=None, commi
|
||||
write_silent_log(log_info)
|
||||
trace = inspect.trace()
|
||||
if trace:
|
||||
trace = trace[-1][0].f_locals
|
||||
if trace.get('__name__') == '__main__':
|
||||
trace = {'commit_id': trace.get('COMMIT_ID'),
|
||||
'interactive': trace.get('INTERACTIVE'),
|
||||
'version': trace.get('__version__'),
|
||||
'config': trace.get('CONFIG')}
|
||||
local_vars = trace[-1][0].f_locals
|
||||
if local_vars.get('__name__') == '__main__':
|
||||
local_vars.update({'commit_id': local_vars.get('COMMIT_ID'),
|
||||
'interactive': local_vars.get('INTERACTIVE'),
|
||||
'version': local_vars.get('__version__'),
|
||||
'config': local_vars.get('CONFIG')})
|
||||
else:
|
||||
trace = dict()
|
||||
send_email(name, content, citizen, local_vars=trace)
|
||||
local_vars = dict()
|
||||
send_email(name, content, citizen, local_vars=local_vars)
|
||||
|
||||
|
||||
def process_warning(log_info: str, name: str, exc_info: tuple, citizen=None, commit_id: str = None):
|
||||
@ -307,10 +308,10 @@ def process_warning(log_info: str, name: str, exc_info: tuple, citizen=None, com
|
||||
|
||||
trace = inspect.trace()
|
||||
if trace:
|
||||
trace = trace[-1][0].f_locals
|
||||
local_vars = trace[-1][0].f_locals
|
||||
else:
|
||||
trace = dict()
|
||||
send_email(name, content, citizen, local_vars=trace)
|
||||
local_vars = dict()
|
||||
send_email(name, content, citizen, local_vars=local_vars)
|
||||
|
||||
|
||||
def slugify(value, allow_unicode=False) -> str:
|
||||
@ -370,9 +371,11 @@ def get_air_hit_dmg_value(citizen_id: int, natural_enemy: bool = False, true_pat
|
||||
return calculate_hit(0, rang, true_patriot, elite, natural_enemy, booster, weapon_power)
|
||||
|
||||
|
||||
def _clear_up_battle_memory(battle):
|
||||
from . import classes
|
||||
battle: classes.Battle
|
||||
del battle.invader._battle, battle.defender._battle
|
||||
for div_id, division in battle.div.items():
|
||||
del division._battle
|
||||
# def _clear_up_battle_memory(battle):
|
||||
# del battle.invader._battle, battle.defender._battle
|
||||
# for div_id, division in battle.div.items():
|
||||
# del division._battle
|
||||
|
||||
|
||||
def deprecation(message):
|
||||
warnings.warn(message, DeprecationWarning, stacklevel=2)
|
||||
|
@ -1,6 +1,6 @@
|
||||
from datetime import timedelta
|
||||
|
||||
from erepublik import Citizen, utils
|
||||
from erepublik import Citizen, utils, constants
|
||||
|
||||
CONFIG = {
|
||||
'email': 'player@email.com',
|
||||
@ -18,7 +18,7 @@ def main():
|
||||
player.set_debug(CONFIG.get('debug', False))
|
||||
player.login()
|
||||
now = player.now.replace(second=0, microsecond=0)
|
||||
dt_max = now.replace(year=9999)
|
||||
dt_max = constants.max_datetime
|
||||
tasks = {
|
||||
'eat': now,
|
||||
}
|
||||
|
@ -1,17 +1,19 @@
|
||||
bump2version==1.0.0
|
||||
coverage==5.2
|
||||
bump2version==1.0.1
|
||||
coverage==5.3
|
||||
edx-sphinx-theme==1.5.0
|
||||
flake8==3.8.3
|
||||
ipython==7.16.1
|
||||
isort==5.0.9
|
||||
pip==20.1.1
|
||||
PyInstaller==3.6
|
||||
flake8==3.8.4
|
||||
ipython>=7.18.1
|
||||
isort==5.6.4
|
||||
pip==20.2.4
|
||||
PyInstaller==4.0
|
||||
pytz==2020.1
|
||||
pytest==5.4.3
|
||||
responses==0.10.15
|
||||
setuptools==49.2.0
|
||||
Sphinx==3.1.2
|
||||
tox==3.16.1
|
||||
pytest==6.1.1
|
||||
responses==0.12.0
|
||||
setuptools==50.3.2
|
||||
Sphinx==3.2.1
|
||||
requests==2.24.0
|
||||
PySocks==1.7.1
|
||||
tox==3.20.1
|
||||
twine==3.2.0
|
||||
watchdog==0.10.3
|
||||
wheel==0.34.2
|
||||
wheel==0.35.1
|
||||
|
@ -1,5 +1,5 @@
|
||||
[bumpversion]
|
||||
current_version = 0.21.2.2
|
||||
current_version = 0.22.1
|
||||
commit = True
|
||||
tag = True
|
||||
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)\.?(?P<dev>\d+)?
|
||||
@ -33,7 +33,6 @@ ignore_missing_imports = False
|
||||
warn_unused_ignores = True
|
||||
warn_redundant_casts = True
|
||||
warn_unused_configs = True
|
||||
plugins = mypy_django_plugin.main
|
||||
|
||||
[isort]
|
||||
multi_line_output = 2
|
||||
|
15
setup.py
15
setup.py
@ -11,11 +11,18 @@ with open('README.rst') as readme_file:
|
||||
with open('HISTORY.rst') as history_file:
|
||||
history = history_file.read()
|
||||
|
||||
requirements = ['pytz==2020.1', 'requests==2.24.0']
|
||||
requirements = [
|
||||
'pytz==2020.1',
|
||||
'requests==2.24.0',
|
||||
'PySocks==1.7.1'
|
||||
]
|
||||
|
||||
setup_requirements = []
|
||||
|
||||
test_requirements = []
|
||||
test_requirements = [
|
||||
"pytest==6.1.0",
|
||||
"responses==0.12.0"
|
||||
]
|
||||
|
||||
setup(
|
||||
author="Eriks Karls",
|
||||
@ -38,11 +45,11 @@ setup(
|
||||
keywords='erepublik',
|
||||
name='eRepublik',
|
||||
packages=find_packages(include=['erepublik']),
|
||||
python_requires='>=3.7, <4',
|
||||
python_requires='>=3.6, <4',
|
||||
setup_requires=setup_requirements,
|
||||
test_suite='tests',
|
||||
tests_require=test_requirements,
|
||||
url='https://github.com/eeriks/erepublik/',
|
||||
version='0.21.2.2',
|
||||
version='0.22.1',
|
||||
zip_safe=False,
|
||||
)
|
||||
|
@ -2,6 +2,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""Tests for `erepublik` package."""
|
||||
from typing import Callable
|
||||
|
||||
from erepublik import Citizen
|
||||
|
||||
@ -65,6 +66,7 @@ class TestErepublik(unittest.TestCase):
|
||||
self.assertEqual(self.citizen.next_reachable_energy, 0)
|
||||
|
||||
def test_should_fight(self):
|
||||
is_wc_close: Callable[[], bool] = lambda: self.citizen.max_time_till_full_ff > self.citizen.time_till_week_change
|
||||
self.citizen.config.fight = False
|
||||
self.assertEqual(self.citizen.should_fight(), (0, "Fighting not allowed!", False))
|
||||
|
||||
@ -73,62 +75,63 @@ class TestErepublik(unittest.TestCase):
|
||||
# Level up
|
||||
self.citizen.energy.limit = 3000
|
||||
self.citizen.details.xp = 24705
|
||||
self.assertEqual(self.citizen.should_fight(), (0, 'Level up', False))
|
||||
if not is_wc_close:
|
||||
self.assertEqual(self.citizen.should_fight(), (0, 'Level up', False))
|
||||
|
||||
self.citizen.energy.recovered = 3000
|
||||
self.citizen.energy.recoverable = 2950
|
||||
self.citizen.energy.interval = 30
|
||||
self.assertEqual(self.citizen.should_fight(), (900, 'Level up', True))
|
||||
self.citizen.my_companies.ff_lockdown = 160
|
||||
self.assertEqual(self.citizen.should_fight(), (900, 'Level up', True))
|
||||
self.citizen.my_companies.ff_lockdown = 0
|
||||
self.citizen.energy.recovered = 3000
|
||||
self.citizen.energy.recoverable = 2950
|
||||
self.citizen.energy.interval = 30
|
||||
self.assertEqual(self.citizen.should_fight(), (900, 'Level up', True))
|
||||
self.citizen.my_companies.ff_lockdown = 160
|
||||
self.assertEqual(self.citizen.should_fight(), (900, 'Level up', True))
|
||||
self.citizen.my_companies.ff_lockdown = 0
|
||||
|
||||
# Level up reachable
|
||||
self.citizen.details.xp = 24400
|
||||
self.assertEqual(self.citizen.should_fight(), (305, 'Fighting for close Levelup. Doing 305 hits', True))
|
||||
self.citizen.my_companies.ff_lockdown = 160
|
||||
self.assertEqual(self.citizen.should_fight(), (305, 'Fighting for close Levelup. Doing 305 hits', True))
|
||||
self.citizen.my_companies.ff_lockdown = 0
|
||||
# Level up reachable
|
||||
self.citizen.details.xp = 24400
|
||||
self.assertEqual(self.citizen.should_fight(), (305, 'Fighting for close Levelup. Doing 305 hits', True))
|
||||
self.citizen.my_companies.ff_lockdown = 160
|
||||
self.assertEqual(self.citizen.should_fight(), (305, 'Fighting for close Levelup. Doing 305 hits', True))
|
||||
self.citizen.my_companies.ff_lockdown = 0
|
||||
|
||||
self.citizen.details.xp = 21000
|
||||
self.assertEqual(self.citizen.should_fight(), (75, 'Obligatory fighting for at least 75pp', True))
|
||||
self.citizen.my_companies.ff_lockdown = 160
|
||||
self.assertEqual(self.citizen.should_fight(), (75, 'Obligatory fighting for at least 75pp', True))
|
||||
self.citizen.my_companies.ff_lockdown = 0
|
||||
self.citizen.details.pp = 80
|
||||
self.citizen.details.xp = 21000
|
||||
self.assertEqual(self.citizen.should_fight(), (75, 'Obligatory fighting for at least 75pp', True))
|
||||
self.citizen.my_companies.ff_lockdown = 160
|
||||
self.assertEqual(self.citizen.should_fight(), (75, 'Obligatory fighting for at least 75pp', True))
|
||||
self.citizen.my_companies.ff_lockdown = 0
|
||||
self.citizen.details.pp = 80
|
||||
|
||||
# All-in (type = all-in and full ff)
|
||||
self.citizen.config.all_in = True
|
||||
self.assertEqual(self.citizen.should_fight(), (595, 'Fighting all-in. Doing 595 hits', False))
|
||||
self.citizen.my_companies.ff_lockdown = 160
|
||||
self.assertEqual(self.citizen.should_fight(), (
|
||||
435, 'Fight count modified (old count: 595 | FF: 595 | WAM ff_lockdown: 160 | New count: 435)', False
|
||||
))
|
||||
self.citizen.my_companies.ff_lockdown = 0
|
||||
# All-in (type = all-in and full ff)
|
||||
self.citizen.config.all_in = True
|
||||
self.assertEqual(self.citizen.should_fight(), (595, 'Fighting all-in. Doing 595 hits', False))
|
||||
self.citizen.my_companies.ff_lockdown = 160
|
||||
self.assertEqual(self.citizen.should_fight(), (
|
||||
435, 'Fight count modified (old count: 595 | FF: 595 | WAM ff_lockdown: 160 | New count: 435)', False
|
||||
))
|
||||
self.citizen.my_companies.ff_lockdown = 0
|
||||
|
||||
self.citizen.config.air = True
|
||||
self.citizen.energy.recoverable = 1000
|
||||
self.assertEqual(self.citizen.should_fight(), (400, 'Fighting all-in in AIR. Doing 400 hits', False))
|
||||
self.citizen.my_companies.ff_lockdown = 160
|
||||
self.assertEqual(self.citizen.should_fight(), (
|
||||
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.config.air = True
|
||||
self.citizen.energy.recoverable = 1000
|
||||
self.assertEqual(self.citizen.should_fight(), (400, 'Fighting all-in in AIR. Doing 400 hits', False))
|
||||
self.citizen.my_companies.ff_lockdown = 160
|
||||
self.assertEqual(self.citizen.should_fight(), (
|
||||
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.config.next_energy = True
|
||||
self.citizen.energy.limit = 5000
|
||||
self.citizen.details.next_pp = [100, 150, 250, 400, 500]
|
||||
self.assertEqual(self.citizen.should_fight(), (320, 'Fighting for +1 energy. Doing 320 hits', False))
|
||||
self.citizen.my_companies.ff_lockdown = 160
|
||||
self.assertEqual(self.citizen.should_fight(), (
|
||||
160, 'Fight count modified (old count: 320 | FF: 400 | WAM ff_lockdown: 160 | New count: 160)', False
|
||||
))
|
||||
self.citizen.my_companies.ff_lockdown = 0
|
||||
self.citizen.energy.limit = 3000
|
||||
self.citizen.details.next_pp = [19250, 20000]
|
||||
self.citizen.config.next_energy = False
|
||||
self.citizen.config.next_energy = True
|
||||
self.citizen.energy.limit = 5000
|
||||
self.citizen.details.next_pp = [100, 150, 250, 400, 500]
|
||||
self.assertEqual(self.citizen.should_fight(), (320, 'Fighting for +1 energy. Doing 320 hits', False))
|
||||
self.citizen.my_companies.ff_lockdown = 160
|
||||
self.assertEqual(self.citizen.should_fight(), (
|
||||
160, 'Fight count modified (old count: 320 | FF: 400 | WAM ff_lockdown: 160 | New count: 160)', False
|
||||
))
|
||||
self.citizen.my_companies.ff_lockdown = 0
|
||||
self.citizen.energy.limit = 3000
|
||||
self.citizen.details.next_pp = [19250, 20000]
|
||||
self.citizen.config.next_energy = False
|
||||
|
||||
# 1h worth of energy
|
||||
self.citizen.energy.recoverable = 2910
|
||||
self.assertEqual(self.citizen.should_fight(), (30, 'Fighting for 1h energy. Doing 30 hits', True))
|
||||
# 1h worth of energy
|
||||
self.citizen.energy.recoverable = 2910
|
||||
self.assertEqual(self.citizen.should_fight(), (30, 'Fighting for 1h energy. Doing 30 hits', True))
|
||||
|
Reference in New Issue
Block a user