diff --git a/.gitignore b/.gitignore index 947ae6a..3daad31 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *.txt *.doc *.docx +*.html .idea/ __pycache__ diff --git a/terms_exporter.py b/terms_exporter.py index 42c3655..c03bc19 100644 --- a/terms_exporter.py +++ b/terms_exporter.py @@ -1,9 +1,16 @@ +import sys import docx +from tqdm import tqdm class TermsExporter: @classmethod def doc_export(cls, terms: list, lang: str): + if lang.lower() == "рус": + filename = "glossary_ru.docx" + else: + filename = "glossary_kz.docx" + print(f"Экспорт в {filename}...") for i in range(len(terms)): terms[i] = terms[i].split(" - ", 1) doc = docx.Document() @@ -21,7 +28,7 @@ def doc_export(cls, terms: list, lang: str): term = "" description = "" try: - for term, description in terms: + for term, description in tqdm(terms): row_cells = table.add_row().cells row_cells[0].text = term row_cells[1].text = description @@ -30,10 +37,7 @@ def doc_export(cls, terms: list, lang: str): print(f"Exception occurred: {sys.exc_info()[0]}") print(f"Term: {term} Description: {description} I: {i}") print(terms[i]) - if lang.lower() == "рус": - filename = "glossary_ru.docx" - else: - filename = "glossary_kz.docx" + doc.save(filename) @classmethod @@ -42,6 +46,7 @@ def export_terms_to_txt(cls, selected_terms: list, lang: str): txt_filename = "glossary_ru.txt" else: txt_filename = "glossary_kz.txt" + print(f"Экспорт в {txt_filename}...") with open(txt_filename, "w", encoding="UTF-8") as glossaryFile: for term in selected_terms: glossaryFile.write(term) diff --git a/terms_loader.py b/terms_loader.py index 0fa554e..7091783 100644 --- a/terms_loader.py +++ b/terms_loader.py @@ -1,6 +1,7 @@ import os.path import random import sys + import requests from bs4 import BeautifulSoup from app_config import AppConfig @@ -46,13 +47,13 @@ def __load_raw_terms() -> list: except: print("Unexpected error occurred while parsing response from glossary page: ", sys.exc_info()[0]) - print("Парсинг терминов...") trs = soup.find("table").find_all("tr") trs = trs[1:] return trs @classmethod def __parse_terms(cls, raw_terms: list, lang: str) -> list: + print("Парсинг терминов...") description = "" term = "" terms_list = [] @@ -90,6 +91,7 @@ def __parse_terms(cls, raw_terms: list, lang: str) -> list: @classmethod def __get_random_terms(cls, terms_list: list) -> list: + print("Выбор случайных терминов...") used_terms = [] selected_terms = [] for i in range(AppConfig.terms_count):