Skip to content

Commit 11f7207

Browse files
committed
translations: adapt to newer TP website layout
1 parent 9cdbf28 commit 11f7207

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

Diff for: translations/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/venv
2+
/.mypy_cache

Diff for: translations/refresh-tp.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88
import semver
99
import subprocess
1010

11+
from typing import List, Dict
12+
1113
# $1: package name $2: version string
1214
matching_patt = r'(.*?)-(\d.*?).zh_CN'
1315
po_dl_url = 'https://translationproject.org/PO-files/{lang}/{fn}'
1416
po_name = '{pkg}-{ver}.{lang}.po'
1517
domain_url = 'https://translationproject.org/domain/index.html'
1618

1719

18-
def collect_local_info(dirname):
20+
def collect_local_info(dirname: str):
1921
files = []
2022
for f in os.listdir(dirname):
2123
if not os.path.isfile(os.path.join(dirname, f)):
@@ -32,11 +34,11 @@ def collect_local_info(dirname):
3234
return files
3335

3436

35-
def collect_remote_info():
37+
def collect_remote_info() -> Dict[str, str]:
3638
parser = html5lib.HTMLParser(tree=html5lib.getTreeBuilder("dom"))
3739
domain_data = requests.get(domain_url)
38-
domain_data = parser.parse(domain_data.text)
39-
nodes = domain_data.getElementsByTagName('tbody')[0]
40+
parsed = parser.parse(domain_data.text)
41+
nodes = parsed.getElementsByTagName('tbody')[0]
4042
nodes = nodes.childNodes
4143
head = True
4244
remote_data = {}
@@ -57,8 +59,12 @@ def download_po(pkg, ver, lang, folder='.'):
5759
po_file = po_name.format(pkg=pkg, ver=ver, lang=lang)
5860
po_url = po_dl_url.format(lang=lang, fn=po_file)
5961
logging.warning('Downloading %s...' % po_file)
62+
resp = requests.get(po_url)
63+
if resp.status_code not in range(200, 300):
64+
logging.error('Download error: %s' % resp.status_code)
65+
return
6066
with open(os.path.join(folder, po_file), 'wt') as f:
61-
f.write(requests.get(po_url).text)
67+
f.write(resp.text)
6268

6369

6470
def main():
@@ -73,10 +79,12 @@ def main():
7379
remote_ver = remote.get(f[0])
7480
if not remote_ver:
7581
logging.error('Local file %s not found in remote data' % f[0])
82+
continue
7683
if f[1] == remote_ver:
7784
continue
7885
try:
7986
if semver.compare(f[1], remote_ver) >= 0:
87+
logging.info('Local file %s is up to date' % f[0])
8088
continue
8189
except ValueError:
8290
pass

0 commit comments

Comments
 (0)