From 1069396e0792dcbe39dd0f555f15939b60aefe46 Mon Sep 17 00:00:00 2001 From: Empiriker <till.ueberfries@gmail.com> Date: Tue, 17 Oct 2023 17:06:43 +0300 Subject: [PATCH] Properly initialize Wtp object for non-english editions --- src/load_templates.py | 3 ++- src/wiktextract_context.py | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/load_templates.py b/src/load_templates.py index e3ee406..17e132b 100644 --- a/src/load_templates.py +++ b/src/load_templates.py @@ -64,7 +64,7 @@ def load_templates(wiktlang: str): is_done, msg=f"Loading templates for {wiktlang}..." ) - wxr = get_wiktextract_context(wiktlang) + wxr = get_wiktextract_context(wiktlang, mock_get_page=False) wxr.wtp.db_conn.execute("DELETE FROM pages") wxr.wtp.db_conn.commit() @@ -81,6 +81,7 @@ def load_templates(wiktlang: str): out_f=None, # type: ignore ) wxr.wtp.db_conn.commit() + wxr.wtp.close_db_conn() stop_progress_indicator(indicator_thread, is_done) diff --git a/src/wiktextract_context.py b/src/wiktextract_context.py index e1abb42..79d08e0 100644 --- a/src/wiktextract_context.py +++ b/src/wiktextract_context.py @@ -31,7 +31,7 @@ class CustomWtp(Wtp): return original_result -def get_wiktextract_context(wiktlang: str, wordlang: Optional[str] = None): +def get_wiktextract_context(wiktlang: str, wordlang: Optional[str] = None, mock_get_page: bool = True): db_path = f"./sqlite-{wiktlang}.db" config = WiktionaryConfig( dump_file_lang_code=wiktlang, @@ -46,6 +46,8 @@ def get_wiktextract_context(wiktlang: str, wordlang: Optional[str] = None): capture_descendants=True, capture_inflections=True, ) - wxr = WiktextractContext(CustomWtp(db_path=db_path), config) + config.load_edition_settings() + wtp = CustomWtp(db_path=db_path, lang_code=wiktlang) if mock_get_page else Wtp(db_path=db_path, lang_code=wiktlang) + wxr = WiktextractContext(wtp, config) return wxr -- GitLab