Compare commits

..

11 Commits

Author SHA1 Message Date
a1d10bb427 Bump version: 0.14.4 → 0.14.5 2019-07-23 17:55:08 +03:00
ec701396d9 project name migration 2019-07-23 17:55:04 +03:00
d8035b42e3 Underline too short 2019-07-23 17:53:00 +03:00
42320a14a4 no message 2019-07-23 17:50:14 +03:00
de4b059b7d Package name update: erepublik_script → eRepublik 2019-07-23 16:41:21 +03:00
dc106cc87d Bump version: 0.14.3 → 0.14.4 2019-07-23 14:37:35 +03:00
bb2c13d63a requirement update 2019-07-23 14:37:26 +03:00
ea48fbe7e1 Wall post comment creation endpoints 2019-07-23 14:37:07 +03:00
65a3a9f678 Possible memory leak addressed 2019-07-23 14:36:27 +03:00
0757345e17 . 2019-07-23 14:34:49 +03:00
6f4b32b12c code cleanup 2019-07-22 11:54:33 +03:00
18 changed files with 100 additions and 226 deletions

View File

@ -2,10 +2,8 @@
language: python
python:
- 3.7
- 3.6
- 3.5
- 3.4
- 2.7
# Command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
install: pip install -U tox-travis

View File

@ -6,3 +6,9 @@ History
------------------
* First release on PyPI.
0.14.4 (2019-07-23)
-------------------
* Wall post comment endpoints updated with comment create endpoints

View File

@ -51,7 +51,7 @@ clean-test: ## remove test and coverage artifacts
rm -fr .pytest_cache
lint: ## check style with flake8
flake8 erepublik_script tests
flake8 erepublik tests
test: ## run tests quickly with the default Python
python setup.py test
@ -60,15 +60,15 @@ test-all: ## run tests on every Python version with tox
tox
coverage: ## check code coverage quickly with the default Python
coverage run --source erepublik_script setup.py test
coverage run --source erepublik setup.py test
coverage report -m
coverage html
$(BROWSER) htmlcov/index.html
docs: ## generate Sphinx HTML documentation, including API docs
rm -f docs/erepublik_script.rst
rm -f docs/erepublik.rst
rm -f docs/modules.rst
sphinx-apidoc -o docs/ erepublik_script
sphinx-apidoc -o docs/ erepublik
$(MAKE) -C docs clean
$(MAKE) -C docs html
$(BROWSER) docs/_build/html/index.html

View File

@ -3,10 +3,10 @@ eRepublik script
================
.. image:: https://img.shields.io/pypi/v/erepublik_script.svg
:target: https://pypi.python.org/pypi/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
.. image:: https://readthedocs.org/projects/erepublik/badge/?version=latest
:target: https://erepublik-script.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-script.readthedocs.io.
* Documentation: https://erepublik.readthedocs.io.
Features

View File

@ -4,7 +4,7 @@
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = python -msphinx
SPHINXPROJ = erepublik_script
SPHINXPROJ = erepublik
SOURCEDIR = .
BUILDDIR = _build

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# erepublik_script documentation build configuration file, created by
# erepublik documentation build configuration file, created by
# sphinx-quickstart on Fri Jun 9 13:47:02 2017.
#
# This file is execfile()d with the current directory set to its
@ -22,7 +22,7 @@ import os
import sys
sys.path.insert(0, os.path.abspath('..'))
import erepublik_script
import erepublik
# -- General configuration ---------------------------------------------
@ -56,9 +56,9 @@ author = u"Eriks Karls"
# the built documents.
#
# The short X.Y version.
version = erepublik_script.__version__
version = erepublik.__version__
# The full version, including alpha/beta/rc tags.
release = erepublik_script.__version__
release = erepublik.__version__
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
@ -128,7 +128,7 @@ latex_elements = {
# (source start file, target name, title, author, documentclass
# [howto, manual, or own class]).
latex_documents = [
(master_doc, 'erepublik_script.tex',
(master_doc, 'erepublik.tex',
u'eRepublik script Documentation',
u'Eriks Karls', 'manual'),
]
@ -139,7 +139,7 @@ latex_documents = [
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'erepublik_script',
(master_doc, 'erepublik',
u'eRepublik script Documentation',
[author], 1)
]
@ -151,10 +151,10 @@ man_pages = [
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'erepublik_script',
(master_doc, 'erepublik',
u'eRepublik script Documentation',
author,
'erepublik_script',
'erepublik',
'One line description of project.',
'Miscellaneous'),
]

View File

@ -12,7 +12,7 @@ To install eRepublik script, run this command in your terminal:
.. code-block:: console
$ pip install erepublik_script
$ pip install erepublik
This is the preferred method to install eRepublik script, as it will always install the most recent stable release.

View File

@ -4,4 +4,4 @@ Usage
To use eRepublik script in a project::
import erepublik_script
import erepublik

10
erepublik/__init__.py Normal file
View File

@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
"""Top-level package for eRepublik script."""
__author__ = """Eriks Karls"""
__email__ = 'eriks@72.lv'
__version__ = '0.14.5'
from erepublik import classes, utils
from erepublik.citizen import Citizen

View File

@ -9,7 +9,7 @@ from typing import Dict, List, Tuple, Any, Union
import requests
from requests import Response, RequestException
from erepublik_script import classes, utils
from erepublik import classes, utils
class Citizen(classes.CitizenAPI):
@ -94,6 +94,8 @@ class Citizen(classes.CitizenAPI):
ret = super().__dict__.copy()
ret.pop('reporter', None)
ret.pop('stop_threads', None)
ret.pop('_Citizen__last_war_update_data', None)
ret.update(all_battles=self.all_battles)
return ret
@ -440,6 +442,7 @@ class Citizen(classes.CitizenAPI):
self.update_citizen_info()
resp_json = self.get_military_campaigns().json()
self.all_battles = {}
if resp_json.get("countries"):
for c_id, c_data in resp_json.get("countries").items():
if int(c_id) not in self.countries:
@ -619,10 +622,8 @@ class Citizen(classes.CitizenAPI):
battle_id = r.get("citizen_contribution")[0].get("battle_id", 0)
ret_battles.append(battle_id)
ret_battles += (cs_battles_air + cs_battles_ground +
deployed_battles_air + deployed_battles_ground +
ally_battles_air + ally_battles_ground +
other_battles_air + other_battles_ground)
ret_battles += cs_battles_air + cs_battles_ground + deployed_battles_air + deployed_battles_ground + \
ally_battles_air + ally_battles_ground + other_battles_air + other_battles_ground
return ret_battles
@property
@ -643,8 +644,8 @@ class Citizen(classes.CitizenAPI):
if battle.is_rw:
side_id = battle.defender.id if self.config.rw_def_side else battle.invader.id
else:
side_id = battle.defender.id if (self.details.current_country in battle.defender.allies +
[battle.defender.id, ]) else battle.invader.id
side = self.details.current_country in battle.defender.allies + [battle.defender.id, ]
side_id = battle.defender.id if side else battle.invader.id
try:
def_points = battle.div.get(div).dom_pts.get('def')
inv_points = battle.div.get(div).dom_pts.get('inv')
@ -1285,12 +1286,12 @@ class Citizen(classes.CitizenAPI):
if count > 0 and not force_fight:
if self.my_companies.ff_lockdown and self.details.pp > 75:
if self.energy.food_fights - self.my_companies.ff_lockdown > 0:
if count - self.my_companies.ff_lockdown > 0:
log_msg = ("Fight count modified (old count: {} | FF: {} | "
"WAM ff_lockdown: {} | New count: {})").format(
count, self.energy.food_fights, self.my_companies.ff_lockdown,
self.energy.food_fights - self.my_companies.ff_lockdown)
count = self.energy.food_fights - self.my_companies.ff_lockdown
count - self.my_companies.ff_lockdown)
count -= self.my_companies.ff_lockdown
else:
count = 0
if count <= 0:
@ -1446,11 +1447,12 @@ class Citizen(classes.CitizenAPI):
raw = wrm
else:
continue
effective_bonus = cdata["effective_bonus"]
base_prod = float(cdata["base_production"])
if cdata["is_raw"]:
raw += float(cdata["base_production"]) * cdata["effective_bonus"] / 100
raw += base_prod * effective_bonus / 100
else:
raw -= cdata["effective_bonus"] / 100 * cdata["base_production"] * \
cdata["upgrades"][str(cdata["quality"])]["raw_usage"]
raw -= effective_bonus / 100 * base_prod * cdata["upgrades"][str(cdata["quality"])]["raw_usage"]
if cdata["industry_token"] == "FOOD":
frm = raw
elif cdata["industry_token"] == "WEAPON":

View File

@ -11,7 +11,7 @@ from typing import Any, Dict, List, Union
from requests import Response, Session
from slugify import slugify
from erepublik_script import utils
from erepublik import utils
class ErepublikException(Exception):
@ -228,7 +228,7 @@ class SlowRequests(Session):
file.write(body.encode("UTF-8"))
def _log_response(self, url, resp, redirect: bool = False):
from erepublik_script import Citizen
from erepublik import Citizen
if self.debug:
if resp.history and not redirect:
for hist_resp in resp.history:
@ -358,6 +358,7 @@ class Energy:
def available(self):
return self.recovered + self.recoverable
@property
def __dict__(self):
return dict(
limit=self.limit,
@ -780,6 +781,10 @@ class CitizenAPI:
data = {"_token": token, "postId": post_id}
return self.post("{}/main/country-comment/retrieve/json".format(self.url), data=data)
def post_country_comment_create(self, token: str, post_id: int, comment_message: str):
data = {"_token": 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, token: str, body: str, post_as: int):
data = {"_token": token, "post_message": body, "post_as": post_as}
return self.post("{}/main/country-post/create/json".format(self.url), data=data)
@ -794,6 +799,10 @@ class CitizenAPI:
data = {"_token": 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, token: str, post_id: int, comment_message: str):
data = {"_token": 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, token: str, body: str, post_as: int):
data = {"_token": token, "post_message": body, "post_as": post_as}
return self.post("{}/main/military-unit-post/create/json".format(self.url), data=data)
@ -808,6 +817,10 @@ class CitizenAPI:
data = {"_token": token, "postId": post_id}
return self.post("{}/main/party-comment/retrieve/json".format(self.url), data=data)
def post_party_comment_create(self, token: str, post_id: int, comment_message: str):
data = {"_token": 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, token: str, body: str):
data = {"_token": token, "post_message": body}
return self.post("{}/main/party-post/create/json".format(self.url), data=data)
@ -822,6 +835,10 @@ class CitizenAPI:
data = {"_token": token, "postId": post_id}
return self.post("{}/main/wall-comment/retrieve/json".format(self.url), data=data)
def post_wall_comment_create(self, token: str, post_id: int, comment_message: str):
data = {"_token": 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, token: str, body: str):
data = {"_token": token, "post_message": body}
return self.post("{}/main/wall-post/create/json".format(self.url), data=data)
@ -998,21 +1015,24 @@ class Battle(object):
else:
end = datetime.datetime.max
self.div.update({div: BattleDivision(end, data.get('epic_type') in [1, 5],
data.get('dom_pts').get("inv"), data.get('dom_pts').get("def"),
data.get('wall').get("for"), data.get('wall').get("dom"))})
battle_div = BattleDivision(
end=end, epic=data.get('epic_type') in [1, 5],
inv_pts=data.get('dom_pts').get("inv"), def_pts=data.get('dom_pts').get("def"),
wall_for=data.get('wall').get("for"), wall_dom=data.get('wall').get("dom")
)
self.div.update({div: battle_div})
def __repr__(self):
now = utils.now()
is_started = self.start < utils.now()
if is_started:
timepart = "{}".format(now - self.start)
time_part = "{}".format(now - self.start)
else:
timepart = "- {}".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, timepart)
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
)
class EnergyToFight:

View File

@ -214,7 +214,7 @@ def write_file(filename: str, content: str) -> int:
def write_request(response: requests.Response, is_error: bool = False):
from erepublik_script import Citizen
from erepublik import Citizen
# Remove GET args from url name
url = response.url
last_index = url.index("?") if "?" in url else len(response.url)
@ -238,7 +238,7 @@ def write_request(response: requests.Response, is_error: bool = False):
def send_email(name, content: list, player=None, local_vars=dict, promo: bool = False, captcha: bool = False):
from erepublik_script import Citizen
from erepublik import Citizen
file_content_template = "<html><head><title>{title}</title></head><body>{body}</body></html>"
if isinstance(player, Citizen):
@ -284,156 +284,6 @@ def send_email(name, content: list, player=None, local_vars=dict, promo: bool =
requests.post('https://pasts.72.lv', data=data, files=files)
def parse_input(msg: str) -> bool:
msg += " (y|n):"
data = None
while data not in ['', 'y', 'Y', 'n', 'N']:
try:
data = input(msg)
except EOFError:
data = 'n'
return data in ['', 'y', 'Y']
def parse_config(config=None) -> dict:
if config is None:
config = {}
if not config.get('email'):
config['email'] = input("Player email: ")
if not config.get('password'):
config['password'] = input("Player password: ")
if 'wt' in config:
config['work'] = config['wt']
config['train'] = config['wt']
if 'work' not in config:
config['work'] = parse_input('Should I work')
if 'train' not in config:
config['train'] = parse_input('Should I train')
if 'ot' not in config:
config['ot'] = parse_input('Should I work overtime')
if 'wam' not in config:
config['wam'] = parse_input('Should I WAM')
if 'employ' not in config:
config['employ'] = parse_input('Should I employ employees')
if config['wam'] or config['employ']:
if "autosell" in config:
config.pop("autosell")
if "autosell_raw" in config:
config.pop("autosell_raw")
if "autosell_final" in config:
config.pop("autosell_final")
if 'auto_sell' not in config or not isinstance(config['auto_sell'], list):
if parse_input('Should I auto sell produced products'):
config['auto_sell'] = []
if parse_input("Should I auto sell Food products"):
if parse_input("Should I auto sell Food products"):
config['auto_sell'].append("food")
if parse_input("Should I auto sell Weapon products"):
config['auto_sell'].append("weapon")
if parse_input("Should I auto sell House products"):
config['auto_sell'].append("house")
if parse_input("Should I auto sell Aircraft products"):
config['auto_sell'].append("airplane")
if parse_input("Should I auto sell raw products"):
if parse_input("Should I auto sell Food raw"):
config['auto_sell'].append("foodRaw")
if parse_input("Should I auto sell Weapon raw"):
config['auto_sell'].append("weaponRaw")
if parse_input("Should I auto sell House raw"):
config['auto_sell'].append("houseRaw")
if parse_input("Should I auto sell Airplane raw"):
config['auto_sell'].append("airplaneRaw")
if config['auto_sell']:
if 'auto_sell_all' not in config:
print("When selling produced items should I also sell items already in inventory?")
config['auto_sell_all'] = parse_input('Y - sell all, N - only just produced')
else:
config['auto_sell_all'] = False
if 'auto_buy_raw' not in config:
config['auto_buy_raw'] = parse_input('Should I auto buy raw deficit at WAM or employ')
else:
config['auto_sell'] = []
config['auto_sell_all'] = False
config['auto_buy_raw'] = False
if 'fight' not in config:
config['fight'] = parse_input('Should I fight')
if config.get('fight'):
if 'air' not in config:
config['air'] = parse_input('Should I fight in AIR')
if 'ground' not in config:
config['ground'] = parse_input('Should I fight in GROUND')
if 'all_in' not in config:
print("When full energy should I go all in")
config['all_in'] = parse_input('Y - all in, N - 1h worth of energy')
if 'next_energy' not in config:
config['next_energy'] = parse_input('Should I fight when next pp +1 energy available')
if 'boosters' not in config:
config['boosters'] = parse_input('Should I use +50% dmg boosters')
if 'travel_to_fight' not in config:
config['travel_to_fight'] = parse_input('Should I travel to fight')
if 'epic_hunt' not in config:
config['epic_hunt'] = parse_input('Should I check for epic battles')
if not config['epic_hunt']:
config['epic_hunt_ebs'] = False
if not config['epic_hunt']:
config['epic_hunt_ebs'] = False
elif 'epic_hunt_ebs' not in config:
config['epic_hunt_ebs'] = parse_input('Should I eat EBs when fighting in epic battle')
if 'rw_def_side' not in config:
config['rw_def_side'] = parse_input('Should I fight on defenders side in RWs')
if 'continuous_fighting' not in config:
config['continuous_fighting'] = parse_input('If already fought in any battle, \n'
'should I continue to fight all FF in that battle')
else:
config['air'] = False
config['ground'] = False
config['all_in'] = False
config['next_energy'] = False
config['boosters'] = False
config['travel_to_fight'] = False
config['epic_hunt'] = False
config['epic_hunt_ebs'] = False
config['rw_def_side'] = False
config['continuous_fighting'] = False
if 'debug' not in config:
config['debug'] = parse_input('Should I generate debug files')
if 'random_sleep' not in config:
config['random_sleep'] = parse_input('Should I add random amount (0-120sec) to sleep time')
if 'gold_buy' not in config:
config['gold_buy'] = parse_input('Should I auto buy 10g every day')
if 'interactive' not in config:
config['interactive'] = parse_input('Should I print output to console?')
return config
def normalize_html_json(js: str) -> str:
js = re.sub(r' \'(.*?)\'', lambda a: '"%s"' % a.group(1), js)
js = re.sub(r'(\d\d):(\d\d):(\d\d)', r'\1\2\3', js)

View File

@ -1,12 +0,0 @@
# -*- coding: utf-8 -*-
"""Top-level package for eRepublik script."""
__author__ = """Eriks Karls"""
__email__ = 'eriks@72.lv'
__version__ = '0.14.3'
__all__ = ["Citizen"]
from erepublik_script import classes, utils
from erepublik_script.citizen import Citizen

View File

@ -1,6 +1,6 @@
pip==19.1.1
bumpversion==0.5.3
wheel==0.32.1
wheel==0.33.4
watchdog==0.9.0
flake8==3.7.8
tox==3.13.2

View File

@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.14.3
current_version = 0.14.5
commit = True
tag = True
@ -7,7 +7,7 @@ tag = True
search = version='{current_version}'
replace = version='{new_version}'
[bumpversion:file:erepublik_script/__init__.py]
[bumpversion:file:erepublik/__init__.py]
search = __version__ = '{current_version}'
replace = __version__ = '{new_version}'
@ -17,7 +17,7 @@ universal = 1
[flake8]
exclude = docs
max-line-length = 120
ignore = E722
ignore = E722 F401
[aliases]

View File

@ -21,26 +21,26 @@ setup(
author="Eriks Karls",
author_email='eriks@72.lv',
classifiers=[
'Development Status :: 2 - Pre-Alpha',
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.7',
],
description="Python package for eRepublik automated playing",
description="Python package for automated eRepublik playing",
entry_points={},
install_requires=requirements,
license="MIT license",
long_description=readme + '\n\n' + history,
include_package_data=True,
keywords='erepublik_script',
name='erepublik_script',
packages=find_packages(include=['erepublik_script']),
keywords='erepublik',
name='eRepublik',
packages=find_packages(include=['erepublik']),
setup_requires=setup_requirements,
test_suite='tests',
tests_require=test_requirements,
url='https://github.com/eeriks/erepublik_script',
version='0.14.3',
version='0.14.5',
zip_safe=False,
)

View File

@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-
"""Unit test package for erepublik_script."""
"""Unit test package for erepublik."""

View File

@ -1,18 +1,18 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Tests for `erepublik_script` package."""
"""Tests for `erepublik` package."""
import unittest
from click.testing import CliRunner
from erepublik_script import Citizen
from erepublik_script import cli
from erepublik import Citizen
from erepublik import cli
class TestErepublik_script(unittest.TestCase):
"""Tests for `erepublik_script` package."""
"""Tests for `erepublik` package."""
def setUp(self):
"""Set up test fixtures, if any."""
@ -28,7 +28,7 @@ class TestErepublik_script(unittest.TestCase):
runner = CliRunner()
result = runner.invoke(cli.main)
assert result.exit_code == 0
assert 'erepublik_script.cli.main' in result.output
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