Compare commits

...

43 Commits

Author SHA1 Message Date
638373e452 Bump version: 0.22.1.1 → 0.22.1.2 2020-10-27 17:04:40 +02:00
04f357cc70 Bugfix 2020-10-27 17:04:37 +02:00
ed4ffe5af6 Bump version: 0.22.1 → 0.22.1.1 2020-10-22 18:04:13 +03:00
8aa90a7dbf Lint 2020-10-22 18:04:06 +03:00
e798859105 Bump version: 0.22.0 → 0.22.1 2020-10-22 16:27:09 +03:00
241f1642ce Session dump/load, Citizen.inventory update, memory and network optimization, python3.6 support 2020-10-22 16:26:59 +03:00
a4128b5d89 Bump version: 0.21.5.8 → 0.22.0 2020-10-21 14:46:24 +03:00
22c2a0ffd2 New Features!
Dump session to file!
Load session from file!
2020-10-21 14:45:29 +03:00
38f0335354 Bump version: 0.21.5.7 → 0.21.5.8 2020-10-07 09:22:01 +03:00
889435b94e House renewal bugfix 2020-10-07 09:21:36 +03:00
bb16c27674 Bump version: 0.21.5.6 → 0.21.5.7 2020-10-06 12:35:19 +03:00
963d7ca11a bugfix 2020-10-06 12:35:14 +03:00
36c7fefdf7 Bump version: 0.21.5.5 → 0.21.5.6 2020-09-30 08:40:14 +03:00
d9fa30b06e bugfix in default weapon switch 2020-09-30 08:35:35 +03:00
b53dc447f4 switch to deploy 2020-09-30 08:13:36 +03:00
233d8d83f8 Bump version: 0.21.5.4 → 0.21.5.5 2020-09-29 18:02:52 +03:00
ec62d90aa2 wheeloffortune bugfix 2020-09-29 18:02:52 +03:00
0c433a56da Bump version: 0.21.5.3 → 0.21.5.4 2020-09-29 17:38:44 +03:00
ad24338f4d wheeloffortune bugfix 2020-09-29 17:38:26 +03:00
6f4bc65d1b Bump version: 0.21.5.2 → 0.21.5.3 2020-09-29 17:21:00 +03:00
cc09ba7ee7 wheeloffortune argument bugfix 2020-09-29 17:20:53 +03:00
9e1166a460 Bump version: 0.21.5.1 → 0.21.5.2 2020-09-29 17:17:07 +03:00
fb0042c00d wheeloffortune url bugfix 2020-09-29 17:17:00 +03:00
bb800578e7 Bump version: 0.21.5 → 0.21.5.1 2020-09-29 15:06:39 +03:00
7025f750dc PySocks as requirement 2020-09-29 15:06:30 +03:00
bf77f21b60 MyCompanies export as dict optimised 2020-09-29 15:04:51 +03:00
6b7639d7fb Bump version: 0.21.4.8 → 0.21.5 2020-09-29 10:52:36 +03:00
3b1c1928fd Added proxy support 😉 2020-09-29 10:52:14 +03:00
2e26c2db79 Bump version: 0.21.4.7 → 0.21.4.8 2020-09-25 10:10:33 +03:00
78c055fee2 bugfix 2020-09-25 10:10:27 +03:00
fe41c4cdc6 Bump version: 0.21.4.6 → 0.21.4.7 2020-09-23 13:22:38 +03:00
123b6cf4ed Fight reporting unified and moved to Reporter.report_fighting 2020-09-23 13:22:31 +03:00
f652b02443 Fight reporting duplicate 2020-09-23 13:17:46 +03:00
73537e4742 Bump version: 0.21.4.5 → 0.21.4.6 2020-09-23 11:15:32 +03:00
955432e0d2 Check also for maintenance in BaseCitizen._errors_in_response() 2020-09-23 11:15:18 +03:00
1d93864dca Bump version: 0.21.4.4 → 0.21.4.5 2020-09-22 16:30:03 +03:00
c472d688be error logging 2020-09-22 16:29:50 +03:00
bff9a2bec9 Bump version: 0.21.4.3 → 0.21.4.4 2020-09-21 20:40:40 +03:00
973ea40e00 bugfix 2020-09-21 20:40:24 +03:00
52c85fdf28 Bump version: 0.21.4.2 → 0.21.4.3 2020-09-21 20:18:02 +03:00
a889e9efa1 bugfix 2020-09-21 20:17:56 +03:00
a9a0cdc6d5 Bump version: 0.21.4.1 → 0.21.4.2 2020-09-21 12:39:44 +03:00
1c102488b6 Test fix to not run if WC end is near 2020-09-21 12:39:27 +03:00
14 changed files with 547 additions and 415 deletions

1
.gitignore vendored
View File

@ -104,3 +104,4 @@ ENV/
debug/
log/
docs/
*dump.json

View File

@ -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

View File

@ -4,9 +4,9 @@
__author__ = """Eriks Karls"""
__email__ = 'eriks@72.lv'
__version__ = '0.21.4.1'
__version__ = '0.22.1.2'
from erepublik import classes, utils, constants
from erepublik.citizen import Citizen
__all__ = ["classes", "utils", "Citizen", ]
__all__ = ["classes", "utils", "Citizen", 'constants']

View File

@ -38,8 +38,10 @@ class SlowRequests(Session):
]
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({
@ -132,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:
@ -154,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):
@ -334,27 +344,32 @@ 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,
buyAction=1)
else:
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)
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)
class ErepublikLeaderBoardAPI(CitizenBaseAPI):
def _get_main_leaderboards_damage_aircraft_rankings(self, country_id: int, weeks: int = 0, mu_id: int = 0) -> Response:
def _get_main_leaderboards_damage_aircraft_rankings(self, country_id: int, weeks: int = 0, mu_id: int = 0) -> Response: # noqa
return self.get(f"{self.url}/main/leaderboards-damage-aircraft-rankings/{country_id}/{weeks}/{mu_id}/0")
def _get_main_leaderboards_damage_rankings(self, country_id: int, weeks: int = 0, mu_id: int = 0, div: int = 0) -> Response:
def _get_main_leaderboards_damage_rankings(self, country_id: int, weeks: int = 0, mu_id: int = 0, div: int = 0) -> Response: # noqa
return self.get(f"{self.url}/main/leaderboards-damage-rankings/{country_id}/{weeks}/{mu_id}/{div}")
def _get_main_leaderboards_kills_aircraft_rankings(self, country_id: int, weeks: int = 0, mu_id: int = 0) -> Response:
def _get_main_leaderboards_kills_aircraft_rankings(self, country_id: int, weeks: int = 0, mu_id: int = 0) -> Response: # noqa
return self.get(f"{self.url}/main/leaderboards-kills-aircraft-rankings/{country_id}/{weeks}/{mu_id}/0")
def _get_main_leaderboards_kills_rankings(self, country_id: int, weeks: int = 0, mu_id: int = 0, div: int = 0) -> Response:
def _get_main_leaderboards_kills_rankings(self, country_id: int, weeks: int = 0, mu_id: int = 0, div: int = 0) -> Response: # noqa
return self.get(f"{self.url}/main/leaderboards-kills-rankings/{country_id}/{weeks}/{mu_id}/{div}")

View File

@ -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):
@ -837,15 +897,18 @@ class CitizenCompanies(BaseCitizen):
if self.restricted_ip:
return None
self.update_companies()
self.update_inventory()
data = {"action_type": "production"}
extra = {}
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"]
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)
@ -879,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:
@ -911,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)
@ -930,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"]:
@ -959,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: Dict[str, Any] = self._post_economy_activate_house(quality).json()
self._update_inventory_data(r)
if r.get("status") and not r.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()
@ -1009,10 +1081,41 @@ 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.id,
"industry": industry,
@ -1021,14 +1124,14 @@ class CitizenEconomy(CitizenTravel):
"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
@ -1138,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',
@ -1336,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()
@ -1380,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)
@ -1391,51 +1494,6 @@ class CitizenMilitary(CitizenTravel):
f" new influence {influence}", kwargs=r.json())
return influence
# def check_epic_battles(self):
# active_fs = False
# for battle_id in self.sorted_battles(self.config.sort_battles_time):
# battle = self.all_battles.get(battle_id)
# if not battle.is_air:
# my_div: BattleDivision = battle.div.get(self.division)
# if my_div.epic and my_div.end > self.now:
# if self.energy.food_fights > 50:
# inv_allies = battle.invader.deployed + [battle.invader.id]
# def_allies = battle.defender.deployed + [battle.defender.id]
# all_allies = inv_allies + def_allies
# if self.details.current_country not in all_allies:
# if self.details.current_country in battle.invader.allies:
# allies = battle.invader.deployed
# side = battle.invader.id
# else:
# allies = battle.defender.deployed
# side = battle.defender.id
#
# self.travel_to_battle(battle.id, allies)
#
# else:
# if self.details.current_country in inv_allies:
# side = battle.invader.id
# elif self.details.current_country in def_allies:
# side = battle.defender.id
# else:
# self.write_log(
# f"Country {self.details.current_country} not in all allies list ({all_allies}) and "
# f"also not in inv allies ({inv_allies}) nor def allies ({def_allies})")
# break
# error_count = 0
# while self.energy.food_fights > 5 and error_count < 20:
# errors = self.fight(battle_id, side_id=side, count=self.energy.food_fights - 5)
# if errors:
# error_count += errors
# if self.config.epic_hunt_ebs:
# self._eat('orange')
# self.travel_to_residence()
# break
# elif bool(my_div.epic):
# active_fs = True
#
# self.active_fs = active_fs
def sorted_battles(self, sort_by_time: bool = True, only_tp=False) -> List[classes.Battle]:
cs_battles_priority_air: List[classes.Battle] = []
cs_battles_priority_ground: List[classes.Battle] = []
@ -1523,7 +1581,7 @@ class CitizenMilitary(CitizenTravel):
if not division.terrain and is_start_ok and not division.div_end:
if division.is_air and self.config.air:
division_medals = self.get_battle_round_data(division)
medal = division_medals[self.details.citizenship == division.battle.is_defender.country]
medal = division_medals[self.details.citizenship == division.battle.defender.country]
if not medal:
air_divs.append((0, division))
else:
@ -1532,7 +1590,7 @@ class CitizenMilitary(CitizenTravel):
if not division.div == self.division and not self.maverick:
continue
division_medals = self.get_battle_round_data(division)
medal = division_medals[self.details.citizenship == division.battle.is_defender.country]
medal = division_medals[self.details.citizenship == division.battle.defender.country]
if not medal:
ground_divs.append((0, division))
else:
@ -1654,11 +1712,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_id=battle.id, side=side, dmg=total_damage,
air=battle.has_air, hits=total_hits,
round=battle.zone_id))
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):
@ -1678,14 +1736,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)
@ -1807,12 +1868,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
@ -1906,7 +1967,7 @@ class CitizenMilitary(CitizenTravel):
battleZoneId=division.id, type="damage")
r_json = r.json()
return (r_json.get(str(battle.invader.id)).get("fighterData"),
r_json.get(str(battle.is_defender.id)).get("fighterData"))
r_json.get(str(battle.defender.id)).get("fighterData"))
def schedule_attack(self, war_id: int, region_id: int, region_name: str, at_time: datetime):
if at_time:
@ -1990,15 +2051,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)})
@ -2006,17 +2068,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))
@ -2071,20 +2123,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(),
@ -2095,11 +2150,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}\"!")
@ -2172,10 +2227,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()
@ -2195,14 +2249,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()
@ -2244,20 +2298,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():
@ -2278,7 +2338,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):
@ -2348,23 +2407,21 @@ class Citizen(CitizenAnniversary, CitizenCompanies, CitizenEconomy, CitizenLeade
self.debug = bool(debug)
self._req.debug = bool(debug)
def set_pin(self, pin: int):
self.details.pin = int(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()
@ -2406,6 +2463,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):
@ -2425,6 +2483,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
@ -2432,13 +2491,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):
"""
@ -2557,7 +2616,8 @@ class Citizen(CitizenAnniversary, CitizenCompanies, CitizenEconomy, CitizenLeade
for holding in regions.values():
raw_usage = holding.get_wam_raw_usage()
if (raw_usage['frm'] + raw_usage['wrm']) * 100 + self.inventory['used'] > self.inventory['total']:
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)

View File

@ -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, 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,14 +290,18 @@ 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)
@ -297,12 +311,16 @@ class MyCompanies:
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 +456,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):
@ -551,7 +570,7 @@ class Reporter:
self.url = "https://api.erep.lv"
self._req.headers.update({"user-agent": "eRepublik Script Reporter v3",
'erep-version': utils.__version__,
'erep-user-id': self.citizen_id,
'erep-user-id': str(self.citizen_id),
'erep-user-name': self.citizen.name})
self.__to_update = []
self.__registered: bool = False
@ -618,6 +637,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))
@ -834,13 +859,15 @@ class Battle:
self.invader = BattleSide(
self, constants.COUNTRIES[battle.get('inv', {}).get('id')], battle.get('inv', {}).get('points'),
[constants.COUNTRIES[row.get('id')] for row in battle.get('inv', {}).get('ally_list')],
[constants.COUNTRIES[row.get('id')] for row in battle.get('inv', {}).get('ally_list') if row['deployed']], False
[constants.COUNTRIES[row.get('id')] for row in battle.get('inv', {}).get('ally_list') if row['deployed']],
False
)
self.defender = BattleSide(
self, constants.COUNTRIES[battle.get('def', {}).get('id')], battle.get('def', {}).get('points'),
[constants.COUNTRIES[row.get('id')] for row in battle.get('def', {}).get('ally_list')],
[constants.COUNTRIES[row.get('id')] for row in battle.get('def', {}).get('ally_list') if row['deployed']], True
[constants.COUNTRIES[row.get('id')] for row in battle.get('def', {}).get('ally_list') if row['deployed']],
True
)
self.div = {}
@ -849,7 +876,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],
@ -867,7 +894,8 @@ class Battle:
else:
time_part = "-{}".format(self.start - time_now)
return f"Battle {self.id} for {self.region_name[:16]} | {self.invader} : {self.defender} | Round time {time_part}"
return (f"Battle {self.id} for {self.region_name[:16]} | "
f"{self.invader} : {self.defender} | Round time {time_part}")
def __repr__(self):
return f"<Battle #{self.id} {self.invader}:{self.defender} R{self.zone_id}>"

View File

@ -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]]:

View File

@ -7,6 +7,7 @@ import textwrap
import time
import traceback
import unicodedata
import warnings
from decimal import Decimal
from pathlib import Path
from typing import Any, List, Optional, Union, Dict
@ -26,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__
@ -47,7 +48,7 @@ def localize_dt(dt: Union[datetime.date, datetime.datetime]) -> datetime.datetim
elif isinstance(dt, datetime.date):
return constants.erep_tz.localize(datetime.datetime.combine(dt, datetime.time(0, 0, 0)))
else:
return dt.astimezone(constants.erep_tz)
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:
@ -278,14 +279,13 @@ def process_error(log_info: str, name: str, exc_info: tuple, citizen=None, commi
elif interactive is not None:
write_silent_log(log_info)
trace = inspect.trace()
local_vars = None
if trace:
trace_local_vars = trace[-1][0].f_locals
if trace_local_vars.get('__name__') == '__main__':
local_vars = {'commit_id': trace_local_vars.get('COMMIT_ID'),
'interactive': trace_local_vars.get('INTERACTIVE'),
'version': trace_local_vars.get('__version__'),
'config': trace_local_vars.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:
local_vars = dict()
send_email(name, content, citizen, local_vars=local_vars)
@ -371,7 +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):
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)

View File

@ -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,
}

View File

@ -1,18 +1,19 @@
bump2version==1.0.0
bump2version==1.0.1
coverage==5.3
edx-sphinx-theme==1.5.0
flake8==3.8.3
ipython==7.18.1
isort==5.5.3
pip==20.2.3
flake8==3.8.4
ipython>=7.18.1
isort==5.6.4
pip==20.2.4
PyInstaller==4.0
pytz==2020.1
pytest==6.0.2
pytest==6.1.1
responses==0.12.0
setuptools==50.3.0
setuptools==50.3.2
Sphinx==3.2.1
requests==2.24.0
tox==3.20.0
PySocks==1.7.1
tox==3.20.1
twine==3.2.0
watchdog==0.10.3
wheel==0.35.1

View File

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

View File

@ -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.4.1',
version='0.22.1.2',
zip_safe=False,
)

View File

@ -65,6 +65,8 @@ class TestErepublik(unittest.TestCase):
self.assertEqual(self.citizen.next_reachable_energy, 0)
def test_should_fight(self):
def is_wc_close():
return 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))

View File

@ -1,9 +1,10 @@
[tox]
envlist = py37, flake8
envlist = py37, py38, flake8
[travis]
python =
3.7: py37
3.8: py38
[testenv:flake8]
basepython = python
@ -15,4 +16,3 @@ setenv =
PYTHONPATH = {toxinidir}
commands = python setup.py test