Skip to content

Commit

Permalink
Add progressbar for doc_export
Browse files Browse the repository at this point in the history
Add prints to indicate app state
  • Loading branch information
cmd-E committed Apr 29, 2021
1 parent 9042c25 commit ef3cc56
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.txt
*.doc
*.docx
*.html
.idea/
__pycache__
15 changes: 10 additions & 5 deletions terms_exporter.py
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
4 changes: 3 additions & 1 deletion terms_loader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os.path
import random
import sys

import requests
from bs4 import BeautifulSoup
from app_config import AppConfig
Expand Down Expand Up @@ -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 = []
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit ef3cc56

Please sign in to comment.