ezKit 1.11.8__py3-none-any.whl → 1.11.10__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ezKit/utils.py +58 -3
- {ezKit-1.11.8.dist-info → ezKit-1.11.10.dist-info}/METADATA +1 -1
- {ezKit-1.11.8.dist-info → ezKit-1.11.10.dist-info}/RECORD +6 -6
- {ezKit-1.11.8.dist-info → ezKit-1.11.10.dist-info}/LICENSE +0 -0
- {ezKit-1.11.8.dist-info → ezKit-1.11.10.dist-info}/WHEEL +0 -0
- {ezKit-1.11.8.dist-info → ezKit-1.11.10.dist-info}/top_level.txt +0 -0
ezKit/utils.py
CHANGED
@@ -3,9 +3,11 @@ import csv
|
|
3
3
|
import hashlib
|
4
4
|
import json
|
5
5
|
import os
|
6
|
+
import re
|
6
7
|
import subprocess
|
7
8
|
import time
|
8
9
|
import tomllib
|
10
|
+
from ast import literal_eval
|
9
11
|
from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor
|
10
12
|
from copy import deepcopy
|
11
13
|
from datetime import date, datetime, timedelta, timezone
|
@@ -16,6 +18,7 @@ from typing import Any, Callable
|
|
16
18
|
from urllib.parse import ParseResult, urlparse
|
17
19
|
from uuid import uuid4
|
18
20
|
|
21
|
+
import markdown
|
19
22
|
from loguru import logger
|
20
23
|
|
21
24
|
# --------------------------------------------------------------------------------------------------
|
@@ -73,11 +76,11 @@ def check_arguments(data: list) -> bool:
|
|
73
76
|
|
74
77
|
try:
|
75
78
|
if not isTrue(data, list):
|
76
|
-
logger.error(f"argument
|
79
|
+
logger.error(f"argument error: data {type(data)}")
|
77
80
|
return False
|
78
|
-
for arg, arg_type,
|
81
|
+
for arg, arg_type, info in data:
|
79
82
|
if not isTrue(arg, arg_type):
|
80
|
-
logger.error(f"argument
|
83
|
+
logger.error(f"argument error: {info} {type(arg)}")
|
81
84
|
return False
|
82
85
|
return True
|
83
86
|
except Exception as e:
|
@@ -1440,3 +1443,55 @@ def url_parse(
|
|
1440
1443
|
# logger.exception(exception)
|
1441
1444
|
# else:
|
1442
1445
|
# logger.error(exception)
|
1446
|
+
|
1447
|
+
|
1448
|
+
# --------------------------------------------------------------------------------------------------
|
1449
|
+
|
1450
|
+
|
1451
|
+
def markdown_to_html(markdown_file: str, html_file: str, title: str) -> bool:
|
1452
|
+
|
1453
|
+
info: str = "将 Markdown 转换为 HTML"
|
1454
|
+
|
1455
|
+
try:
|
1456
|
+
|
1457
|
+
logger.info(f"{info} [开始]")
|
1458
|
+
|
1459
|
+
if not check_arguments([
|
1460
|
+
(markdown_file, str, "markdown_to_html -> markdown_file"),
|
1461
|
+
(html_file, str, "markdown_to_html -> html_file"),
|
1462
|
+
(title, str, "markdown_to_html -> title"),
|
1463
|
+
]):
|
1464
|
+
return False
|
1465
|
+
|
1466
|
+
# 读取 HTML模版 文件
|
1467
|
+
logger.info(f"{info} [读取 HTML模版 文件]")
|
1468
|
+
html_template_file = f"{current_dir(__file__)}/markdown_to_html.template"
|
1469
|
+
with open(html_template_file, "r", encoding="utf-8") as _:
|
1470
|
+
html_template = _.read()
|
1471
|
+
|
1472
|
+
# 读取 Markdown 文件
|
1473
|
+
logger.info(f"{info} [读取 Markdown 文件: {markdown_file}]")
|
1474
|
+
with open(markdown_file, "r", encoding="utf-8") as _:
|
1475
|
+
markdown_content = _.read()
|
1476
|
+
|
1477
|
+
# 将 Markdown 转换为 HTML
|
1478
|
+
logger.info(f"{info} [将 Markdown 转换为 HTML]")
|
1479
|
+
html_body = markdown.markdown(markdown_content, extensions=['tables'])
|
1480
|
+
|
1481
|
+
# 构造完整的 HTML
|
1482
|
+
logger.info(f"{info} [构造完整的 HTML]")
|
1483
|
+
html_content = re.sub(r"\{title\}", title, html_template)
|
1484
|
+
html_content = re.sub(r"\{body\}", html_body, html_content)
|
1485
|
+
|
1486
|
+
# 保存为 HTML 文件
|
1487
|
+
logger.info(f"{info} [保存为 HTML 文件: {html_file}]")
|
1488
|
+
with open(html_file, "w", encoding='utf-8') as _:
|
1489
|
+
_.write(html_content)
|
1490
|
+
|
1491
|
+
logger.success(f"{info} [成功]")
|
1492
|
+
return True
|
1493
|
+
|
1494
|
+
except Exception as e:
|
1495
|
+
logger.error(f"{info} [错误]")
|
1496
|
+
logger.error(e)
|
1497
|
+
return False
|
@@ -10,10 +10,10 @@ ezKit/qywx.py,sha256=dGChIIf2V81MwufcPn6hwgSenPuxqK994KRH7ECT-CM,10387
|
|
10
10
|
ezKit/redis.py,sha256=tdiqfizPYQQTIUumkJGUJsJVlv0zVTSTYGQN0QutYs4,1963
|
11
11
|
ezKit/sendemail.py,sha256=47JTDFoLJKi0YtF3RAp9nFfo0ko2jlde3R_C1wr2E2w,7397
|
12
12
|
ezKit/token.py,sha256=HKREyZj_T2S8-aFoFIrBXTaCKExQq4zE66OHXhGHqQg,1750
|
13
|
-
ezKit/utils.py,sha256=
|
13
|
+
ezKit/utils.py,sha256=LnCWp8x0rllHeemIEMsOtubMBHI6OVkubINFEzcW4PY,43965
|
14
14
|
ezKit/xftp.py,sha256=izUH9pLH_AzgR3c0g8xSfhLn7LQ9EDcTst3LFjTM6hU,7878
|
15
|
-
ezKit-1.11.
|
16
|
-
ezKit-1.11.
|
17
|
-
ezKit-1.11.
|
18
|
-
ezKit-1.11.
|
19
|
-
ezKit-1.11.
|
15
|
+
ezKit-1.11.10.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
16
|
+
ezKit-1.11.10.dist-info/METADATA,sha256=5sKykTuUQWPzlqq8ywRE1zbGBDXr4QeWOb2SiSC8_ak,192
|
17
|
+
ezKit-1.11.10.dist-info/WHEEL,sha256=A3WOREP4zgxI0fKrHUG8DC8013e3dK3n7a6HDbcEIwE,91
|
18
|
+
ezKit-1.11.10.dist-info/top_level.txt,sha256=aYLB_1WODsqNTsTFWcKP-BN0KCTKcV-HZJ4zlHkCFw8,6
|
19
|
+
ezKit-1.11.10.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|