-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
136 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"version": "2024072712"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,4 @@ | ||
import os | ||
from datetime import datetime | ||
|
||
ROOT_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
|
||
# generate a DATA_VERSION (YYYYMMDDHH) | ||
DATA_VERSION = datetime.strftime(datetime.utcnow(), '%Y%m%d%H') | ||
|
||
print(DATA_VERSION) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,66 @@ | ||
import json | ||
import os | ||
|
||
from kancolle.models import slot_item | ||
import requests | ||
from kancolle.models import slot_item | ||
|
||
from script import ROOT_PATH, DATA_VERSION | ||
from script import ROOT_PATH | ||
|
||
|
||
def req_kcdata_json(): | ||
from kancolle.data import KC_DATA_URL | ||
ship_class_url = KC_DATA_URL + "slotitem/all.json" | ||
return requests.get(ship_class_url).json() | ||
class Localization: | ||
def __init__(self, version): | ||
self.version = version | ||
self.kcanotify_data_path = os.path.join(ROOT_PATH, 'repo', 'kcanotify-gamedata', 'files') | ||
|
||
def update_item_l10n(self): | ||
data_path = "slotitem/all.json" | ||
items = slot_item.load_slot_item_list(self.req_kcdata_json(data_path)) | ||
|
||
def load_kcanotify_l10n(): | ||
kcanotify_path = os.path.join(ROOT_PATH, 'repo', 'kcanotify-gamedata') | ||
kcanotify_data_path = os.path.join(kcanotify_path, 'files') | ||
item_en_path = os.path.join(kcanotify_data_path, 'items-en.json') | ||
item_ko_path = os.path.join(kcanotify_data_path, 'items-ko.json') | ||
item_sc_path = os.path.join(kcanotify_data_path, 'items-scn.json') | ||
item_tc_path = os.path.join(kcanotify_data_path, 'items-tcn.json') | ||
with open(item_en_path, 'r') as f: | ||
item_en = json.load(f) | ||
with open(item_ko_path, 'r') as f: | ||
item_ko = json.load(f) | ||
with open(item_sc_path, 'r') as f: | ||
item_sc = json.load(f) | ||
with open(item_tc_path, 'r') as f: | ||
item_tc = json.load(f) | ||
return item_en, item_ko, item_sc, item_tc | ||
result = {item.id: {"ja": item.name} for item in items} | ||
|
||
translations = self.load_kcanotify_l10n() | ||
|
||
def check_l10n(data): | ||
for item in data.values(): | ||
try: | ||
assert item.get("ja") is not None | ||
assert item.get("en") is not None | ||
assert item.get("ko") is not None | ||
assert item.get("sc") is not None | ||
assert item.get("tc") is not None | ||
except AssertionError: | ||
print(f'item {item["ja"]} is missing translation') | ||
raise | ||
for k, v in result.items(): | ||
for lang, translation in translations.items(): | ||
if v["ja"] in translation: | ||
result[k][lang] = translation[v["ja"]] | ||
|
||
self.check_l10n(result) | ||
|
||
if __name__ == '__main__': | ||
items = slot_item.load_slot_item_list(req_kcdata_json()) | ||
print(f'{len(result)} translations, {len(items)} items') | ||
|
||
l10n_dict = {} | ||
for item in items: | ||
l10n_dict[item.id] = {"ja": item.name} | ||
with open(os.path.join(ROOT_PATH, 'data', 'item_l10n.json'), 'w') as f: | ||
data = { | ||
"data_version": str(self.version), | ||
"data": result | ||
} | ||
json.dump(data, f, indent=2, ensure_ascii=False) | ||
|
||
item_en, item_ko, item_sc, item_tc = load_kcanotify_l10n() | ||
for k, v in l10n_dict.items(): | ||
if v["ja"] in item_en: | ||
l10n_dict[k]["en"] = item_en[v["ja"]] | ||
if v["ja"] in item_ko: | ||
l10n_dict[k]["ko"] = item_ko[v["ja"]] | ||
if v["ja"] in item_sc: | ||
l10n_dict[k]["sc"] = item_sc[v["ja"]] | ||
if v["ja"] in item_tc: | ||
l10n_dict[k]["tc"] = item_tc[v["ja"]] | ||
def load_kcanotify_l10n(self): | ||
kcanotify_data_path = self.kcanotify_data_path | ||
item_paths = { | ||
'en': os.path.join(kcanotify_data_path, 'items-en.json'), | ||
'ko': os.path.join(kcanotify_data_path, 'items-ko.json'), | ||
'sc': os.path.join(kcanotify_data_path, 'items-scn.json'), | ||
'tc': os.path.join(kcanotify_data_path, 'items-tcn.json') | ||
} | ||
translations = {} | ||
for lang, path in item_paths.items(): | ||
with open(path, 'r') as f: | ||
translations[lang] = json.load(f) | ||
return translations | ||
|
||
check_l10n(l10n_dict) | ||
@staticmethod | ||
def check_l10n(data): | ||
for item in data.values(): | ||
try: | ||
assert all(k in item for k in ['ja', 'en', 'ko', 'sc', 'tc']) | ||
except AssertionError: | ||
print(item) | ||
raise | ||
|
||
with open(os.path.join(ROOT_PATH, 'data', 'item_l10n.json'), 'w') as f: | ||
data = { | ||
"data_version": str(DATA_VERSION), | ||
"data": l10n_dict | ||
} | ||
json.dump(data, f, indent=2, ensure_ascii=False) | ||
@staticmethod | ||
def req_kcdata_json(path): | ||
from kancolle.data import KC_DATA_URL | ||
ship_class_url = KC_DATA_URL + path | ||
return requests.get(ship_class_url).json() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import json | ||
import os | ||
from datetime import datetime | ||
|
||
from script import ROOT_PATH | ||
from script import akashi_schedule | ||
from script.l10n import Localization | ||
|
||
if __name__ == '__main__': | ||
data_version = datetime.strftime(datetime.utcnow(), '%Y%m%d%H') | ||
print(data_version) | ||
|
||
l10n = Localization(data_version) | ||
l10n.update_item_l10n() | ||
|
||
akashi_schedule.update_schedule(data_version) | ||
|
||
data_version_path = os.path.join(ROOT_PATH, 'data', 'version.json') | ||
|
||
with open(data_version_path, 'w') as f: | ||
version_json = { | ||
"version": data_version | ||
} | ||
|
||
f.write(json.dumps(version_json)) | ||
|
||
print('finish') |