Skip to content

Commit cca29ef

Browse files
committed
contrib/push_locale: minor clean-up
1 parent ef452b1 commit cca29ef

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

contrib/push_locale

+7-4
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,15 @@ subprocess.check_output(cmd, shell=True)
7979
os.chdir(os.path.join(project_root, "electrum"))
8080

8181
crowdin_api_key = None
82-
8382
filename = os.path.expanduser('~/.crowdin_api_key')
8483
if os.path.exists(filename):
8584
with open(filename) as f:
8685
crowdin_api_key = f.read().strip()
87-
8886
if "crowdin_api_key" in os.environ:
8987
crowdin_api_key = os.environ["crowdin_api_key"]
90-
9188
if not crowdin_api_key:
9289
print('Missing crowdin_api_key. Cannot push.')
93-
sys.exit(0)
90+
sys.exit(1)
9491
print('Found crowdin_api_key. Will push updated source-strings to crowdin.')
9592

9693
crowdin_project_id = 20482 # for "Electrum" project on crowdin
@@ -100,24 +97,30 @@ crowdin_file_id = 68 # for "/electrum-client/messages.pot"
10097
global_headers = {"Authorization": "Bearer {}".format(crowdin_api_key)}
10198

10299
# client.storages.add_storage(f)
100+
# https://support.crowdin.com/developer/api/v2/?q=api#tag/Storage/operation/api.storages.post
103101
print(f"Uploading to temp storage...")
104102
url = f'https://api.crowdin.com/api/v2/storages'
105103
with open(locale_file_name, 'rb') as f:
106104
headers = {**global_headers, **{"Crowdin-API-FileName": crowdin_file_name}}
107105
response = requests.request("POST", url, data=f, headers=headers)
106+
response.raise_for_status()
108107
print("", "storages.add_storage:", "-" * 20, response.text, "-" * 20, sep="\n")
109108
storage_id = response.json()["data"]["id"]
110109

111110
# client.source_files.update_file(projectId=crowdin_project_id, storageId=storage_id, fileId=crowdin_file_id)
111+
# https://support.crowdin.com/developer/api/v2/?q=api#tag/Source-Files/operation/api.projects.files.put
112112
print(f"Copying from temp storage and updating file in perm storage...")
113113
url = f'https://api.crowdin.com/api/v2/projects/{crowdin_project_id}/files/{crowdin_file_id}'
114114
headers = {**global_headers, **{"content-type": "application/json"}}
115115
response = requests.request("PUT", url, json={"storageId": storage_id}, headers=headers)
116+
response.raise_for_status()
116117
print("", "source_files.update_file:", "-" * 20, response.text, "-" * 20, sep="\n")
117118

118119
# client.translations.build_crowdin_project_translation(projectId=crowdin_project_id)
120+
# https://support.crowdin.com/developer/api/v2/?q=api#tag/Translations/operation/api.projects.translations.builds.post
119121
print(f"Rebuilding translations...")
120122
url = f'https://api.crowdin.com/api/v2/projects/{crowdin_project_id}/translations/builds'
121123
headers = {**global_headers, **{"content-type": "application/json"}}
122124
response = requests.request("POST", url, headers=headers)
125+
response.raise_for_status()
123126
print("", "translations.build_crowdin_project_translation:", "-" * 20, response.text, "-" * 20, sep="\n")

0 commit comments

Comments
 (0)