diff --git a/bot/data.py b/bot/data.py index 9415eaa..291a9c9 100644 --- a/bot/data.py +++ b/bot/data.py @@ -7,7 +7,7 @@ from pathlib import Path from platformdirs import user_config_dir -def config(): +def load_config(): config_dir = user_config_dir("jitenbot") if not Path(config_dir).is_dir(): os.makedirs(config_dir) @@ -16,25 +16,25 @@ def config(): with open(config_file, "r") as f: config = json.load(f) else: - config = __default_config() + config = __load_default_config() with open(config_file, "w") as f: json.dump(config, f, indent=4) return config -def yomichan_inflection_categories(): +def load_yomichan_inflection_categories(): file_name = "yomichan_inflection_categories.json" data = __load_json(file_name) return data -def yomichan_metadata(): +def load_yomichan_metadata(): file_name = "yomichan_metadata.json" data = __load_json(file_name) return data -def variant_kanji(): +def load_variant_kanji(): def loader(data, row): data[row[0]] = row[1] file_name = "variant_kanji.csv" @@ -43,7 +43,7 @@ def variant_kanji(): return data -def __default_config(): +def __load_default_config(): file_name = "default_config.json" data = __load_json(file_name) return data diff --git a/bot/entries/jitenon.py b/bot/entries/jitenon.py index 9ba61ee..a6c33e8 100644 --- a/bot/entries/jitenon.py +++ b/bot/entries/jitenon.py @@ -2,7 +2,7 @@ import re from datetime import datetime, date from bs4 import BeautifulSoup -import bot.data as Data +from bot.data import load_variant_kanji import bot.expressions as Expressions @@ -11,12 +11,12 @@ class JitenonEntry: def __init__(self, entry_id): if self._VARIANT_KANJI is None: - self._VARIANT_KANJI = Data.variant_kanji() + self._VARIANT_KANJI = load_variant_kanji() self.entry_id = entry_id self.markup = "" self.modified_date = date(1970, 1, 1) self.attribution = "" - for column in self.COLUMNS.values(): + for column in self._COLUMNS.values(): setattr(self, column[0], column[1]) self._headwords = None @@ -74,7 +74,7 @@ class JitenonEntry: self.modified_date = date def __set_column(self, colname, colval): - attr_name = self.COLUMNS[colname][0] + attr_name = self._COLUMNS[colname][0] attr_value = getattr(self, attr_name) if isinstance(attr_value, str): setattr(self, attr_name, colval) @@ -130,7 +130,7 @@ class JitenonEntry: def __str__(self): colvals = [str(self.entry_id)] - for attr in self.COLUMNS.values(): + for attr in self._COLUMNS.values(): attr_val = getattr(self, attr[0]) if isinstance(attr_val, str): colvals.append(attr_val) @@ -140,7 +140,7 @@ class JitenonEntry: class JitenonYojiEntry(JitenonEntry): - COLUMNS = { + _COLUMNS = { "四字熟語": ["expression", ""], "読み方": ["yomikata", ""], "意味": ["imi", ""], @@ -160,7 +160,7 @@ class JitenonYojiEntry(JitenonEntry): class JitenonKotowazaEntry(JitenonEntry): - COLUMNS = { + _COLUMNS = { "言葉": ["expression", ""], "読み方": ["yomikata", ""], "意味": ["imi", ""], diff --git a/bot/scraper.py b/bot/scraper.py index 25060fa..98add3f 100644 --- a/bot/scraper.py +++ b/bot/scraper.py @@ -11,7 +11,7 @@ from urllib.parse import urlparse from requests.adapters import HTTPAdapter from requests.packages.urllib3.util.retry import Retry -import bot.data as Data +from bot.data import load_config class Scraper(): @@ -19,7 +19,7 @@ class Scraper(): def __init__(self): if self.__CONFIG is None: - self.__CONFIG = Data.config() + self.__CONFIG = load_config() pattern = r"^(?:([A-Za-z0-9.\-]+)\.)?" + self.domain + r"$" self.netloc_re = re.compile(pattern) self.__set_session() diff --git a/bot/yomichan/export.py b/bot/yomichan/export.py index b6ed7b1..35dcc38 100644 --- a/bot/yomichan/export.py +++ b/bot/yomichan/export.py @@ -5,7 +5,7 @@ from pathlib import Path from datetime import datetime from platformdirs import user_documents_dir, user_cache_dir -from bot.data import yomichan_metadata +from bot.data import load_yomichan_metadata from bot.yomichan.terms.jitenon import JitenonYojiTerminator from bot.yomichan.terms.jitenon import JitenonKotowazaTerminator @@ -17,7 +17,7 @@ class Exporter: self._terms_per_file = 2000 def export(self, entries): - meta = yomichan_metadata() + meta = load_yomichan_metadata() index = meta[self._name]["index"] index["revision"] = self._get_revision(entries) index["attribution"] = self._get_attribution(entries) diff --git a/bot/yomichan/grammar.py b/bot/yomichan/grammar.py index 1a47ade..a6a6286 100644 --- a/bot/yomichan/grammar.py +++ b/bot/yomichan/grammar.py @@ -1,7 +1,7 @@ from sudachipy import tokenizer from sudachipy import dictionary -import bot.data as Data +from bot.data import load_yomichan_inflection_categories __U_KANA_LIST = ["う", "く", "す", "つ", "ぬ", "ふ", "む", "ゆ", "る", "ぐ", "ず", "づ", "ぶ", "ぷ"] @@ -16,7 +16,7 @@ def sudachi_rules(expression): if __SUDACHI_DICTIONARY is None: __SUDACHI_DICTIONARY = dictionary.Dictionary(dict="full").create() if __SUDACHI_INFLECTION_TYPES is None: - categories = Data.yomichan_inflection_categories() + categories = load_yomichan_inflection_categories() __SUDACHI_INFLECTION_TYPES = categories["sudachi"] splitmode = tokenizer.Tokenizer.SplitMode.A tokens = __SUDACHI_DICTIONARY.tokenize(expression, splitmode) diff --git a/bot/yomichan/terms/jitenon.py b/bot/yomichan/terms/jitenon.py index 3a0388b..721d491 100644 --- a/bot/yomichan/terms/jitenon.py +++ b/bot/yomichan/terms/jitenon.py @@ -1,4 +1,4 @@ -import bot.yomichan.grammar as Grammar +from bot.yomichan.grammar import sudachi_rules from bot.yomichan.terms.terminator import Terminator from bot.yomichan.glossary.jitenon import make_glossary @@ -44,7 +44,7 @@ class JitenonKotowazaTerminator(JitenonTerminator): super().__init__() def _inflection_rules(self, entry, expression): - return Grammar.sudachi_rules(expression) + return sudachi_rules(expression) def _term_tags(self, entry): return ""