-
Notifications
You must be signed in to change notification settings - Fork 93
/
update.py
executable file
·50 lines (40 loc) · 1.37 KB
/
update.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
import os
import sys
import io
import zipfile
try:
import requests
except ImportError as e:
sys.exit(f"Error: {str(e)}. Try 'python3 -m pip install --user <module-name>'")
def pull_locale(path):
if not os.path.exists(path):
os.mkdir(path)
os.chdir(path)
# Download & unzip
print('Downloading translations...')
s = requests.request('GET', 'https://crowdin.com/backend/download/project/electrum.zip').content
zfobj = zipfile.ZipFile(io.BytesIO(s))
print('Unzipping translations...')
prefix = "electrum-client/locale/"
for name in zfobj.namelist():
if not name.startswith(prefix) or name == prefix:
continue
if name.endswith('/'):
if not os.path.exists(name[len(prefix):]):
os.mkdir(name[len(prefix):])
else:
with open(name[len(prefix):], 'wb') as output:
output.write(zfobj.read(name))
if __name__ == '__main__':
path_here = os.path.dirname(os.path.realpath(__file__))
path_locale = os.path.join(path_here, "locale")
pull_locale(path_locale)
print('Preparing git commit...')
os.chdir(path_here)
for lang in os.listdir('locale'):
po = 'locale/%s/electrum.po' % lang
cmd = "git add %s"%po
os.system(cmd)
os.system("git commit -a -m 'update translations'")
print("please push")