From b458ea99b2a91544086c049653674cbb63e03809 Mon Sep 17 00:00:00 2001 From: niyari Date: Wed, 28 Sep 2022 07:02:34 +0900 Subject: [PATCH 1/2] Added progress (ika). --- s3s.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/s3s.py b/s3s.py index 123f272..7d768e2 100755 --- a/s3s.py +++ b/s3s.py @@ -207,7 +207,10 @@ def fetch_json(which, separate=False, exportall=False, specific=False, numbers_o queries.append(None) needs_sorted = False # https://ygdp.yale.edu/phenomena/needs-washed :D + progress = Progress() + for sha in queries: + progress() if sha != None: if DEBUG: print(f"* making query1 to {sha}") @@ -222,6 +225,7 @@ def fetch_json(which, separate=False, exportall=False, specific=False, numbers_o for battle_group in query1_resp["data"]["latestBattleHistories"]["historyGroups"]["nodes"]: for battle in battle_group["historyDetails"]["nodes"]: battle_ids.append(battle["id"]) # don't filter out private battles here - do that in post_result() + progress() # ink battles - latest 50 turf war elif "regularBattleHistories" in query1_resp["data"]: @@ -229,12 +233,14 @@ def fetch_json(which, separate=False, exportall=False, specific=False, numbers_o for battle_group in query1_resp["data"]["regularBattleHistories"]["historyGroups"]["nodes"]: for battle in battle_group["historyDetails"]["nodes"]: battle_ids.append(battle["id"]) + progress() # ink battles - latest 50 anarchy battles elif "bankaraBattleHistories" in query1_resp["data"]: needs_sorted = True for battle_group in query1_resp["data"]["bankaraBattleHistories"]["historyGroups"]["nodes"]: for battle in battle_group["historyDetails"]["nodes"]: battle_ids.append(battle["id"]) + progress() # ink battles - latest 50 private battles elif "privateBattleHistories" in query1_resp["data"] \ and not utils.custom_key_exists("ignore_private", CONFIG_DATA): @@ -242,11 +248,13 @@ def fetch_json(which, separate=False, exportall=False, specific=False, numbers_o for battle_group in query1_resp["data"]["privateBattleHistories"]["historyGroups"]["nodes"]: for battle in battle_group["historyDetails"]["nodes"]: battle_ids.append(battle["id"]) + progress() # salmon run jobs - latest 50 elif "coopResult" in query1_resp["data"]: for shift in query1_resp["data"]["coopResult"]["historyGroups"]["nodes"]: for job in shift["historyDetails"]["nodes"]: job_ids.append(job["id"]) + progress() if numbers_only: ink_list.extend(battle_ids) @@ -259,6 +267,7 @@ def fetch_json(which, separate=False, exportall=False, specific=False, numbers_o cookies=dict(_gtoken=GTOKEN)) query2_resp_b = json.loads(query2_b.text) ink_list.append(query2_resp_b) + progress() for jid in job_ids: query2_j = requests.post(utils.GRAPHQL_URL, @@ -267,6 +276,7 @@ def fetch_json(which, separate=False, exportall=False, specific=False, numbers_o cookies=dict(_gtoken=GTOKEN)) query2_resp_j = json.loads(query2_j.text) salmon_list.append(query2_resp_j) + progress() if needs_sorted: # put regular, bankara, and private in order, since they were exported in sequential chunks try: @@ -992,6 +1002,18 @@ def monitor_battles(which, secs, isblackout, istestrun): print("Please run s3s again with " + '\033[91m' + "-r" + '\033[0m' + " to get these battles.") print("Bye!") +class Progress: + def __init__(self): + self.count = 0 + + def __call__(self): + lineend = 31 + ika = '>=> ' if self.count % 2 == 0 else '===>' + sys.stdout.write("\r%s%s%s" % (' ' * self.count, ika, ' ' * (lineend - self.count))) + sys.stdout.flush() + self.count += 1 + if(self.count > lineend): + self.count = 0 def main(): '''Main process, including I/O and setup.''' From 8ae33e6267bf067cbfe9cbf2ff806a549896a8b8 Mon Sep 17 00:00:00 2001 From: eli fessler Date: Tue, 27 Sep 2022 21:24:42 -1000 Subject: [PATCH 2/2] tweak squid swim progress animation --- s3s.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/s3s.py b/s3s.py index 7d768e2..0e79119 100755 --- a/s3s.py +++ b/s3s.py @@ -207,10 +207,10 @@ def fetch_json(which, separate=False, exportall=False, specific=False, numbers_o queries.append(None) needs_sorted = False # https://ygdp.yale.edu/phenomena/needs-washed :D - progress = Progress() + swim = SquidProgress() for sha in queries: - progress() + swim() if sha != None: if DEBUG: print(f"* making query1 to {sha}") @@ -219,13 +219,13 @@ def fetch_json(which, separate=False, exportall=False, specific=False, numbers_o query1 = requests.post(utils.GRAPHQL_URL, data=utils.gen_graphql_body(sha), headers=headbutt(), cookies=dict(_gtoken=GTOKEN)) query1_resp = json.loads(query1.text) + swim() # ink battles - latest 50 of any type if "latestBattleHistories" in query1_resp["data"]: for battle_group in query1_resp["data"]["latestBattleHistories"]["historyGroups"]["nodes"]: for battle in battle_group["historyDetails"]["nodes"]: battle_ids.append(battle["id"]) # don't filter out private battles here - do that in post_result() - progress() # ink battles - latest 50 turf war elif "regularBattleHistories" in query1_resp["data"]: @@ -233,14 +233,12 @@ def fetch_json(which, separate=False, exportall=False, specific=False, numbers_o for battle_group in query1_resp["data"]["regularBattleHistories"]["historyGroups"]["nodes"]: for battle in battle_group["historyDetails"]["nodes"]: battle_ids.append(battle["id"]) - progress() # ink battles - latest 50 anarchy battles elif "bankaraBattleHistories" in query1_resp["data"]: needs_sorted = True for battle_group in query1_resp["data"]["bankaraBattleHistories"]["historyGroups"]["nodes"]: for battle in battle_group["historyDetails"]["nodes"]: battle_ids.append(battle["id"]) - progress() # ink battles - latest 50 private battles elif "privateBattleHistories" in query1_resp["data"] \ and not utils.custom_key_exists("ignore_private", CONFIG_DATA): @@ -248,13 +246,11 @@ def fetch_json(which, separate=False, exportall=False, specific=False, numbers_o for battle_group in query1_resp["data"]["privateBattleHistories"]["historyGroups"]["nodes"]: for battle in battle_group["historyDetails"]["nodes"]: battle_ids.append(battle["id"]) - progress() # salmon run jobs - latest 50 elif "coopResult" in query1_resp["data"]: for shift in query1_resp["data"]["coopResult"]["historyGroups"]["nodes"]: for job in shift["historyDetails"]["nodes"]: job_ids.append(job["id"]) - progress() if numbers_only: ink_list.extend(battle_ids) @@ -267,7 +263,7 @@ def fetch_json(which, separate=False, exportall=False, specific=False, numbers_o cookies=dict(_gtoken=GTOKEN)) query2_resp_b = json.loads(query2_b.text) ink_list.append(query2_resp_b) - progress() + swim() for jid in job_ids: query2_j = requests.post(utils.GRAPHQL_URL, @@ -276,7 +272,7 @@ def fetch_json(which, separate=False, exportall=False, specific=False, numbers_o cookies=dict(_gtoken=GTOKEN)) query2_resp_j = json.loads(query2_j.text) salmon_list.append(query2_resp_j) - progress() + swim() if needs_sorted: # put regular, bankara, and private in order, since they were exported in sequential chunks try: @@ -1002,17 +998,17 @@ def monitor_battles(which, secs, isblackout, istestrun): print("Please run s3s again with " + '\033[91m' + "-r" + '\033[0m' + " to get these battles.") print("Bye!") -class Progress: +class SquidProgress: def __init__(self): self.count = 0 def __call__(self): - lineend = 31 + lineend = os.get_terminal_size()[0] - 4 ika = '>=> ' if self.count % 2 == 0 else '===>' - sys.stdout.write("\r%s%s%s" % (' ' * self.count, ika, ' ' * (lineend - self.count))) + sys.stdout.write(f"\r{' '*self.count}{ika}{' '*(lineend - self.count)}") sys.stdout.flush() self.count += 1 - if(self.count > lineend): + if self.count > lineend: self.count = 0 def main():