Example updates
This commit is contained in:
parent
5712007e3f
commit
ff2a0e02dc
@ -5,7 +5,7 @@
|
||||
__author__ = """Eriks Karls"""
|
||||
__email__ = 'eriks@72.lv'
|
||||
__version__ = '0.20.0'
|
||||
__commit_id__ = "f64a9dc"
|
||||
__commit_id__ = "5712007"
|
||||
|
||||
from erepublik import classes, utils
|
||||
from erepublik.citizen import Citizen
|
||||
|
@ -9,7 +9,8 @@ CONFIG = {
|
||||
'interactive': True,
|
||||
'fight': True,
|
||||
'debug': True,
|
||||
'start_battles': {
|
||||
'battle_launcher': {
|
||||
# War id: {auto_attack: bool (attack asap when region is available), regions: [region_ids allowed to attack]}
|
||||
121672: {"auto_attack": False, "regions": [661]},
|
||||
125530: {"auto_attack": False, "regions": [259]},
|
||||
125226: {"auto_attack": True, "regions": [549]},
|
||||
@ -24,7 +25,7 @@ def _battle_launcher(player: Citizen):
|
||||
time. If player is allowed to fight, do 100 hits on the first round in players division.
|
||||
|
||||
:param player: Logged in Citizen instance
|
||||
":type player: Citizen
|
||||
:type player: Citizen
|
||||
"""
|
||||
global CONFIG
|
||||
finished_war_ids = {*[]}
|
||||
@ -38,13 +39,13 @@ def _battle_launcher(player: Citizen):
|
||||
player.update_war_info()
|
||||
running_wars = {b.war_id for b in player.all_battles.values()}
|
||||
for war_id in war_ids - finished_war_ids - running_wars:
|
||||
war = war_data[str(war_id)]
|
||||
war = war_data[war_id]
|
||||
war_regions = set(war.get('regions'))
|
||||
auto_attack = war.get('auto_attack')
|
||||
|
||||
status = player.get_war_status(war_id)
|
||||
if status.get('ended', False):
|
||||
CONFIG['start_battles'].pop(str(war_id), None)
|
||||
CONFIG['start_battles'].pop(war_id, None)
|
||||
finished_war_ids.add(war_id)
|
||||
continue
|
||||
elif not status.get('can_attack'):
|
||||
@ -76,18 +77,19 @@ def _battle_launcher(player: Citizen):
|
||||
else:
|
||||
next_attack_time = utils.good_timedelta(next_attack_time, timedelta(minutes=5))
|
||||
player.stop_threads.wait(utils.get_sleep_seconds(next_attack_time))
|
||||
except:
|
||||
player.report_error("Task error: start_battles")
|
||||
except Exception as e:
|
||||
player.report_error(f"Task battle launcher ran into error {e}")
|
||||
|
||||
|
||||
# noinspection DuplicatedCode
|
||||
def main():
|
||||
player = Citizen(email=CONFIG['email'], password=CONFIG['password'], auto_login=False)
|
||||
player.config.interactive = CONFIG['interactive']
|
||||
player.config.fight = CONFIG['fight']
|
||||
player.set_debug(CONFIG.get('debug', False))
|
||||
player.login()
|
||||
if CONFIG.get('start_battles'):
|
||||
name = "{}-start_battles-{}".format(player.name, threading.active_count() - 1)
|
||||
if CONFIG.get('battle_launcher'):
|
||||
name = "{}-battle_launcher-{}".format(player.name, threading.active_count() - 1)
|
||||
state_thread = threading.Thread(target=_battle_launcher, args=(player,), name=name)
|
||||
state_thread.start()
|
||||
|
||||
|
@ -10,6 +10,7 @@ CONFIG = {
|
||||
}
|
||||
|
||||
|
||||
# noinspection DuplicatedCode
|
||||
def main():
|
||||
player = Citizen(email=CONFIG['email'], password=CONFIG['password'], auto_login=False)
|
||||
player.config.interactive = CONFIG['interactive']
|
||||
@ -30,72 +31,75 @@ def main():
|
||||
if player.config.wam:
|
||||
tasks.update({'wam': now.replace(hour=14, minute=0)})
|
||||
while True:
|
||||
player.update_all()
|
||||
if tasks.get('work', dt_max) <= now:
|
||||
player.write_log("Doing task: work")
|
||||
player.update_citizen_info()
|
||||
player.work()
|
||||
if player.config.ot:
|
||||
tasks['ot'] = now
|
||||
player.collect_daily_task()
|
||||
next_time = utils.good_timedelta(now.replace(hour=0, minute=0, second=0), timedelta(days=1))
|
||||
tasks.update({'work': next_time})
|
||||
try:
|
||||
player.update_all()
|
||||
if tasks.get('work', dt_max) <= now:
|
||||
player.write_log("Doing task: work")
|
||||
player.update_citizen_info()
|
||||
player.work()
|
||||
if player.config.ot:
|
||||
tasks['ot'] = now
|
||||
player.collect_daily_task()
|
||||
next_time = utils.good_timedelta(now.replace(hour=0, minute=0, second=0), timedelta(days=1))
|
||||
tasks.update({'work': next_time})
|
||||
|
||||
if tasks.get('train', dt_max) <= now:
|
||||
player.write_log("Doing task: train")
|
||||
player.update_citizen_info()
|
||||
player.train()
|
||||
player.collect_daily_task()
|
||||
next_time = utils.good_timedelta(now.replace(hour=0, minute=0, second=0), timedelta(days=1))
|
||||
tasks.update({'train': next_time})
|
||||
if tasks.get('train', dt_max) <= now:
|
||||
player.write_log("Doing task: train")
|
||||
player.update_citizen_info()
|
||||
player.train()
|
||||
player.collect_daily_task()
|
||||
next_time = utils.good_timedelta(now.replace(hour=0, minute=0, second=0), timedelta(days=1))
|
||||
tasks.update({'train': next_time})
|
||||
|
||||
if tasks.get('wam', dt_max) <= now:
|
||||
player.write_log("Doing task: Work as manager")
|
||||
success = player.work_wam()
|
||||
player.eat()
|
||||
if success:
|
||||
next_time = utils.good_timedelta(now.replace(hour=14, minute=0, second=0, microsecond=0),
|
||||
timedelta(days=1))
|
||||
else:
|
||||
next_time = utils.good_timedelta(now.replace(second=0, microsecond=0), timedelta(minutes=30))
|
||||
if tasks.get('wam', dt_max) <= now:
|
||||
player.write_log("Doing task: Work as manager")
|
||||
success = player.work_as_manager()
|
||||
player.eat()
|
||||
if success:
|
||||
next_time = utils.good_timedelta(now.replace(hour=14, minute=0, second=0, microsecond=0),
|
||||
timedelta(days=1))
|
||||
else:
|
||||
next_time = utils.good_timedelta(now.replace(second=0, microsecond=0), timedelta(minutes=30))
|
||||
|
||||
tasks.update({'wam': next_time})
|
||||
tasks.update({'wam': next_time})
|
||||
|
||||
if tasks.get('eat', dt_max) <= now:
|
||||
player.write_log("Doing task: eat")
|
||||
player.eat()
|
||||
if tasks.get('eat', dt_max) <= now:
|
||||
player.write_log("Doing task: eat")
|
||||
player.eat()
|
||||
|
||||
if player.energy.food_fights > player.energy.limit // 10:
|
||||
next_minutes = 12
|
||||
else:
|
||||
next_minutes = (player.energy.limit - 5 * player.energy.interval) // player.energy.interval * 6
|
||||
if player.energy.food_fights > player.energy.limit // 10:
|
||||
next_minutes = 12
|
||||
else:
|
||||
next_minutes = (player.energy.limit - 5 * player.energy.interval) // player.energy.interval * 6
|
||||
|
||||
next_time = player.energy.reference_time + timedelta(minutes=next_minutes)
|
||||
tasks.update({'eat': next_time})
|
||||
next_time = player.energy.reference_time + timedelta(minutes=next_minutes)
|
||||
tasks.update({'eat': next_time})
|
||||
|
||||
if tasks.get('ot', dt_max) <= now:
|
||||
player.write_log("Doing task: ot")
|
||||
if now > player.my_companies.next_ot_time:
|
||||
player.work_ot()
|
||||
next_time = now + timedelta(minutes=60)
|
||||
else:
|
||||
next_time = player.my_companies.next_ot_time
|
||||
tasks.update({'ot': next_time})
|
||||
if tasks.get('ot', dt_max) <= now:
|
||||
player.write_log("Doing task: ot")
|
||||
if now > player.my_companies.next_ot_time:
|
||||
player.work_ot()
|
||||
next_time = now + timedelta(minutes=60)
|
||||
else:
|
||||
next_time = player.my_companies.next_ot_time
|
||||
tasks.update({'ot': next_time})
|
||||
|
||||
closest_next_time = dt_max
|
||||
next_tasks = []
|
||||
for task, next_time in sorted(tasks.items(), key=lambda s: s[1]):
|
||||
next_tasks.append("{}: {}".format(next_time.strftime('%F %T'), task))
|
||||
if next_time < closest_next_time:
|
||||
closest_next_time = next_time
|
||||
sleep_seconds = int(utils.get_sleep_seconds(closest_next_time))
|
||||
if sleep_seconds <= 0:
|
||||
player.write_log(f"Loop detected! Offending task: '{next_tasks[0]}'")
|
||||
player.write_log("My next Tasks and there time:\n" + "\n".join(sorted(next_tasks)))
|
||||
player.write_log("Sleeping until (eRep): {} (sleeping for {}s)".format(
|
||||
closest_next_time.strftime("%F %T"), sleep_seconds))
|
||||
seconds_to_sleep = sleep_seconds if sleep_seconds > 0 else 0
|
||||
player.sleep(seconds_to_sleep)
|
||||
closest_next_time = dt_max
|
||||
next_tasks = []
|
||||
for task, next_time in sorted(tasks.items(), key=lambda s: s[1]):
|
||||
next_tasks.append("{}: {}".format(next_time.strftime('%F %T'), task))
|
||||
if next_time < closest_next_time:
|
||||
closest_next_time = next_time
|
||||
sleep_seconds = int(utils.get_sleep_seconds(closest_next_time))
|
||||
if sleep_seconds <= 0:
|
||||
player.write_log(f"Loop detected! Offending task: '{next_tasks[0]}'")
|
||||
player.write_log("My next Tasks and there time:\n" + "\n".join(sorted(next_tasks)))
|
||||
player.write_log("Sleeping until (eRep): {} (sleeping for {}s)".format(
|
||||
closest_next_time.strftime("%F %T"), sleep_seconds))
|
||||
seconds_to_sleep = sleep_seconds if sleep_seconds > 0 else 0
|
||||
player.sleep(seconds_to_sleep)
|
||||
except Exception as e:
|
||||
player.report_error(f"Task main loop ran into error: {e}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Loading…
x
Reference in New Issue
Block a user