Skip to content

Commit c7e896f

Browse files
Apply automatic changes
0 parents  commit c7e896f

3 files changed

Lines changed: 44433 additions & 0 deletions

File tree

.github/workflows/update.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
on:
2+
schedule:
3+
- cron: '28 21 * * *'
4+
workflow_dispatch:
5+
6+
jobs:
7+
pull:
8+
runs-on: ubuntu-latest
9+
10+
permissions:
11+
contents: write
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
- run: python3 gen.py
16+
- uses: stefanzweifel/git-auto-commit-action@v5
17+
with:
18+
commit_author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
19+
commit_options: '--amend --no-edit'
20+
push_options: '--force'
21+
skip_fetch: true

gen.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import requests
2+
try:
3+
import ujson as json
4+
except ModuleNotFoundError:
5+
import json
6+
7+
SUPPORTED_DATABASE_VERSIONS = {6, 7}
8+
9+
with open('zh2en.json', 'r', encoding='UTF-8') as f:
10+
zh2en = json.load(f)
11+
12+
r = requests.get("https://cdn.jsdelivr.net/gh/EhTagTranslation/DatabaseReleases/db.text.json")
13+
r.raise_for_status()
14+
j = r.json()
15+
16+
version = j.get("version")
17+
if version not in SUPPORTED_DATABASE_VERSIONS:
18+
raise RuntimeError(
19+
f"Unsupported db.text.json version {version!r}; "
20+
f"supported versions: {sorted(SUPPORTED_DATABASE_VERSIONS)}"
21+
)
22+
23+
detrans_namespace = zh2en["namespace"]
24+
detrans_tag = zh2en["tag"]
25+
for namespace in j["data"]:
26+
detrans_namespace[namespace["frontMatters"]["name"]] = namespace["namespace"]
27+
detrans_tag[namespace["namespace"]] = detrans_tag.get(namespace["namespace"], {})
28+
for tag in namespace["data"]:
29+
detrans_tag[namespace["namespace"]][namespace["data"][tag]["name"]] = tag
30+
31+
with open('zh2en.json', 'w', encoding='UTF-8') as f:
32+
json.dump(zh2en, f, ensure_ascii=False, indent='\t')

0 commit comments

Comments
 (0)