Skip to content

Commit

Permalink
export terms in docs directory
Browse files Browse the repository at this point in the history
Update README.md
  • Loading branch information
cmd-E committed Apr 29, 2021
1 parent fec1d12 commit 51ec302
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,23 @@
- Запустить `main.py` из коммандной строки
- Задать необходимое колличество терминов
- Выбрать язык
- Забрать термины из `glossary.txt` (находится в директории с `main.py`)
- Забрать термины из `docs/glossary_**.txt` или `docs/glossary_**.docx` (находится в директории с `main.py`)
```console
me@pc:~$ python3 main.py
Колличество терминов (1-500): 500
Язык(РУС/каз):
Загрузка терминов...
100%|████████████████████████████████████████████████████████████████████████████████| 788k/788k [00:01<00:00, 771kiB/s]
Парсинг терминов...
Выбор случайных терминов...
Экспорт в docs/glossary_ru.txt...
Экспорт в docs/glossary_ru.docx...
100%|████████████████████████████████████████████████████████████████████████████████| 302/302 [00:02<00:00, 132.63it/s]
```


# Зависимости
`requests`, `BeautifulSoup`, `python-docx`

Установить всё: `py -m pip install -r requirements.txt`

Установить всё: `python3 -m pip install -r requirements.txt`
9 changes: 5 additions & 4 deletions terms_exporter.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os.path
import sys
import docx
from tqdm import tqdm
Expand All @@ -7,9 +8,9 @@ class TermsExporter:
@classmethod
def doc_export(cls, terms: list, lang: str):
if lang.lower() == "рус":
filename = "glossary_ru.docx"
filename = "docs/glossary_ru.docx"
else:
filename = "glossary_kz.docx"
filename = "docs/glossary_kz.docx"
print(f"Экспорт в {filename}...")
for i in range(len(terms)):
terms[i] = terms[i].split(" - ", 1)
Expand Down Expand Up @@ -43,9 +44,9 @@ def doc_export(cls, terms: list, lang: str):
@classmethod
def export_terms_to_txt(cls, selected_terms: list, lang: str):
if lang.lower() == "рус":
txt_filename = "glossary_ru.txt"
txt_filename = "docs/glossary_ru.txt"
else:
txt_filename = "glossary_kz.txt"
txt_filename = "docs/glossary_kz.txt"
print(f"Экспорт в {txt_filename}...")
with open(txt_filename, "w", encoding="UTF-8") as glossaryFile:
for term in selected_terms:
Expand Down
4 changes: 3 additions & 1 deletion terms_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def get_terms(cls) -> list:
@staticmethod
def __load_raw_terms() -> list:
url = "http://libr.aues.kz/facultet/frts/kaf_aes/52/umm/aes_1.htm"
html_filename = 'terms_origin.html'
if not os.path.isdir("docs"):
os.mkdir("docs")
html_filename = 'docs/terms_origin.html'
if not os.path.isfile(html_filename):
print('Загрузка терминов...')
try:
Expand Down

0 comments on commit 51ec302

Please sign in to comment.