Move Yomichan index and tag metadata to data file

This commit is contained in:
stephenmk 2023-04-22 14:14:28 -05:00
parent 90eb5dc285
commit e73c4d3d7f
No known key found for this signature in database
GPG key ID: B6DA730DB06235F1
3 changed files with 50 additions and 31 deletions

View file

@ -27,6 +27,12 @@ def yomichan_inflection_categories():
return data return data
def yomichan_metadata():
file_name = "yomichan_metadata.json"
data = __load_json(file_name)
return data
def __default_config(): def __default_config():
file_name = "default_config.json" file_name = "default_config.json"
data = __load_json(file_name) data = __load_json(file_name)

View file

@ -1,46 +1,31 @@
import json import json
import os import os
import shutil import shutil
import uuid
from pathlib import Path from pathlib import Path
from datetime import datetime from datetime import datetime
from platformdirs import user_documents_dir, user_cache_dir from platformdirs import user_documents_dir, user_cache_dir
import bot.data as Data
def jitenon_yoji(entries): def jitenon_yoji(entries):
terms, modified_date, attribution = __terms(entries) __jitenon(entries, "jitenon-yoji")
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)
def jitenon_kotowaza(entries): def jitenon_kotowaza(entries):
__jitenon(entries, "jitenon-kotowaza")
def __jitenon(entries, name):
terms, modified_date, attribution = __terms(entries) terms, modified_date, attribution = __terms(entries)
index = { meta = Data.yomichan_metadata()
"title": "故事・ことわざ・慣用句オンライン",
"revision": f"jitenon-kotowaza.{modified_date}", index = meta[name]["index"]
"sequenced": True, index["revision"] = f"{name}.{modified_date}"
"format": 3, index["attribution"] = attribution
"url": "https://kotowaza.jitenon.jp/", tags = meta[name]["tags"]
"attribution": attribution,
} __create_zip(terms, index, tags)
__create_zip(terms, index)
def __terms(entries): def __terms(entries):
@ -56,7 +41,7 @@ def __terms(entries):
return terms, modified_date, attribution return terms, modified_date, attribution
def __create_zip(terms, index, tags=[]): def __create_zip(terms, index, tags):
cache_dir = user_cache_dir("jitenbot") cache_dir = user_cache_dir("jitenbot")
timestamp = datetime.now().strftime("%Y%m%d%H%M%S") timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
build_directory = os.path.join(cache_dir, f"build_{timestamp}") build_directory = os.path.join(cache_dir, f"build_{timestamp}")

View file

@ -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": []
}
}