From 687923690f7123b6b1a6e83acb79cd9b4f63d199 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Wed, 11 Nov 2020 13:23:16 +0100 Subject: [PATCH] Chunk translation clean script to avoid too long url error (#43090) --- script/translations/clean.py | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/script/translations/clean.py b/script/translations/clean.py index 370c1d672ea..63281b36229 100644 --- a/script/translations/clean.py +++ b/script/translations/clean.py @@ -91,22 +91,25 @@ def run(): print("No missing translations!") return 0 - key_data = lokalise.keys_list( - {"filter_keys": ",".join(missing_keys), "limit": 1000} - ) - if len(key_data) != len(missing_keys): - print( - f"Lookin up key in Lokalise returns {len(key_data)} results, expected {len(missing_keys)}" - ) - return 1 + # We can't query too many keys at once, so limit the number to 50. + for i in range(0, len(missing_keys), 50): + chunk = missing_keys[i : i + 50] - print(f"Deleting {len(missing_keys)} keys:") - for key in missing_keys: - print(" -", key) - print() - while input("Type YES to delete these keys: ") != "YES": - pass + key_data = lokalise.keys_list({"filter_keys": ",".join(chunk), "limit": 1000}) + if len(key_data) != len(chunk): + print( + f"Lookin up key in Lokalise returns {len(key_data)} results, expected {len(chunk)}" + ) + return 1 - print(lokalise.keys_delete_multiple([key["key_id"] for key in key_data])) + print(f"Deleting {len(chunk)} keys:") + for key in chunk: + print(" -", key) + print() + while input("Type YES to delete these keys: ") != "YES": + pass + + print(lokalise.keys_delete_multiple([key["key_id"] for key in key_data])) + print() return 0