From e73c4d3d7fef089505f281543088b3f4ebb0b718 Mon Sep 17 00:00:00 2001 From: stephenmk Date: Sat, 22 Apr 2023 14:14:28 -0500 Subject: [PATCH] Move Yomichan index and tag metadata to data file --- bot/data.py | 6 +++++ bot/yomichan/export.py | 47 +++++++++++++------------------------ data/yomichan_metadata.json | 28 ++++++++++++++++++++++ 3 files changed, 50 insertions(+), 31 deletions(-) create mode 100644 data/yomichan_metadata.json diff --git a/bot/data.py b/bot/data.py index ec85287..1b7eeb1 100644 --- a/bot/data.py +++ b/bot/data.py @@ -27,6 +27,12 @@ def yomichan_inflection_categories(): return data +def yomichan_metadata(): + file_name = "yomichan_metadata.json" + data = __load_json(file_name) + return data + + def __default_config(): file_name = "default_config.json" data = __load_json(file_name) diff --git a/bot/yomichan/export.py b/bot/yomichan/export.py index 54bfc9e..c413b84 100644 --- a/bot/yomichan/export.py +++ b/bot/yomichan/export.py @@ -1,46 +1,31 @@ import json import os import shutil -import uuid from pathlib import Path from datetime import datetime - from platformdirs import user_documents_dir, user_cache_dir +import bot.data as Data + def jitenon_yoji(entries): - terms, modified_date, attribution = __terms(entries) - index = { - "title": "四字熟語辞典オンライン", - "revision": f"jitenon-yoji.{modified_date}", - "sequenced": True, - "format": 3, - "url": "https://yoji.jitenon.jp/", - "attribution": attribution, - } - tags = [ - ["1級", "frequent", 0, "漢字検定(漢検)1級の四字熟語", 0], - ["準1級", "frequent", 0, "漢字検定(漢検)準1級の四字熟語", 0], - ["2級", "frequent", 0, "漢字検定(漢検)2級の四字熟語", 0], - ["準2級", "frequent", 0, "漢字検定(漢検)準2級の四字熟語", 0], - ["3級", "frequent", 0, "漢字検定(漢検)3級の四字熟語", 0], - ["4級", "frequent", 0, "漢字検定(漢検)4級の四字熟語", 0], - ["5級", "frequent", 0, "漢字検定(漢検)5級の四字熟語", 0], - ] - __create_zip(terms, index, tags) + __jitenon(entries, "jitenon-yoji") def jitenon_kotowaza(entries): + __jitenon(entries, "jitenon-kotowaza") + + +def __jitenon(entries, name): terms, modified_date, attribution = __terms(entries) - index = { - "title": "故事・ことわざ・慣用句オンライン", - "revision": f"jitenon-kotowaza.{modified_date}", - "sequenced": True, - "format": 3, - "url": "https://kotowaza.jitenon.jp/", - "attribution": attribution, - } - __create_zip(terms, index) + meta = Data.yomichan_metadata() + + index = meta[name]["index"] + index["revision"] = f"{name}.{modified_date}" + index["attribution"] = attribution + tags = meta[name]["tags"] + + __create_zip(terms, index, tags) def __terms(entries): @@ -56,7 +41,7 @@ def __terms(entries): return terms, modified_date, attribution -def __create_zip(terms, index, tags=[]): +def __create_zip(terms, index, tags): cache_dir = user_cache_dir("jitenbot") timestamp = datetime.now().strftime("%Y%m%d%H%M%S") build_directory = os.path.join(cache_dir, f"build_{timestamp}") diff --git a/data/yomichan_metadata.json b/data/yomichan_metadata.json new file mode 100644 index 0000000..ab6a066 --- /dev/null +++ b/data/yomichan_metadata.json @@ -0,0 +1,28 @@ +{ + "jitenon-yoji": { + "index": { + "title": "四字熟語辞典オンライン", + "sequenced": true, + "format": 3, + "url": "https://yoji.jitenon.jp/" + }, + "tags": [ + ["1級", "frequent", 0, "漢字検定(漢検)1級の四字熟語", 0], + ["準1級", "frequent", 0, "漢字検定(漢検)準1級の四字熟語", 0], + ["2級", "frequent", 0, "漢字検定(漢検)2級の四字熟語", 0], + ["準2級", "frequent", 0, "漢字検定(漢検)準2級の四字熟語", 0], + ["3級", "frequent", 0, "漢字検定(漢検)3級の四字熟語", 0], + ["4級", "frequent", 0, "漢字検定(漢検)4級の四字熟語", 0], + ["5級", "frequent", 0, "漢字検定(漢検)5級の四字熟語", 0] + ] + }, + "jitenon-kotowaza": { + "index": { + "title": "故事・ことわざ・慣用句オンライン", + "sequenced": true, + "format": 3, + "url": "https://kotowaza.jitenon.jp/" + }, + "tags": [] + } +}