From 947cd02f06ac81f9e85b22471cf3a6501cd60dd9 Mon Sep 17 00:00:00 2001 From: hldh214 Date: Mon, 3 Jul 2023 13:41:44 +0900 Subject: [PATCH] feat(farmer): add `interval` for `train_troop_thread` && sync `version` Signed-off-by: hldh214 --- config.example.json | 3 ++- lokbot/client.py | 2 +- lokbot/farmer.py | 21 +++++++++------------ 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/config.example.json b/config.example.json index 5d637d9c..d6de3c36 100644 --- a/config.example.json +++ b/config.example.json @@ -118,7 +118,8 @@ "enabled": true, "kwargs": { "troop_code": 50100101, - "speedup": true + "speedup": true, + "interval": 3600 } } ] diff --git a/lokbot/client.py b/lokbot/client.py index 61b41773..6f87fc1c 100644 --- a/lokbot/client.py +++ b/lokbot/client.py @@ -611,7 +611,7 @@ def field_march_start(self, data): def get_version(): first = 1 - second = 1630 + second = 1652 third = httpx.get('https://play.leagueofkingdoms.com/json/version-live.json').json().get('table') fourth = httpx.get(f'https://play.leagueofkingdoms.com/bundles/webgl/kingdominfo_{second}').json() fourth = [each for each in fourth if each.get('name') == 'ui'][0].get('version') diff --git a/lokbot/farmer.py b/lokbot/farmer.py index 3f6d6b16..dafa7703 100644 --- a/lokbot/farmer.py +++ b/lokbot/farmer.py @@ -93,7 +93,7 @@ def __init__(self, token, captcha_solver_config): "country": "USA", "language": "English", "bundle": "", - "version": "1.1630.136.218", + "version": "1.1652.138.219", "platform": "web", "pushId": "" }) @@ -1042,9 +1042,10 @@ def _random_choice_building(self, building_code): buildings = self.kingdom_enter.get('kingdom', {}).get('buildings', []) return random.choice([building for building in buildings if building['code'] == building_code]) - def train_troop_thread(self, troop_code, speedup=False): + def train_troop_thread(self, troop_code, speedup=False, interval=3600): """ train troop + :param interval: :param troop_code: :param speedup: :return: @@ -1058,18 +1059,14 @@ def train_troop_thread(self, troop_code, speedup=False): if worker_used: if worker_used[0].get('status') == STATUS_CLAIMED: self.api.kingdom_task_claim(self._random_choice_building(BUILDING_CODE_MAP['barrack'])['position']) - logger.info('train_troop: one loop completed, sleep for 3h') - threading.Timer( - 3 * 3600, - self.train_troop_thread, - [troop_code, speedup] - ).start() + logger.info(f'train_troop: one loop completed, sleep for {interval} seconds') + threading.Timer(interval, self.train_troop_thread, [troop_code, speedup, interval]).start() return if worker_used[0].get('status') == STATUS_PENDING: self.train_queue_available.wait() # wait for train queue available from `sock_thread` self.train_queue_available.clear() - threading.Thread(target=self.train_troop_thread, args=[troop_code, speedup]).start() + threading.Thread(target=self.train_troop_thread, args=[troop_code, speedup, interval]).start() return # if there is not enough resource, train how much possible @@ -1078,8 +1075,8 @@ def train_troop_thread(self, troop_code, speedup=False): troop_training_capacity = total_troops_capacity_according_to_resources if not troop_training_capacity: - logger.info('train_troop: no resource, sleep for 3h') - threading.Timer(3 * 3600, self.train_troop_thread, [troop_code, speedup]).start() + logger.info('train_troop: no resource, sleep for 1h') + threading.Timer(3600, self.train_troop_thread, [troop_code, speedup, interval]).start() return res = self.api.train_troop(troop_code, troop_training_capacity) @@ -1089,7 +1086,7 @@ def train_troop_thread(self, troop_code, speedup=False): self.train_queue_available.wait() # wait for train queue available from `sock_thread` self.train_queue_available.clear() - threading.Thread(target=self.train_troop_thread, args=[troop_code, speedup]).start() + threading.Thread(target=self.train_troop_thread, args=[troop_code, speedup, interval]).start() def free_chest_farmer_thread(self, _type=0): """