Compare commits
89 Commits
Author | SHA1 | Date | |
---|---|---|---|
13b639dc5a | |||
ec1141a46e | |||
77170433c2 | |||
4736f70203 | |||
48a27997ac | |||
90bec82630 | |||
aedfbf4465 | |||
66f459c692 | |||
ef27960ff1 | |||
c48af9a891 | |||
1abfdb71ac | |||
e060f67666 | |||
06d8d1c0b5 | |||
adda8dcb54 | |||
c7f084436d | |||
94a87091a4 | |||
c0b97f112d | |||
3d895bd085 | |||
d548d1bbf1 | |||
b1eefcc662 | |||
41798c446c | |||
074da3adbe | |||
6c9a9e920d | |||
ffa2fc109c | |||
f7f4028f32 | |||
e91705ce90 | |||
ca65a1ffe1 | |||
07c8881092 | |||
25e534f783 | |||
daa071f0f5 | |||
2f8120bd0d | |||
6b2c073abe | |||
c298d66086 | |||
bf971972bf | |||
50f3d291ca | |||
b03140f2b8 | |||
fe9a118875 | |||
17c73c79a7 | |||
7533608316 | |||
71a7f55338 | |||
0ca0f49f92 | |||
3f1b0018b2 | |||
2aaa4aad65 | |||
b44a3a4b62 | |||
3a7dd9a6fa | |||
630c7cbc76 | |||
1ee47dfdcf | |||
ab34135b73 | |||
20bba4b9f9 | |||
8db4ab1f0f | |||
acbf1590d7 | |||
63dd2d4f77 | |||
896b1b2432 | |||
60543e02c8 | |||
b06e9a2933 | |||
4eb96d7f1e | |||
c8a1d8c8e8 | |||
c85f0417f2 | |||
7573f29950 | |||
597d27117c | |||
95570b7c17 | |||
bc4ba671d6 | |||
088219a60a | |||
53266b1c94 | |||
065a0ff3ec | |||
c8e90ca910 | |||
bbab84bf5b | |||
fff17469e0 | |||
0d208a8d32 | |||
86004eb81b | |||
7e05e35ebf | |||
411b158487 | |||
d6e161d815 | |||
1285e95cec | |||
324db2c136 | |||
1c6b41e41b | |||
a52552afb7 | |||
28bfdc7b20 | |||
de1b734728 | |||
fa5646ecfd | |||
339392cfb0 | |||
7ebba458cb | |||
4f436292af | |||
416c391d21 | |||
66c53ef985 | |||
3fa7d097fe | |||
6af9675c39 | |||
2343a6c6c8 | |||
7e56f01a38 |
@ -15,7 +15,7 @@ Types of Contributions
|
||||
Report Bugs
|
||||
~~~~~~~~~~~
|
||||
|
||||
Report bugs at https://github.com/eeriks/erepublik_script/issues.
|
||||
Report bugs at https://github.com/eeriks/erepublik/issues.
|
||||
|
||||
If you are reporting a bug, please include:
|
||||
|
||||
@ -45,7 +45,7 @@ articles, and such.
|
||||
Submit Feedback
|
||||
~~~~~~~~~~~~~~~
|
||||
|
||||
The best way to send feedback is to file an issue at https://github.com/eeriks/erepublik_script/issues.
|
||||
The best way to send feedback is to file an issue at https://github.com/eeriks/erepublik/issues.
|
||||
|
||||
If you are proposing a feature:
|
||||
|
||||
@ -62,7 +62,7 @@ Ready to contribute? Here's how to set up `erepublik` for local development.
|
||||
1. Fork the `erepublik_script` repo on GitHub.
|
||||
2. Clone your fork locally::
|
||||
|
||||
$ git clone git@github.com:your_name_here/erepublik_script.git
|
||||
$ git clone git@github.com:your_name_here/erepublik.git
|
||||
|
||||
3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development::
|
||||
|
||||
|
26
HISTORY.rst
26
HISTORY.rst
@ -3,6 +3,31 @@ History
|
||||
=======
|
||||
|
||||
|
||||
0.17.0 (2019-11-21)
|
||||
-------------------
|
||||
|
||||
* 12th anniversary's endpoints added
|
||||
* Telegram message queue optimisation
|
||||
* WC end fighting energy bugfix
|
||||
* More strict fighting limiting before week change
|
||||
* Improved and fixed ground damage booster usage
|
||||
|
||||
|
||||
0.16.0 (2019-09-29)
|
||||
-------------------
|
||||
|
||||
* Telegram notification integration
|
||||
* Improved serialization to JSON
|
||||
* When failing to do WAM because of not enough food - buy food
|
||||
* Buy food buys 48h worth instead of 24h energy
|
||||
|
||||
|
||||
0.15.3 (2019-08-24)
|
||||
-------------------
|
||||
|
||||
* Update after eRepublik changed campaign apis
|
||||
|
||||
|
||||
0.15.0 (2019-07-30)
|
||||
-------------------
|
||||
|
||||
@ -15,6 +40,7 @@ History
|
||||
|
||||
* Wall post comment endpoints updated with comment create endpoints.
|
||||
|
||||
|
||||
0.1.0 (2019-07-19)
|
||||
------------------
|
||||
|
||||
|
@ -6,8 +6,8 @@ eRepublik script
|
||||
.. image:: https://img.shields.io/pypi/v/erepublik.svg
|
||||
:target: https://pypi.python.org/pypi/erepublik
|
||||
|
||||
.. image:: https://readthedocs.org/projects/erepublik_script/badge/?version=latest
|
||||
:target: https://erepublik_script.readthedocs.io/en/latest/?badge=latest
|
||||
.. image:: https://readthedocs.org/projects/erepublik/badge/?version=latest
|
||||
:target: https://erepublik.readthedocs.io/en/latest/?badge=latest
|
||||
:alt: Documentation Status
|
||||
|
||||
|
||||
@ -15,7 +15,7 @@ Python package for automated eRepublik playing
|
||||
|
||||
|
||||
* Free software: MIT license
|
||||
* Documentation: https://erepublik.readthedocs.io.
|
||||
* Documentation: https://erepublik.readthedocs.io/en/latest/
|
||||
|
||||
|
||||
Features
|
||||
|
@ -33,4 +33,4 @@
|
||||
"travel_to_fight": true,
|
||||
"wam": true,
|
||||
"work": true
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ import sys
|
||||
sys.path.insert(0, os.path.abspath('..'))
|
||||
|
||||
import erepublik
|
||||
import edx_theme
|
||||
|
||||
# -- General configuration ---------------------------------------------
|
||||
|
||||
@ -32,7 +33,7 @@ import erepublik
|
||||
|
||||
# Add any Sphinx extension module names here, as strings. They can be
|
||||
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
|
||||
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode']
|
||||
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode', 'edx_theme']
|
||||
|
||||
# Add any paths that contain templates here, relative to this directory.
|
||||
templates_path = ['_templates']
|
||||
@ -84,7 +85,8 @@ todo_include_todos = False
|
||||
# The theme to use for HTML and HTML Help pages. See the documentation for
|
||||
# a list of builtin themes.
|
||||
#
|
||||
html_theme = 'alabaster'
|
||||
html_theme = 'edx_theme'
|
||||
html_theme_path = [edx_theme.get_html_theme_path()]
|
||||
|
||||
# Theme options are theme-specific and customize the look and feel of a
|
||||
# theme further. For a list of options available for each theme, see the
|
||||
@ -158,6 +160,3 @@ texinfo_documents = [
|
||||
'One line description of project.',
|
||||
'Miscellaneous'),
|
||||
]
|
||||
|
||||
|
||||
|
||||
|
@ -32,13 +32,13 @@ You can either clone the public repository:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ git clone git://github.com/eeriks/erepublik_script
|
||||
$ git clone git://github.com/eeriks/erepublik
|
||||
|
||||
Or download the `tarball`_:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ curl -OL https://github.com/eeriks/erepublik_script/tarball/master
|
||||
$ curl -OL https://github.com/eeriks/erepublik/tarball/master
|
||||
|
||||
Once you have a copy of the source, you can install it with:
|
||||
|
||||
@ -47,5 +47,5 @@ Once you have a copy of the source, you can install it with:
|
||||
$ python setup.py install
|
||||
|
||||
|
||||
.. _Github repo: https://github.com/eeriks/erepublik_script
|
||||
.. _tarball: https://github.com/eeriks/erepublik_script/tarball/master
|
||||
.. _Github repo: https://github.com/eeriks/erepublik
|
||||
.. _tarball: https://github.com/eeriks/erepublik/tarball/master
|
||||
|
@ -1,36 +1,36 @@
|
||||
@ECHO OFF
|
||||
|
||||
pushd %~dp0
|
||||
|
||||
REM Command file for Sphinx documentation
|
||||
|
||||
if "%SPHINXBUILD%" == "" (
|
||||
set SPHINXBUILD=python -msphinx
|
||||
)
|
||||
set SOURCEDIR=.
|
||||
set BUILDDIR=_build
|
||||
set SPHINXPROJ=erepublik_script
|
||||
|
||||
if "%1" == "" goto help
|
||||
|
||||
%SPHINXBUILD% >NUL 2>NUL
|
||||
if errorlevel 9009 (
|
||||
echo.
|
||||
echo.The Sphinx module was not found. Make sure you have Sphinx installed,
|
||||
echo.then set the SPHINXBUILD environment variable to point to the full
|
||||
echo.path of the 'sphinx-build' executable. Alternatively you may add the
|
||||
echo.Sphinx directory to PATH.
|
||||
echo.
|
||||
echo.If you don't have Sphinx installed, grab it from
|
||||
echo.http://sphinx-doc.org/
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
|
||||
goto end
|
||||
|
||||
:help
|
||||
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
|
||||
|
||||
:end
|
||||
popd
|
||||
@ECHO OFF
|
||||
|
||||
pushd %~dp0
|
||||
|
||||
REM Command file for Sphinx documentation
|
||||
|
||||
if "%SPHINXBUILD%" == "" (
|
||||
set SPHINXBUILD=python -msphinx
|
||||
)
|
||||
set SOURCEDIR=.
|
||||
set BUILDDIR=_build
|
||||
set SPHINXPROJ=erepublik
|
||||
|
||||
if "%1" == "" goto help
|
||||
|
||||
%SPHINXBUILD% >NUL 2>NUL
|
||||
if errorlevel 9009 (
|
||||
echo.
|
||||
echo.The Sphinx module was not found. Make sure you have Sphinx installed,
|
||||
echo.then set the SPHINXBUILD environment variable to point to the full
|
||||
echo.path of the 'sphinx-build' executable. Alternatively you may add the
|
||||
echo.Sphinx directory to PATH.
|
||||
echo.
|
||||
echo.If you don't have Sphinx installed, grab it from
|
||||
echo.http://sphinx-doc.org/
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
|
||||
goto end
|
||||
|
||||
:help
|
||||
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
|
||||
|
||||
:end
|
||||
popd
|
||||
|
@ -4,4 +4,7 @@ Usage
|
||||
|
||||
To use eRepublik script in a project::
|
||||
|
||||
import erepublik
|
||||
from erepublik import Citizen
|
||||
player = Citizen('email@domain.com', 'password')
|
||||
player.update_all()
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
__author__ = """Eriks Karls"""
|
||||
__email__ = 'eriks@72.lv'
|
||||
__version__ = '0.15.2'
|
||||
__version__ = '0.17.1'
|
||||
|
||||
from erepublik import classes, utils
|
||||
from erepublik.citizen import Citizen
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -2,12 +2,13 @@ import datetime
|
||||
import decimal
|
||||
import hashlib
|
||||
import random
|
||||
import threading
|
||||
import time
|
||||
from collections import deque
|
||||
from json import JSONDecodeError, loads, JSONEncoder
|
||||
from typing import Any, Dict, List, Union, Mapping, Iterable
|
||||
from typing import Any, Dict, List, Union, Mapping, Iterable, Tuple
|
||||
|
||||
from requests import Response, Session
|
||||
from requests import Response, Session, post
|
||||
|
||||
from erepublik import utils
|
||||
|
||||
@ -17,7 +18,7 @@ class ErepublikException(Exception):
|
||||
super().__init__(message)
|
||||
|
||||
|
||||
class ErepublikNetworkException(Exception):
|
||||
class ErepublikNetworkException(ErepublikException):
|
||||
def __init__(self, message, request):
|
||||
super().__init__(message)
|
||||
self.request = request
|
||||
@ -61,7 +62,7 @@ class MyCompanies:
|
||||
production=0, base_production=0, wam_enabled=False, can_work_as_manager=False,
|
||||
preset_own_work=0, already_worked=False, can_assign_employees=False, preset_works=0,
|
||||
todays_works=0, holding_company_id=None, is_assigned_to_holding=False,
|
||||
cannot_work_as_manager_reason=False)
|
||||
cannot_work_as_manager_reason=False, industry_id=0)
|
||||
|
||||
for c_id, company in companies.items():
|
||||
tmp = {}
|
||||
@ -119,7 +120,10 @@ class MyCompanies:
|
||||
raw = []
|
||||
factory = []
|
||||
if holding_id in self.holdings:
|
||||
for company_id in self.holdings.get(holding_id, {}).get('companies', []):
|
||||
for company_id in sorted(self.holdings.get(holding_id, {}).get('companies', []),
|
||||
key=lambda cid: (-self.companies[cid].get('is_raw'), # True, False
|
||||
self.companies[cid].get('industry_id'), # F W H A
|
||||
-self.companies[cid].get('quality'),)): # 7, 6, .. 2, 1
|
||||
company = self.companies.get(company_id, {})
|
||||
wam_enabled = bool(company.get('wam_enabled', {}))
|
||||
already_worked = not company.get('already_worked', {})
|
||||
@ -156,28 +160,33 @@ class MyCompanies:
|
||||
|
||||
raise ErepublikException("Wrong function call")
|
||||
|
||||
# @property
|
||||
# def __dict__(self):
|
||||
# ret = {}
|
||||
# for key in dir(self):
|
||||
# if not key.startswith('_'):
|
||||
# ret[key] = getattr(self, key)
|
||||
# return ret
|
||||
|
||||
|
||||
class SlowRequests(Session):
|
||||
last_time: datetime.datetime
|
||||
timeout = datetime.timedelta(milliseconds=500)
|
||||
uas = [
|
||||
# Chrome
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
|
||||
'Chrome/73.0.3683.103 Safari/537.36',
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
|
||||
'Chrome/72.0.3626.13 Safari/537.36',
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
|
||||
'Chrome/71.0.3578.98 Safari/537.36',
|
||||
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36',
|
||||
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.11 Safari/537.36',
|
||||
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36',
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36',
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36',
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.80 Safari/537.36',
|
||||
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36',
|
||||
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36',
|
||||
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.80 Safari/537.36',
|
||||
# FireFox
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0',
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0',
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:64.0) Gecko/20100101 Firefox/64.0',
|
||||
'Mozilla/5.0 (X11; Linux x86_64; rv:66.0) Gecko/20100101 Firefox/66.0',
|
||||
'Mozilla/5.0 (X11; Linux x86_64; rv:65.0) Gecko/20100101 Firefox/65.0',
|
||||
'Mozilla/5.0 (X11; Linux x86_64; rv:64.0) Gecko/20100101 Firefox/64.0',
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0',
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0',
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:67.0) Gecko/20100101 Firefox/67.0',
|
||||
'Mozilla/5.0 (X11; Linux x86_64; rv:69.0) Gecko/20100101 Firefox/69.0',
|
||||
'Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0',
|
||||
'Mozilla/5.0 (X11; Linux x86_64; rv:67.0) Gecko/20100101 Firefox/67.0',
|
||||
]
|
||||
debug = False
|
||||
|
||||
@ -192,7 +201,7 @@ class SlowRequests(Session):
|
||||
@property
|
||||
def __dict__(self):
|
||||
return dict(last_time=self.last_time, timeout=self.timeout, user_agent=self.headers['User-Agent'],
|
||||
request_log_name=self.request_log_name)
|
||||
request_log_name=self.request_log_name, debug=self.debug)
|
||||
|
||||
def request(self, method, url, *args, **kwargs):
|
||||
self._slow_down_requests()
|
||||
@ -211,7 +220,10 @@ class SlowRequests(Session):
|
||||
def _log_request(self, url, method, data=None, json=None, params=None, **kwargs):
|
||||
if self.debug:
|
||||
args = {}
|
||||
args.update({'kwargs': kwargs})
|
||||
kwargs.pop('allow_redirects', None)
|
||||
if kwargs:
|
||||
args.update({'kwargs': kwargs})
|
||||
|
||||
if data:
|
||||
args.update({"data": data})
|
||||
|
||||
@ -235,10 +247,9 @@ class SlowRequests(Session):
|
||||
self._log_request(hist_resp.request.url, "REDIRECT")
|
||||
self._log_response(hist_resp.request.url, hist_resp, redirect=True)
|
||||
|
||||
# TODO: Must thoroughly check response writing on windows systems
|
||||
file_data = {
|
||||
"path": 'debug/requests',
|
||||
"time": self.last_time.strftime('%Y-%m-%d_%H-%M-%S'),
|
||||
"time": self.last_time.strftime('%Y/%m/%d/%H-%M-%S'),
|
||||
"name": utils.slugify(url[len(Citizen.url):]),
|
||||
"extra": "_REDIRECT" if redirect else ""
|
||||
}
|
||||
@ -280,38 +291,41 @@ class Config:
|
||||
force_wam = False
|
||||
sort_battles_time = True
|
||||
force_travel = False
|
||||
telegram = True
|
||||
telegram_chat_id = 0
|
||||
telegram_token = ""
|
||||
|
||||
@property
|
||||
def wt(self):
|
||||
return self.work and self.train
|
||||
|
||||
def __dict__(self) -> Dict[str, Union[bool, str, List[str]]]:
|
||||
return dict(
|
||||
email=self.email,
|
||||
password=self.password,
|
||||
work=self.work,
|
||||
train=self.train,
|
||||
wam=self.wam,
|
||||
auto_sell=self.auto_sell,
|
||||
auto_sell_all=self.auto_sell_all,
|
||||
employees=self.employees,
|
||||
fight=self.fight,
|
||||
air=self.air,
|
||||
ground=self.ground,
|
||||
all_in=self.all_in,
|
||||
next_energy=self.next_energy,
|
||||
boosters=self.boosters,
|
||||
travel_to_fight=self.travel_to_fight,
|
||||
epic_hunt=self.epic_hunt,
|
||||
epic_hunt_ebs=self.epic_hunt_ebs,
|
||||
rw_def_side=self.rw_def_side,
|
||||
interactive=self.interactive,
|
||||
continuous_fighting=self.continuous_fighting,
|
||||
auto_buy_raw=self.auto_buy_raw,
|
||||
force_wam=self.force_wam,
|
||||
sort_battles_time=self.sort_battles_time,
|
||||
force_travel=self.force_travel,
|
||||
)
|
||||
def reset(self):
|
||||
self.work = True
|
||||
self.train = True
|
||||
self.wam = False
|
||||
self.auto_sell = list()
|
||||
self.auto_sell_all = False
|
||||
self.employees = False
|
||||
self.fight = False
|
||||
self.air = False
|
||||
self.ground = False
|
||||
self.all_in = False
|
||||
self.next_energy = False
|
||||
self.boosters = False
|
||||
self.travel_to_fight = False
|
||||
self.always_travel = False
|
||||
self.epic_hunt = False
|
||||
self.epic_hunt_ebs = False
|
||||
self.rw_def_side = False
|
||||
self.interactive = True
|
||||
self.continuous_fighting = False
|
||||
self.auto_buy_raw = False
|
||||
self.force_wam = False
|
||||
self.sort_battles_time = True
|
||||
self.force_travel = False
|
||||
self.telegram = True
|
||||
self.telegram_chat_id = 0
|
||||
self.telegram_token = ""
|
||||
|
||||
|
||||
class Energy:
|
||||
@ -332,7 +346,7 @@ class Energy:
|
||||
|
||||
@property
|
||||
def food_fights(self):
|
||||
return (self.recoverable + self.recovered) // 10
|
||||
return self.available // 10
|
||||
|
||||
@property
|
||||
def reference_time(self):
|
||||
@ -344,7 +358,7 @@ class Energy:
|
||||
|
||||
@property
|
||||
def is_recoverable_full(self):
|
||||
return self.recoverable >= self.limit - self.interval
|
||||
return self.recoverable >= self.limit - 5 * self.interval
|
||||
|
||||
@property
|
||||
def is_recovered_full(self):
|
||||
@ -358,18 +372,8 @@ class Energy:
|
||||
def available(self):
|
||||
return self.recovered + self.recoverable
|
||||
|
||||
@property
|
||||
def __dict__(self):
|
||||
return dict(
|
||||
limit=self.limit,
|
||||
interval=self.interval,
|
||||
recoverable=self.recoverable,
|
||||
recovered=self.recovered,
|
||||
reference_time=self.reference_time
|
||||
)
|
||||
|
||||
|
||||
class Details(object):
|
||||
class Details:
|
||||
xp = 0
|
||||
cc = 0
|
||||
pp = 0
|
||||
@ -423,7 +427,7 @@ class Politics:
|
||||
is_country_president: bool = False
|
||||
|
||||
|
||||
class House(object):
|
||||
class House:
|
||||
quality = None
|
||||
unactivated_count = 0
|
||||
active_untill = utils.good_timedelta(utils.now(), -datetime.timedelta(days=1))
|
||||
@ -454,25 +458,25 @@ Class for unifying eRepublik known endpoints and their required/optional paramet
|
||||
def get(self, url: str, **kwargs) -> Response:
|
||||
return self._req.get(url, **kwargs)
|
||||
|
||||
def _get_article_json(self, article_id: int) -> Response:
|
||||
def _get_main_article_json(self, article_id: int) -> Response:
|
||||
return self.get("{}/main/articleJson/{}".format(self.url, article_id))
|
||||
|
||||
def _get_battlefield_choose_side(self, battle: int, side: int) -> Response:
|
||||
def _get_military_battlefield_choose_side(self, battle: int, side: int) -> Response:
|
||||
return self.get("{}/military/battlefield-choose-side/{}/{}".format(self.url, battle, side))
|
||||
|
||||
def _get_candidate_party(self, party_slug: str) -> Response:
|
||||
return self.post("{}/candidate/{}".format(self.url, party_slug))
|
||||
|
||||
def _get_citizen_hovercard(self, citizen: int) -> Response:
|
||||
def _get_main_citizen_hovercard(self, citizen: int) -> Response:
|
||||
return self.get("{}/main/citizen-hovercard/{}".format(self.url, citizen))
|
||||
|
||||
def _get_citizen_profile(self, player_id: int) -> Response:
|
||||
def _get_main_citizen_profile_json(self, player_id: int) -> Response:
|
||||
return self.get("{}/main/citizen-profile-json/{}".format(self.url, player_id))
|
||||
|
||||
def _get_citizen_daily_assistant(self) -> Response:
|
||||
def _get_main_citizen_daily_assistant(self) -> Response:
|
||||
return self.get("{}/main/citizenDailyAssistant".format(self.url))
|
||||
|
||||
def _get_city_data_residents(self, city: int, page: int = 1, params: Mapping[str, Any] = None) -> Response:
|
||||
def _get_main_city_data_residents(self, city: int, page: int = 1, params: Mapping[str, Any] = None) -> Response:
|
||||
if params is None:
|
||||
params = {}
|
||||
return self.get("{}/main/city-data/{}/residents".format(self.url, city), params={"currentPage": page, **params})
|
||||
@ -480,6 +484,9 @@ Class for unifying eRepublik known endpoints and their required/optional paramet
|
||||
def _get_country_military(self, country: str) -> Response:
|
||||
return self.get("{}/country/military/{}".format(self.url, country))
|
||||
|
||||
def _get_economy_citizen_accounts(self, organisation_id: int) -> Response:
|
||||
return self.get("{}/economy/citizen-accounts/{}".format(self.url, organisation_id))
|
||||
|
||||
def _get_economy_inventory_items(self) -> Response:
|
||||
return self.get("{}/economy/inventory-items/".format(self.url))
|
||||
|
||||
@ -492,96 +499,95 @@ Class for unifying eRepublik known endpoints and their required/optional paramet
|
||||
def _get_economy_my_market_offers(self) -> Response:
|
||||
return self.get("{}/economy/myMarketOffers".format(self.url))
|
||||
|
||||
def _get_job_data(self) -> Response:
|
||||
def _get_main_job_data(self) -> Response:
|
||||
return self.get("{}/main/job-data".format(self.url))
|
||||
|
||||
def _get_leaderboards_damage_aircraft_rankings(self, country: int, weeks: int = 0, mu: int = 0) -> Response:
|
||||
def _get_main_leaderboards_damage_aircraft_rankings(self, country: int, weeks: int = 0, mu: int = 0) -> Response:
|
||||
data = (country, weeks, mu)
|
||||
return self.get("{}/main/leaderboards-damage-aircraft-rankings/{}/{}/{}/0".format(self.url, *data))
|
||||
|
||||
def _get_leaderboards_damage_rankings(self, country: int, weeks: int = 0, mu: int = 0, div: int = 0) -> Response:
|
||||
def _get_main_leaderboards_damage_rankings(self, country: int, weeks: int = 0, mu: int = 0,
|
||||
div: int = 0) -> Response:
|
||||
data = (country, weeks, mu, div)
|
||||
return self.get("{}/main/leaderboards-damage-rankings/{}/{}/{}/{}".format(self.url, *data))
|
||||
|
||||
def _get_leaderboards_kills_aircraft_rankings(self, country: int, weeks: int = 0, mu: int = 0) -> Response:
|
||||
def _get_main_leaderboards_kills_aircraft_rankings(self, country: int, weeks: int = 0, mu: int = 0) -> Response:
|
||||
data = (country, weeks, mu)
|
||||
return self.get("{}/main/leaderboards-kills-aircraft-rankings/{}/{}/{}/0".format(self.url, *data))
|
||||
|
||||
def _get_leaderboards_kills_rankings(self, country: int, weeks: int = 0, mu: int = 0, div: int = 0) -> Response:
|
||||
def _get_main_leaderboards_kills_rankings(self, country: int, weeks: int = 0, mu: int = 0,
|
||||
div: int = 0) -> Response:
|
||||
data = (country, weeks, mu, div)
|
||||
return self.get("{}/main/leaderboards-kills-rankings/{}/{}/{}/{}".format(self.url, *data))
|
||||
|
||||
def _get_main(self) -> Response:
|
||||
return self.get(self.url)
|
||||
|
||||
def _get_messages(self, page: int = 1) -> Response:
|
||||
def _get_main_messages_paginated(self, page: int = 1) -> Response:
|
||||
return self.get("{}/main/messages-paginated/{}".format(self.url, page))
|
||||
|
||||
def _get_military_campaigns(self) -> Response:
|
||||
return self.get("{}/military/campaigns-new/".format(self.url))
|
||||
|
||||
def _get_military_show_weapons(self, battle_id: int) -> Response:
|
||||
params = {"_token": self.token, "battleId": battle_id}
|
||||
return self.get("{}/military/show-weapons".format(self.url), params=params)
|
||||
|
||||
def _get_military_unit_data(self, unit_id: int, **kwargs) -> Response:
|
||||
params = {"groupId": unit_id, "panel": "members", **kwargs}
|
||||
return self.get("{}/military/military-unit-data/".format(self.url), params=params)
|
||||
|
||||
def _get_money_donation_accept(self, donation_id: int) -> Response:
|
||||
def _get_main_money_donation_accept(self, donation_id: int) -> Response:
|
||||
return self.get("{}/main/money-donation/accept/{}".format(self.url, donation_id), params={"_token": self.token})
|
||||
|
||||
def _get_money_donation_reject(self, donation_id: int) -> Response:
|
||||
def _get_main_money_donation_reject(self, donation_id: int) -> Response:
|
||||
return self.get("{}/main/money-donation/reject/{}".format(self.url, donation_id), params={"_token": self.token})
|
||||
|
||||
def _get_notifications_ajax_community(self, page: int = 1) -> Response:
|
||||
def _get_main_notifications_ajax_community(self, page: int = 1) -> Response:
|
||||
return self.get("{}/main/notificationsAjax/community/{}".format(self.url, page))
|
||||
|
||||
def _get_notifications_ajax_system(self, page: int = 1) -> Response:
|
||||
def _get_main_notifications_ajax_system(self, page: int = 1) -> Response:
|
||||
return self.get("{}/main/notificationsAjax/system/{}".format(self.url, page))
|
||||
|
||||
def _get_notifications_ajax_report(self, page: int = 1) -> Response:
|
||||
def _get_main_notifications_ajax_report(self, page: int = 1) -> Response:
|
||||
return self.get("{}/main/notificationsAjax/report/{}".format(self.url, page))
|
||||
|
||||
def _get_party_members(self, party: int) -> Response:
|
||||
def _get_main_party_members(self, party: int) -> Response:
|
||||
return self.get("{}/main/party-members/{}".format(self.url, party))
|
||||
|
||||
def _get_rankings_parties(self, country: int) -> Response:
|
||||
def _get_main_rankings_parties(self, country: int) -> Response:
|
||||
return self.get("{}/main/rankings-parties/1/{}".format(self.url, country))
|
||||
|
||||
def _get_training_grounds_json(self) -> Response:
|
||||
def _get_main_training_grounds_json(self) -> Response:
|
||||
return self.get("{}/main/training-grounds-json".format(self.url))
|
||||
|
||||
def _get_weekly_challenge_data(self) -> Response:
|
||||
def _get_main_weekly_challenge_data(self) -> Response:
|
||||
return self.get("{}/main/weekly-challenge-data".format(self.url))
|
||||
|
||||
def _get_wars_show(self, war_id: int) -> Response:
|
||||
return self.get("{}/wars/show/{}".format(self.url, war_id))
|
||||
|
||||
def _post_activate_battle_effect(self, battle: int, kind: str, citizen_id: int) -> Response:
|
||||
def _post_main_activate_battle_effect(self, battle: int, kind: str, citizen_id: int) -> Response:
|
||||
data = dict(battleId=battle, citizenId=citizen_id, type=kind, _token=self.token)
|
||||
return self.post("{}/main/fight-activateBattleEffect".format(self.url), data=data)
|
||||
|
||||
def _post_article_comments(self, article: int, page: int = 1) -> Response:
|
||||
def _post_main_article_comments(self, article: int, page: int = 1) -> Response:
|
||||
data = dict(_token=self.token, articleId=article, page=page)
|
||||
if page:
|
||||
data.update({'page': page})
|
||||
return self.post("{}/main/articleComments".format(self.url), data=data)
|
||||
|
||||
def _post_article_comments_create(self, message: str, article: int, parent: int = 0) -> Response:
|
||||
def _post_main_article_comments_create(self, message: str, article: int, parent: int = 0) -> Response:
|
||||
data = dict(_token=self.token, message=message, articleId=article)
|
||||
if parent:
|
||||
data.update({"parentId": parent})
|
||||
return self.post("{}/main/articleComments/create".format(self.url), data=data)
|
||||
|
||||
def _post_battle_console(self, battle: int, zone: int, round_id: int, division: int, page: int,
|
||||
damage: bool) -> Response:
|
||||
data = dict(battleId=battle, zoneId=zone, action="battleStatistics", round=round_id, division=division,
|
||||
leftPage=page, rightPage=page, _token=self.token)
|
||||
if damage:
|
||||
data.update({"type": "damage"})
|
||||
else:
|
||||
data.update({"type": "kills"})
|
||||
def _post_main_battlefield_travel(self, side_id: int, battle_id: int) -> Response:
|
||||
data = dict(_token=self.token, sideCountryId=side_id, battleId=battle_id)
|
||||
return self.post("{}/main/battlefieldTravel".format(self.url), data=data)
|
||||
|
||||
return self.post("{}/military/battle-console".format(self.url), data=data)
|
||||
|
||||
def _post_buy_gold_items(self, currency: str, item: str, amount: int) -> Response:
|
||||
def _post_main_buy_gold_items(self, currency: str, item: str, amount: int) -> Response:
|
||||
data = dict(itemId=item, currency=currency, amount=amount, _token=self.token)
|
||||
return self.post("{}/main/buyGoldItems".format(self.url), data=data)
|
||||
|
||||
@ -589,7 +595,7 @@ Class for unifying eRepublik known endpoints and their required/optional paramet
|
||||
data = dict(_token=self.token, presentation=presentation)
|
||||
return self.post("{}/candidate-for-congress".format(self.url), data=data)
|
||||
|
||||
def _post_citizen_add_remove_friend(self, citizen: int, add: bool) -> Response:
|
||||
def _post_main_citizen_add_remove_friend(self, citizen: int, add: bool) -> Response:
|
||||
data = dict(_token=self.token, citizenId=citizen, url="//www.erepublik.com/en/main/citizen-addRemoveFriend")
|
||||
if add:
|
||||
data.update({"action": "addFriend"})
|
||||
@ -597,18 +603,22 @@ Class for unifying eRepublik known endpoints and their required/optional paramet
|
||||
data.update({"action": "removeFriend"})
|
||||
return self.post("{}/main/citizen-addRemoveFriend".format(self.url), data=data)
|
||||
|
||||
def _post_collect_anniversary_reward(self) -> Response:
|
||||
def _post_main_collect_anniversary_reward(self) -> Response:
|
||||
return self.post("{}/main/collect-anniversary-reward".format(self.url), data={"_token": self.token})
|
||||
|
||||
def _post_country_donate(self, country: int, action: str, value: Union[int, float],
|
||||
quality: int = None) -> Response:
|
||||
def _post_main_country_donate(self, country: int, action: str, value: Union[int, float],
|
||||
quality: int = None) -> Response:
|
||||
json = dict(countryId=country, action=action, _token=self.token, value=value, quality=quality)
|
||||
return self.post("{}/main/country-donate".format(self.url), data=json,
|
||||
headers={"Referer": "{}/country/economy/Latvia".format(self.url)})
|
||||
|
||||
def _post_daily_task_reward(self) -> Response:
|
||||
def _post_main_daily_task_reward(self) -> Response:
|
||||
return self.post("{}/main/daily-tasks-reward".format(self.url), data=dict(_token=self.token))
|
||||
|
||||
def _post_main_donate_article(self, article_id: int, amount: int) -> Response:
|
||||
data = dict(_token=self.token, articleId=article_id, amount=amount)
|
||||
return self.post("{}/main/donate-article".format(self.url), data=data)
|
||||
|
||||
def _post_delete_message(self, msg_id: list) -> Response:
|
||||
data = {"_token": self.token, "delete_message[]": msg_id}
|
||||
return self.post("{}/main/messages-delete".format(self.url), data)
|
||||
@ -617,6 +627,10 @@ Class for unifying eRepublik known endpoints and their required/optional paramet
|
||||
data = dict(_token=self.token, buttonColor=color)
|
||||
return self.post("{}/main/eat".format(self.url), params=data)
|
||||
|
||||
def _post_economy_activate_booster(self, quality: int, duration: int, kind: str) -> Response:
|
||||
data = dict(type=kind, quality=quality, duration=duration, fromInventory=True)
|
||||
return self.post("{}/economy/activateBooster".format(self.url), data=data)
|
||||
|
||||
def _post_economy_activate_house(self, quality: int) -> Response:
|
||||
data = {"action": "activate", "quality": quality, "type": "house", "_token": self.token}
|
||||
return self.post("{}/economy/activateHouse".format(self.url), data=data)
|
||||
@ -650,6 +664,11 @@ Class for unifying eRepublik known endpoints and their required/optional paramet
|
||||
data = dict(_token=self.token, personalOffers=int(personal), page=page, currencyId=currency)
|
||||
return self.post("{}/economy/exchange/retrieve/".format(self.url), data=data)
|
||||
|
||||
def _post_economy_game_tokens_market(self, action: str) -> Response:
|
||||
assert action in ['retrieve', ]
|
||||
data = dict(_token=self.token, action=action)
|
||||
return self.post("{}/economy/gameTokensMarketAjax".format(self.url), data=data)
|
||||
|
||||
def _post_economy_job_market_apply(self, citizen: int, salary: int) -> Response:
|
||||
data = dict(_token=self.token, citizenId=citizen, salary=salary)
|
||||
return self.post("{}/economy/job-market-apply".format(self.url), data=data)
|
||||
@ -675,18 +694,18 @@ Class for unifying eRepublik known endpoints and their required/optional paramet
|
||||
data={"_token": self.token, "action_type": "resign"})
|
||||
|
||||
def _post_economy_sell_company(self, factory: int, pin: int = None, sell: bool = True) -> Response:
|
||||
url = "{}/economy/sell-company/{}".format(self.url, factory)
|
||||
data = dict(_token=self.token, pin="" if pin is None else pin)
|
||||
if sell:
|
||||
data.update({"sell": "sell"})
|
||||
else:
|
||||
data.update({"dissolve": factory})
|
||||
return self.post(url, data=data, headers={"Referer": url})
|
||||
return self.post("{}/economy/sell-company/{}".format(self.url, factory),
|
||||
data=data, headers={"Referer": self.url})
|
||||
|
||||
def _post_economy_train(self, tg_ids: List[int]) -> Response:
|
||||
data: Dict[str, Union[int, str]] = {}
|
||||
if not tg_ids:
|
||||
return self._get_training_grounds_json()
|
||||
return self._get_main_training_grounds_json()
|
||||
else:
|
||||
for idx, tg_id in enumerate(tg_ids):
|
||||
data["grounds[%i][id]" % idx] = tg_id
|
||||
@ -734,7 +753,7 @@ Class for unifying eRepublik known endpoints and their required/optional paramet
|
||||
data = dict(_token=self.token, email=email, commit="Reset password")
|
||||
return self.post("{}/forgot-password".format(self.url), data=data)
|
||||
|
||||
def _post_fight_activate_booster(self, battle: int, quality: int, duration: int, kind: str) -> Response:
|
||||
def _post_military_fight_activate_booster(self, battle: int, quality: int, duration: int, kind: str) -> Response:
|
||||
data = dict(type=kind, quality=quality, duration=duration, battleId=battle, _token=self.token)
|
||||
return self.post("{}/military/fight-activateBooster".format(self.url), data=data)
|
||||
|
||||
@ -742,25 +761,30 @@ Class for unifying eRepublik known endpoints and their required/optional paramet
|
||||
data = dict(csrf_token=self.token, citizen_email=email, citizen_password=password, remember='on')
|
||||
return self.post("{}/login".format(self.url), data=data)
|
||||
|
||||
def _post_messages_alert(self, notification_ids: List[int]) -> Response:
|
||||
def _post_main_messages_alert(self, notification_ids: List[int]) -> Response:
|
||||
data = {"_token": self.token, "delete_alerts[]": notification_ids, "deleteAllAlerts": "1", "delete": "Delete"}
|
||||
return self.post("{}/main/messages-alerts/1".format(self.url), data=data)
|
||||
|
||||
def _post_messages_compose(self, subject: str, body: str, citizens: List[int]) -> Response:
|
||||
def _post_main_messages_compose(self, subject: str, body: str, citizens: List[int]) -> Response:
|
||||
url_pk = 0 if len(citizens) > 1 else str(citizens[0])
|
||||
data = dict(citizen_name=",".join([str(x) for x in citizens]),
|
||||
citizen_subject=subject, _token=self.token, citizen_message=body)
|
||||
return self.post("{}/main/messages-compose/{}}".format(self.url, url_pk), data=data)
|
||||
return self.post("{}/main/messages-compose/{}".format(self.url, url_pk), data=data)
|
||||
|
||||
def _post_military_battle_console(self, battle_id: int, action: str, page: int = 1, **kwargs) -> Response:
|
||||
data = dict(battleId=battle_id, action=action, _token=self.token)
|
||||
if action == "battleStatistics":
|
||||
data.update(round=kwargs["round_id"], zoneId=kwargs["round_id"], leftPage=page, rightPage=page,
|
||||
division=kwargs["division"], type=kwargs.get("type", 'damage'),)
|
||||
division=kwargs["division"], type=kwargs.get("type", 'damage'), )
|
||||
elif action == "warList":
|
||||
data.update(page=page)
|
||||
return self.post("{}/military/battle-console".format(self.url), data=data)
|
||||
|
||||
def _post_military_change_weapon(self, battle_id: int, battle_zone_id: int, customization_level: int) -> Response:
|
||||
data = dict(_token=self.token, battleZoneId=battle_zone_id, battleId=battle_id,
|
||||
customizationLevel=customization_level)
|
||||
return self.post("{}/military/change-weapon".format(self.url), data=data)
|
||||
|
||||
def _post_military_deploy_bomb(self, battle_id: int, bomb_id: int) -> Response:
|
||||
data = dict(battleId=battle_id, bombId=bomb_id, _token=self.token)
|
||||
return self.post("{}/military/deploy-bomb".format(self.url), data=data)
|
||||
@ -777,22 +801,26 @@ Class for unifying eRepublik known endpoints and their required/optional paramet
|
||||
data = dict(action="check", _token=self.token)
|
||||
return self.post("{}/military/group-missions".format(self.url), data=data)
|
||||
|
||||
def _post_travel(self, check: str, **kwargs) -> Response:
|
||||
def _post_main_travel(self, check: str, **kwargs) -> Response:
|
||||
data = dict(_token=self.token, check=check, **kwargs)
|
||||
return self.post("{}/main/travel".format(self.url), data=data)
|
||||
|
||||
def _post_travel_data(self, **kwargs) -> Response:
|
||||
def _post_main_vote_article(self, article_id: int) -> Response:
|
||||
data = dict(_token=self.token, articleId=article_id)
|
||||
return self.post("{}/main/vote-article".format(self.url), data=data)
|
||||
|
||||
def _post_main_travel_data(self, **kwargs) -> Response:
|
||||
return self.post("{}/main/travelData".format(self.url), data=dict(_token=self.token, **kwargs))
|
||||
|
||||
def _post_wars_attack_region(self, war_id: int, region_id: int, region_name: str) -> Response:
|
||||
data = {'_token': self.token, 'warId': war_id, 'regionName': region_name, 'regionNameConfirm': region_name}
|
||||
return self.post('{}/wars/attack-region/{}/{}'.format(self.url, war_id, region_id), data=data)
|
||||
|
||||
def _post_weekly_challenge_reward(self, reward_id: int) -> Response:
|
||||
def _post_main_weekly_challenge_reward(self, reward_id: int) -> Response:
|
||||
data = dict(_token=self.token, rewardId=reward_id)
|
||||
return self.post("{}/main/weekly-challenge-collect-reward".format(self.url), data=data)
|
||||
|
||||
def _post_write_article(self, title: str, content: str, location: int, kind: int) -> Response:
|
||||
def _post_main_write_article(self, title: str, content: str, location: int, kind: int) -> Response:
|
||||
data = dict(_token=self.token, article_name=title, article_body=content, article_location=location,
|
||||
article_category=kind)
|
||||
return self.post("{}/main/write-article".format(self.url), data=data)
|
||||
@ -800,76 +828,92 @@ Class for unifying eRepublik known endpoints and their required/optional paramet
|
||||
# Wall Posts
|
||||
# ## Country
|
||||
|
||||
def _post_country_comment_retrieve(self, post_id: int) -> Response:
|
||||
def _post_main_country_comment_retrieve(self, post_id: int) -> Response:
|
||||
data = {"_token": self.token, "postId": post_id}
|
||||
return self.post("{}/main/country-comment/retrieve/json".format(self.url), data=data)
|
||||
|
||||
def _post_country_comment_create(self, post_id: int, comment_message: str) -> Response:
|
||||
def _post_main_country_comment_create(self, post_id: int, comment_message: str) -> Response:
|
||||
data = {"_token": self.token, "postId": post_id, 'comment_message': comment_message}
|
||||
return self.post("{}/main/country-comment/create/json".format(self.url), data=data)
|
||||
|
||||
def _post_country_post_create(self, body: str, post_as: int) -> Response:
|
||||
def _post_main_country_post_create(self, body: str, post_as: int) -> Response:
|
||||
data = {"_token": self.token, "post_message": body, "post_as": post_as}
|
||||
return self.post("{}/main/country-post/create/json".format(self.url), data=data)
|
||||
|
||||
def _post_country_post_retrieve(self) -> Response:
|
||||
def _post_main_country_post_retrieve(self) -> Response:
|
||||
data = {"_token": self.token, "page": 1, "switchedFrom": False}
|
||||
return self.post("{}/main/country-post/retrieve/json".format(self.url), data=data)
|
||||
|
||||
# ## Military Unit
|
||||
|
||||
def _post_military_unit_comment_retrieve(self, post_id: int) -> Response:
|
||||
def _post_main_military_unit_comment_retrieve(self, post_id: int) -> Response:
|
||||
data = {"_token": self.token, "postId": post_id}
|
||||
return self.post("{}/main/military-unit-comment/retrieve/json".format(self.url), data=data)
|
||||
|
||||
def _post_military_unit_comment_create(self, post_id: int, comment_message: str) -> Response:
|
||||
def _post_main_military_unit_comment_create(self, post_id: int, comment_message: str) -> Response:
|
||||
data = {"_token": self.token, "postId": post_id, 'comment_message': comment_message}
|
||||
return self.post("{}/main/military-unit-comment/create/json".format(self.url), data=data)
|
||||
|
||||
def _post_military_unit_post_create(self, body: str, post_as: int) -> Response:
|
||||
def _post_main_military_unit_post_create(self, body: str, post_as: int) -> Response:
|
||||
data = {"_token": self.token, "post_message": body, "post_as": post_as}
|
||||
return self.post("{}/main/military-unit-post/create/json".format(self.url), data=data)
|
||||
|
||||
def _post_military_unit_post_retrieve(self) -> Response:
|
||||
def _post_main_military_unit_post_retrieve(self) -> Response:
|
||||
data = {"_token": self.token, "page": 1, "switchedFrom": False}
|
||||
return self.post("{}/main/military-unit-post/retrieve/json".format(self.url), data=data)
|
||||
|
||||
# ## Party
|
||||
|
||||
def _post_party_comment_retrieve(self, post_id: int) -> Response:
|
||||
def _post_main_party_comment_retrieve(self, post_id: int) -> Response:
|
||||
data = {"_token": self.token, "postId": post_id}
|
||||
return self.post("{}/main/party-comment/retrieve/json".format(self.url), data=data)
|
||||
|
||||
def _post_party_comment_create(self, post_id: int, comment_message: str) -> Response:
|
||||
def _post_main_party_comment_create(self, post_id: int, comment_message: str) -> Response:
|
||||
data = {"_token": self.token, "postId": post_id, 'comment_message': comment_message}
|
||||
return self.post("{}/main/party-comment/create/json".format(self.url), data=data)
|
||||
|
||||
def _post_party_post_create(self, body: str) -> Response:
|
||||
def _post_main_party_post_create(self, body: str) -> Response:
|
||||
data = {"_token": self.token, "post_message": body}
|
||||
return self.post("{}/main/party-post/create/json".format(self.url), data=data)
|
||||
|
||||
def _post_party_post_retrieve(self) -> Response:
|
||||
def _post_main_party_post_retrieve(self) -> Response:
|
||||
data = {"_token": self.token, "page": 1, "switchedFrom": False}
|
||||
return self.post("{}/main/party-post/retrieve/json".format(self.url), data=data)
|
||||
|
||||
# ## Friend's Wall
|
||||
|
||||
def _post_wall_comment_retrieve(self, post_id: int) -> Response:
|
||||
def _post_main_wall_comment_retrieve(self, post_id: int) -> Response:
|
||||
data = {"_token": self.token, "postId": post_id}
|
||||
return self.post("{}/main/wall-comment/retrieve/json".format(self.url), data=data)
|
||||
|
||||
def _post_wall_comment_create(self, post_id: int, comment_message: str) -> Response:
|
||||
def _post_main_wall_comment_create(self, post_id: int, comment_message: str) -> Response:
|
||||
data = {"_token": self.token, "postId": post_id, 'comment_message': comment_message}
|
||||
return self.post("{}/main/wall-comment/create/json".format(self.url), data=data)
|
||||
|
||||
def _post_wall_post_create(self, body: str) -> Response:
|
||||
def _post_main_wall_post_create(self, body: str) -> Response:
|
||||
data = {"_token": self.token, "post_message": body}
|
||||
return self.post("{}/main/wall-post/create/json".format(self.url), data=data)
|
||||
|
||||
def _post_wall_post_retrieve(self) -> Response:
|
||||
def _post_main_wall_post_retrieve(self) -> Response:
|
||||
data = {"_token": self.token, "page": 1, "switchedFrom": False}
|
||||
return self.post("{}/main/wall-post/retrieve/json".format(self.url), data=data)
|
||||
|
||||
# 12th anniversary endpoints
|
||||
def _get_anniversary_quest_data(self) -> Response:
|
||||
return self.get("{}/main/anniversaryQuestData".format(self.url))
|
||||
|
||||
def _post_map_rewards_unlock(self, node_id: int) -> Response:
|
||||
data = {'nodeId': node_id, '_token': self.token}
|
||||
return self.post("{}/main/map-rewards-unlock".format(self.url), data=data)
|
||||
|
||||
def _post_map_rewards_speedup(self, node_id: int, currency_amount: int) -> Response:
|
||||
data = {'nodeId': node_id, '_token': self.token, "currencyCost": currency_amount}
|
||||
return self.post("{}/main/map-rewards-speedup".format(self.url), data=data)
|
||||
|
||||
def _post_map_rewards_claim(self, node_id: int) -> Response:
|
||||
data = {'nodeId': node_id, '_token': self.token}
|
||||
return self.post("{}/main/map-rewards-claim".format(self.url), data=data)
|
||||
|
||||
|
||||
class Reporter:
|
||||
__to_update: List[Dict[Any, Any]] = []
|
||||
@ -879,16 +923,17 @@ class Reporter:
|
||||
key: str = ""
|
||||
allowed: bool = False
|
||||
|
||||
@property
|
||||
def __dict__(self):
|
||||
return dict(name=self.name, email=self.email, citizen_id=self.citizen_id, key=self.key, allowed=self.allowed,
|
||||
queue=self.__to_update)
|
||||
|
||||
def __init__(self):
|
||||
self._req = Session()
|
||||
self.url = "https://api.erep.lv"
|
||||
self._req.headers.update({"user-agent": "Bot reporter v2"})
|
||||
self.__registered: bool = False
|
||||
|
||||
@property
|
||||
def __dict__(self):
|
||||
return dict(allowed=self.allowed, __to_update=self.__to_update)
|
||||
|
||||
def do_init(self, name: str = "", email: str = "", citizen_id: int = 0):
|
||||
self.name: str = name
|
||||
self.email: str = email
|
||||
@ -950,11 +995,12 @@ class Reporter:
|
||||
|
||||
class MyJSONEncoder(JSONEncoder):
|
||||
def default(self, o):
|
||||
from erepublik.citizen import Citizen
|
||||
if isinstance(o, decimal.Decimal):
|
||||
return float("{:.02f}".format(o))
|
||||
elif isinstance(o, datetime.datetime):
|
||||
return dict(__type__='datetime', year=o.year, month=o.month, day=o.day, hour=o.hour, minute=o.minute,
|
||||
second=o.second, microsecond=o.microsecond)
|
||||
second=o.second, microsecond=o.microsecond, tzinfo=o.tzinfo.zone if o.tzinfo else None)
|
||||
elif isinstance(o, datetime.date):
|
||||
return dict(__type__='date', year=o.year, month=o.month, day=o.day)
|
||||
elif isinstance(o, datetime.timedelta):
|
||||
@ -964,8 +1010,10 @@ class MyJSONEncoder(JSONEncoder):
|
||||
return dict(headers=o.headers.__dict__, url=o.url, text=o.text)
|
||||
elif hasattr(o, '__dict__'):
|
||||
return o.__dict__
|
||||
elif isinstance(o, deque):
|
||||
elif isinstance(o, (deque, set)):
|
||||
return list(o)
|
||||
elif isinstance(o, Citizen):
|
||||
return o.to_json()
|
||||
return super().default(o)
|
||||
|
||||
|
||||
@ -999,7 +1047,7 @@ class BattleDivision:
|
||||
self.wall = dict({"for": wall_for, "dom": wall_dom})
|
||||
|
||||
|
||||
class Battle(object):
|
||||
class Battle:
|
||||
id: int = 0
|
||||
war_id: int = 0
|
||||
zone_id: int = 0
|
||||
@ -1033,11 +1081,11 @@ class Battle(object):
|
||||
|
||||
self.div = {}
|
||||
for div, data in battle.get('div', {}).items():
|
||||
div = int(div)
|
||||
div = int(data.get('div'))
|
||||
if data.get('end'):
|
||||
end = datetime.datetime.fromtimestamp(data.get('end'), tz=utils.erep_tz)
|
||||
else:
|
||||
end = datetime.datetime.max
|
||||
end = utils.localize_dt(datetime.datetime.max - datetime.timedelta(days=1))
|
||||
|
||||
battle_div = BattleDivision(
|
||||
end=end, epic=data.get('epic_type') in [1, 5],
|
||||
@ -1054,9 +1102,10 @@ class Battle(object):
|
||||
time_part = "{}".format(now - self.start)
|
||||
else:
|
||||
time_part = "- {}".format(self.start - now)
|
||||
return "Battle {} | {:>21.21}:{:<21.21} | Round {:2} | Start {}".format(
|
||||
self.id, utils.COUNTRIES[self.invader.id], utils.COUNTRIES[self.defender.id], self.zone_id, time_part
|
||||
)
|
||||
return f"Battle {self.id} | " \
|
||||
f"{utils.COUNTRIES[self.invader.id]:>21.21}:{utils.COUNTRIES[self.defender.id]:<21.21} | " \
|
||||
f"Round {self.zone_id:2} | " \
|
||||
f"Time since start {time_part}"
|
||||
|
||||
|
||||
class EnergyToFight:
|
||||
@ -1088,3 +1137,89 @@ class EnergyToFight:
|
||||
if 0 < new_energy < self.energy:
|
||||
self.energy = new_energy
|
||||
return self.energy
|
||||
|
||||
|
||||
class TelegramBot:
|
||||
__initialized = False
|
||||
__queue: List[str] = []
|
||||
chat_id = 0
|
||||
api_url = ""
|
||||
player_name = ""
|
||||
__thread_stopper: threading.Event = None
|
||||
_last_time: datetime.datetime = None
|
||||
_last_full_energy_report: datetime.datetime = None
|
||||
_next_time: datetime.datetime = None
|
||||
_threads: List[threading.Thread] = []
|
||||
|
||||
def __init__(self, stop_event: threading.Event = None):
|
||||
self.__thread_stopper = threading.Event() if stop_event is None else stop_event
|
||||
|
||||
def __dict__(self):
|
||||
return dict(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)))
|
||||
|
||||
def do_init(self, chat_id: int, token: str, player_name: str = ""):
|
||||
self.chat_id = chat_id
|
||||
self.api_url = "https://api.telegram.org/bot{}/sendMessage".format(token)
|
||||
self.player_name = player_name
|
||||
self.__initialized = True
|
||||
self._last_time = utils.good_timedelta(utils.now(), datetime.timedelta(minutes=-5))
|
||||
self._last_full_energy_report = utils.good_timedelta(utils.now(), datetime.timedelta(minutes=-30))
|
||||
if self.__queue:
|
||||
self.send_message("\n\n––––––––––––––––––––––\n\n".join(self.__queue))
|
||||
|
||||
def send_message(self, message: str) -> bool:
|
||||
self.__queue.append(message)
|
||||
if not self.__initialized:
|
||||
return True
|
||||
self._threads = [t for t in self._threads if t.is_alive()]
|
||||
self._next_time = utils.good_timedelta(utils.now(), datetime.timedelta(minutes=1))
|
||||
if not self._threads:
|
||||
name = "telegram_{}send".format(f"{self.player_name}_" if self.player_name else "")
|
||||
send_thread = threading.Thread(target=self.__send_messages, name=name)
|
||||
send_thread.start()
|
||||
self._threads.append(send_thread)
|
||||
|
||||
return True
|
||||
|
||||
def report_free_bhs(self, battles: List[Tuple[int, int, int, int, datetime.timedelta]]):
|
||||
battle_links = []
|
||||
for battle_id, side_id, against_id, damage, time_left in battles:
|
||||
total_seconds = int(time_left.total_seconds())
|
||||
time_start = ""
|
||||
hours, remainder = divmod(total_seconds, 3600)
|
||||
if hours:
|
||||
time_start = f"{hours}h "
|
||||
minutes, seconds = divmod(remainder, 60)
|
||||
time_start += f"{minutes:02}m {seconds:02}s"
|
||||
damage = "{:,}".format(damage).replace(',', ' ')
|
||||
battle_links.append(f"*{damage}*dmg bh for [{utils.COUNTRIES[side_id]} vs {utils.COUNTRIES[against_id]}]"
|
||||
f"(https://www.erepublik.com/en/military/battlefield/{battle_id}) "
|
||||
f"_time since start {time_start}_")
|
||||
self.send_message("Free BHs:\n" + "\n".join(battle_links))
|
||||
|
||||
def report_full_energy(self, available: int, limit: int, interval: int):
|
||||
if (utils.now() - self._last_full_energy_report).total_seconds() >= 30 * 60:
|
||||
self._last_full_energy_report = utils.now()
|
||||
message = f"Full energy ({available}hp/{limit}hp +{interval}hp/6min)"
|
||||
self.send_message(message)
|
||||
|
||||
def report_medal(self, msg):
|
||||
self.send_message(f"New award: *{msg}*")
|
||||
|
||||
def __send_messages(self):
|
||||
while self._next_time > utils.now():
|
||||
if self.__thread_stopper.is_set():
|
||||
break
|
||||
self.__thread_stopper.wait(utils.get_sleep_seconds(self._next_time))
|
||||
|
||||
message = "\n\n––––––––––––––––––––––\n\n".join(self.__queue)
|
||||
if self.player_name:
|
||||
message = f"Player *{self.player_name}*\n" + message
|
||||
response = post(self.api_url, json=dict(chat_id=self.chat_id, text=message, parse_mode="Markdown"))
|
||||
self._last_time = utils.now()
|
||||
if response.json().get('ok'):
|
||||
self.__queue = []
|
||||
return True
|
||||
return False
|
||||
|
@ -7,22 +7,17 @@ import sys
|
||||
import time
|
||||
import traceback
|
||||
import unicodedata
|
||||
from collections import deque
|
||||
from decimal import Decimal
|
||||
from json import JSONEncoder
|
||||
from pathlib import Path
|
||||
from typing import Union, Any, List, NoReturn, Mapping
|
||||
|
||||
import pytz
|
||||
import requests
|
||||
from requests import Response
|
||||
|
||||
__all__ = ["FOOD_ENERGY", "COMMIT_ID", "COUNTRIES", "erep_tz",
|
||||
__all__ = ["FOOD_ENERGY", "COMMIT_ID", "COUNTRIES", "erep_tz", 'COUNTRY_LINK',
|
||||
"now", "localize_dt", "localize_timestamp", "good_timedelta", "eday_from_date", "date_from_eday",
|
||||
"get_sleep_seconds", "interactive_sleep", "silent_sleep",
|
||||
"write_silent_log", "write_interactive_log", "get_file", "write_file",
|
||||
"send_email", "normalize_html_json", "process_error", ]
|
||||
|
||||
"send_email", "normalize_html_json", "process_error", 'report_promo', 'calculate_hit']
|
||||
|
||||
FOOD_ENERGY = dict(q1=2, q2=4, q3=6, q4=8, q5=10, q6=12, q7=20)
|
||||
COMMIT_ID = "7b92e19"
|
||||
@ -86,7 +81,8 @@ COUNTRIES = {1: 'Romania', 9: 'Brazil', 10: 'Italy', 11: 'France', 12: 'Germany'
|
||||
|
||||
COUNTRY_LINK = {1: 'Romania', 9: 'Brazil', 11: 'France', 12: 'Germany', 13: 'Hungary', 82: 'Cyprus', 168: 'Georgia',
|
||||
15: 'Spain', 23: 'Canada', 26: 'Mexico', 27: 'Argentina', 28: 'Venezuela', 80: 'Montenegro', 24: 'USA',
|
||||
29: 'United-Kingdom', 50: 'Australia', 47: 'South-Korea',171: 'Cuba', 79: 'Republic-of-Macedonia-FYROM',
|
||||
29: 'United-Kingdom', 50: 'Australia', 47: 'South-Korea', 171: 'Cuba',
|
||||
79: 'Republic-of-Macedonia-FYROM',
|
||||
30: 'Switzerland', 31: 'Netherlands', 32: 'Belgium', 33: 'Austria', 34: 'Czech-Republic', 35: 'Poland',
|
||||
36: 'Slovakia', 37: 'Norway', 38: 'Sweden', 39: 'Finland', 40: 'Ukraine', 41: 'Russia', 42: 'Bulgaria',
|
||||
43: 'Turkey', 44: 'Greece', 45: 'Japan', 48: 'India', 49: 'Indonesia', 78: 'Colombia', 68: 'Singapore',
|
||||
@ -98,27 +94,6 @@ COUNTRY_LINK = {1: 'Romania', 9: 'Brazil', 11: 'France', 12: 'Germany', 13: 'Hun
|
||||
169: 'Armenia', 83: 'Belarus', 84: 'New-Zealand', 164: 'Saudi-Arabia', 170: 'Nigeria', }
|
||||
|
||||
|
||||
class MyJSONEncoder(JSONEncoder):
|
||||
def default(self, o):
|
||||
if isinstance(o, Decimal):
|
||||
return float("{:.02f}".format(o))
|
||||
elif isinstance(o, datetime.datetime):
|
||||
return dict(__type__='datetime', year=o.year, month=o.month, day=o.day, hour=o.hour, minute=o.minute,
|
||||
second=o.second, microsecond=o.microsecond)
|
||||
elif isinstance(o, datetime.date):
|
||||
return dict(__type__='date', year=o.year, month=o.month, day=o.day)
|
||||
elif isinstance(o, datetime.timedelta):
|
||||
return dict(__type__='timedelta', days=o.days, seconds=o.seconds,
|
||||
microseconds=o.microseconds, total_seconds=o.total_seconds())
|
||||
elif isinstance(o, Response):
|
||||
return dict(headers=o.headers.__dict__, url=o.url, text=o.text)
|
||||
elif hasattr(o, '__dict__'):
|
||||
return o.__dict__
|
||||
elif isinstance(o, deque):
|
||||
return list(o)
|
||||
return super().default(o)
|
||||
|
||||
|
||||
def now() -> datetime.datetime:
|
||||
return datetime.datetime.now(erep_tz).replace(microsecond=0)
|
||||
|
||||
@ -296,6 +271,7 @@ def send_email(name: str, content: List[Any], player=None, local_vars: Mapping[A
|
||||
if local_vars:
|
||||
if "state_thread" in local_vars:
|
||||
local_vars.pop('state_thread', None)
|
||||
from erepublik.classes import MyJSONEncoder
|
||||
files.append(('file', ("local_vars.json", json.dumps(local_vars, indent=2,
|
||||
cls=MyJSONEncoder, sort_keys=True), "application/json")))
|
||||
if isinstance(player, Citizen):
|
||||
@ -354,5 +330,45 @@ def slugify(value, allow_unicode=False) -> str:
|
||||
value = unicodedata.normalize('NFKC', value)
|
||||
else:
|
||||
value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode('ascii')
|
||||
value = re.sub(r'[^\w\s-]', '', value).strip().lower()
|
||||
value = re.sub(r'[^\w\s-]', '_', value).strip().lower()
|
||||
return re.sub(r'[-\s]+', '-', value)
|
||||
|
||||
|
||||
def calculate_hit(strength: float, rang: int, tp: bool, elite: bool, ne: bool, booster: int = 0,
|
||||
weapon: int = 200) -> float:
|
||||
base_dmg = 10 * (1 + strength / 400) * (1 + rang / 5) * (1 + weapon / 100)
|
||||
dmg = int(base_dmg * 10 + 5) // 10
|
||||
|
||||
booster_multiplier = (100 + booster) / 100
|
||||
booster_dmg = dmg * booster_multiplier
|
||||
dmg = int(booster_dmg * 10 + 5) // 10
|
||||
|
||||
elite = 1.1 if elite else 1
|
||||
elite_dmg = dmg * elite
|
||||
dmg = int(elite_dmg)
|
||||
|
||||
legend = 1 if (not tp or rang < 70) else 1 + (rang - 69) / 10
|
||||
legend_dmg = dmg * legend
|
||||
dmg = int(legend_dmg)
|
||||
|
||||
return dmg * (1.1 if ne else 1)
|
||||
|
||||
|
||||
def ground_hit_dmg_value(citizen_id: int, natural_enemy: bool = False, true_patriot: bool = False,
|
||||
booster: int = 0, weapon_power: int = 200) -> float:
|
||||
r = requests.get(f"https://www.erepublik.com/en/main/citizen-profile-json/{citizen_id}").json()
|
||||
rang = r['military']['militaryData']['ground']['rankNumber']
|
||||
strength = r['military']['militaryData']['ground']['strength']
|
||||
elite = r['citizenAttributes']['level'] > 100
|
||||
if natural_enemy:
|
||||
true_patriot = True
|
||||
|
||||
return calculate_hit(strength, rang, true_patriot, elite, natural_enemy, booster, weapon_power)
|
||||
|
||||
|
||||
def air_hit_dmg_value(citizen_id: int, natural_enemy: bool = False, true_patriot: bool = False, booster: int = 0,
|
||||
weapon_power: int = 0) -> float:
|
||||
r = requests.get(f"https://www.erepublik.com/en/main/citizen-profile-json/{citizen_id}").json()
|
||||
rang = r['military']['militaryData']['aircraft']['rankNumber']
|
||||
elite = r['citizenAttributes']['level'] > 100
|
||||
return calculate_hit(0, rang, true_patriot, elite, natural_enemy, booster, weapon_power)
|
||||
|
@ -5,11 +5,10 @@ watchdog==0.9.0
|
||||
flake8==3.7.8
|
||||
tox==3.13.2
|
||||
coverage==4.5.3
|
||||
Sphinx==2.1.2
|
||||
twine==1.13.0
|
||||
ipython==7.6.1
|
||||
PyInstaller==3.5
|
||||
Sphinx==2.2.0
|
||||
twine==2.0.0
|
||||
ipython
|
||||
PyInstaller
|
||||
pytz==2019.1
|
||||
requests==2.22.0
|
||||
pycryptodome==3.8.2
|
||||
python-slugify==2.0.1
|
||||
edx-sphinx-theme
|
||||
|
@ -1,5 +1,5 @@
|
||||
[bumpversion]
|
||||
current_version = 0.15.2
|
||||
current_version = 0.17.1
|
||||
commit = True
|
||||
tag = True
|
||||
|
||||
|
10
setup.py
10
setup.py
@ -11,11 +11,11 @@ with open('README.rst') as readme_file:
|
||||
with open('HISTORY.rst') as history_file:
|
||||
history = history_file.read()
|
||||
|
||||
requirements = ['pytz==2019.1', 'requests==2.22.0']
|
||||
requirements = ['pytz>=2019.2', 'requests>=2.22']
|
||||
|
||||
setup_requirements = [ ]
|
||||
setup_requirements = []
|
||||
|
||||
test_requirements = [ ]
|
||||
test_requirements = []
|
||||
|
||||
setup(
|
||||
author="Eriks Karls",
|
||||
@ -41,7 +41,7 @@ setup(
|
||||
setup_requires=setup_requirements,
|
||||
test_suite='tests',
|
||||
tests_require=test_requirements,
|
||||
url='https://github.com/eeriks/erepublik_script',
|
||||
version='0.15.2',
|
||||
url='https://github.com/eeriks/erepublik/',
|
||||
version='0.17.1',
|
||||
zip_safe=False,
|
||||
)
|
||||
|
@ -5,30 +5,126 @@
|
||||
|
||||
|
||||
import unittest
|
||||
from click.testing import CliRunner
|
||||
|
||||
from erepublik import Citizen
|
||||
from erepublik import cli
|
||||
|
||||
|
||||
class TestErepublik_script(unittest.TestCase):
|
||||
class TestErepublik(unittest.TestCase):
|
||||
"""Tests for `erepublik` package."""
|
||||
|
||||
def setUp(self):
|
||||
"""Set up test fixtures, if any."""
|
||||
self.citizen = Citizen("email", "password", False)
|
||||
self.citizen.config.interactive = False
|
||||
|
||||
def tearDown(self):
|
||||
"""Tear down test fixtures, if any."""
|
||||
def test_should_do_levelup(self):
|
||||
self.citizen.energy.recovered = 1900
|
||||
self.citizen.energy.recoverable = 2940
|
||||
self.citizen.energy.interval = 30
|
||||
self.citizen.energy.limit = 3000
|
||||
self.citizen.details.xp = 14850
|
||||
self.assertTrue(self.citizen.should_do_levelup)
|
||||
|
||||
def test_000_something(self):
|
||||
"""Test something."""
|
||||
self.citizen.energy.recoverable = 1000
|
||||
self.assertFalse(self.citizen.should_do_levelup)
|
||||
|
||||
def test_should_travel_to_fight(self):
|
||||
self.citizen.config.always_travel = True
|
||||
self.assertTrue(self.citizen.should_travel_to_fight())
|
||||
self.citizen.config.always_travel = False
|
||||
self.assertFalse(self.citizen.should_travel_to_fight())
|
||||
|
||||
self.citizen.energy.recovered = 1900
|
||||
self.citizen.energy.recoverable = 2940
|
||||
self.citizen.energy.interval = 30
|
||||
self.citizen.energy.limit = 3000
|
||||
self.citizen.details.xp = 14850
|
||||
self.assertTrue(self.citizen.should_travel_to_fight())
|
||||
self.citizen.details.xp = 15000
|
||||
self.assertFalse(self.citizen.should_travel_to_fight())
|
||||
|
||||
self.citizen.energy.recovered = 3000
|
||||
self.citizen.energy.recoverable = 2910
|
||||
self.assertTrue(self.citizen.should_travel_to_fight())
|
||||
self.citizen.energy.recoverable = 2900
|
||||
self.assertFalse(self.citizen.should_travel_to_fight())
|
||||
|
||||
# self.citizen.next_reachable_energy and self.citizen.config.next_energy
|
||||
self.citizen.config.next_energy = True
|
||||
self.citizen.energy.limit = 5000
|
||||
self.citizen.details.next_pp = [5000, 5250, 5750, 6250, 6750]
|
||||
self.citizen.details.pp = 4900
|
||||
self.citizen.energy.recovered = 4000
|
||||
self.citizen.energy.recoverable = 4510
|
||||
self.assertEqual(self.citizen.next_reachable_energy, 850)
|
||||
self.citizen.energy.recoverable = 4490
|
||||
self.assertTrue(self.citizen.should_travel_to_fight())
|
||||
self.assertEqual(self.citizen.next_reachable_energy, 350)
|
||||
self.citizen.energy.recovered = 100
|
||||
self.citizen.energy.recoverable = 150
|
||||
self.assertFalse(self.citizen.should_travel_to_fight())
|
||||
self.assertEqual(self.citizen.next_reachable_energy, 0)
|
||||
|
||||
def test_should_fight(self):
|
||||
self.citizen.config.fight = False
|
||||
self.assertEqual(self.citizen.should_fight(), 0)
|
||||
|
||||
self.citizen.config.fight = True
|
||||
|
||||
# Level up
|
||||
self.citizen.energy.limit = 3000
|
||||
self.citizen.details.xp = 24705
|
||||
self.assertEqual(self.citizen.should_fight(), 0)
|
||||
|
||||
self.citizen.energy.recovered = 3000
|
||||
self.citizen.energy.recoverable = 2950
|
||||
self.citizen.energy.interval = 30
|
||||
self.assertEqual(self.citizen.should_fight(), 900)
|
||||
self.citizen.my_companies.ff_lockdown = 160
|
||||
self.assertEqual(self.citizen.should_fight(), 900)
|
||||
self.citizen.my_companies.ff_lockdown = 0
|
||||
|
||||
# Level up reachable
|
||||
self.citizen.details.xp = 24400
|
||||
self.assertEqual(self.citizen.should_fight(), 305)
|
||||
self.citizen.my_companies.ff_lockdown = 160
|
||||
self.assertEqual(self.citizen.should_fight(), 305)
|
||||
self.citizen.my_companies.ff_lockdown = 0
|
||||
|
||||
self.citizen.details.xp = 21000
|
||||
self.assertEqual(self.citizen.should_fight(), 75)
|
||||
self.citizen.my_companies.ff_lockdown = 160
|
||||
self.assertEqual(self.citizen.should_fight(), 75)
|
||||
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)
|
||||
self.citizen.my_companies.ff_lockdown = 160
|
||||
self.assertEqual(self.citizen.should_fight(), 435)
|
||||
self.citizen.my_companies.ff_lockdown = 0
|
||||
|
||||
self.citizen.config.air = True
|
||||
self.citizen.energy.recoverable = 1000
|
||||
self.assertEqual(self.citizen.should_fight(), 400)
|
||||
self.citizen.my_companies.ff_lockdown = 160
|
||||
self.assertEqual(self.citizen.should_fight(), 240)
|
||||
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)
|
||||
self.citizen.my_companies.ff_lockdown = 160
|
||||
self.assertEqual(self.citizen.should_fight(), 160)
|
||||
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)
|
||||
|
||||
def test_command_line_interface(self):
|
||||
"""Test the CLI."""
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(cli.main)
|
||||
assert result.exit_code == 0
|
||||
assert 'erepublik.cli.main' in result.output
|
||||
help_result = runner.invoke(cli.main, ['--help'])
|
||||
assert help_result.exit_code == 0
|
||||
assert '--help Show this message and exit.' in help_result.output
|
||||
|
Reference in New Issue
Block a user