1
0
Files
ollama/rag/convert.py
AnthonyAxenov f3672e6ffd Много мелких доработок
- переименован input_md => data
- добавление инфы о дате, версии и авторе изменений conf-страницы в индекс
- вывод этой инфы в источниках
- вывод статистики последнего ответа
- указание имени коллекции для qdrant
- мелочи по текстовкам
2025-08-29 08:54:43 +08:00

26 lines
1.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
import argparse
from bs4 import BeautifulSoup
import markdownify
def convert_html_to_md(input_dir, output_dir):
os.makedirs(output_dir, exist_ok=True)
for filename in os.listdir(input_dir):
if filename.endswith(".html"):
input_path = os.path.join(input_dir, filename)
output_filename = os.path.splitext(filename)[0] + ".md"
output_path = os.path.join(output_dir, output_filename)
with open(input_path, "r", encoding="utf-8") as f:
html_content = f.read()
md_content = markdownify.markdownify(html_content, heading_style="ATX")
with open(output_path, "w", encoding="utf-8") as f:
f.write(md_content)
print(f"Готово: {output_path}")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Конвертер HTML-файлов в Markdown")
parser.add_argument("--input-dir", type=str, default="input_html", help="Директория с HTML-файлами для конвертации")
parser.add_argument("--output-dir", type=str, default="data", help="Директория для сохранения Markdown-файлов")
args = parser.parse_args()
convert_html_to_md(args.input_dir, args.output_dir)