Compare commits

..

6 Commits

Author SHA1 Message Date
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
8 changed files with 40 additions and 170 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

@ -4,8 +4,7 @@
__author__ = """Eriks Karls"""
__email__ = 'eriks@72.lv'
__version__ = '0.14.3'
__all__ = ["Citizen"]
__version__ = '0.14.4'
from erepublik_script import classes, utils
from erepublik_script.citizen import Citizen

View File

@ -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:
@ -1285,12 +1288,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:

View File

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

@ -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,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.4
commit = True
tag = True

View File

@ -41,6 +41,6 @@ setup(
test_suite='tests',
tests_require=test_requirements,
url='https://github.com/eeriks/erepublik_script',
version='0.14.3',
version='0.14.4',
zip_safe=False,
)