ezKit 2.0.32__tar.gz → 2.0.34__tar.gz
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-2.0.32/ezKit.egg-info → ezkit-2.0.34}/PKG-INFO +1 -1
- {ezkit-2.0.32 → ezkit-2.0.34}/ezKit/utils.py +74 -0
- {ezkit-2.0.32 → ezkit-2.0.34/ezKit.egg-info}/PKG-INFO +1 -1
- {ezkit-2.0.32 → ezkit-2.0.34}/setup.py +1 -1
- {ezkit-2.0.32 → ezkit-2.0.34}/LICENSE +0 -0
- {ezkit-2.0.32 → ezkit-2.0.34}/MANIFEST.in +0 -0
- {ezkit-2.0.32 → ezkit-2.0.34}/README.md +0 -0
- {ezkit-2.0.32 → ezkit-2.0.34}/ezKit/__init__.py +0 -0
- {ezkit-2.0.32 → ezkit-2.0.34}/ezKit/__zabbix.py +0 -0
- {ezkit-2.0.32 → ezkit-2.0.34}/ezKit/asyncdatabase.py +0 -0
- {ezkit-2.0.32 → ezkit-2.0.34}/ezKit/bandwagon.py +0 -0
- {ezkit-2.0.32 → ezkit-2.0.34}/ezKit/cipher.py +0 -0
- {ezkit-2.0.32 → ezkit-2.0.34}/ezKit/database.py +0 -0
- {ezkit-2.0.32 → ezkit-2.0.34}/ezKit/errorcode.py +0 -0
- {ezkit-2.0.32 → ezkit-2.0.34}/ezKit/fastapix.py +0 -0
- {ezkit-2.0.32 → ezkit-2.0.34}/ezKit/http.py +0 -0
- {ezkit-2.0.32 → ezkit-2.0.34}/ezKit/linux.py +0 -0
- {ezkit-2.0.32 → ezkit-2.0.34}/ezKit/redix.py +0 -0
- {ezkit-2.0.32 → ezkit-2.0.34}/ezKit/sendemail.py +0 -0
- {ezkit-2.0.32 → ezkit-2.0.34}/ezKit/stock.py +0 -0
- {ezkit-2.0.32 → ezkit-2.0.34}/ezKit.egg-info/SOURCES.txt +0 -0
- {ezkit-2.0.32 → ezkit-2.0.34}/ezKit.egg-info/dependency_links.txt +0 -0
- {ezkit-2.0.32 → ezkit-2.0.34}/ezKit.egg-info/requires.txt +0 -0
- {ezkit-2.0.32 → ezkit-2.0.34}/ezKit.egg-info/top_level.txt +0 -0
- {ezkit-2.0.32 → ezkit-2.0.34}/pyproject.toml +0 -0
- {ezkit-2.0.32 → ezkit-2.0.34}/setup.cfg +0 -0
|
@@ -11,6 +11,7 @@ from pathlib import Path
|
|
|
11
11
|
from typing import Any
|
|
12
12
|
from uuid import UUID
|
|
13
13
|
|
|
14
|
+
import markdown
|
|
14
15
|
import tomllib
|
|
15
16
|
from loguru import logger
|
|
16
17
|
|
|
@@ -510,3 +511,76 @@ def read_file(path: str) -> str:
|
|
|
510
511
|
return Path(path).read_text(encoding="utf-8").strip()
|
|
511
512
|
except Exception:
|
|
512
513
|
return ""
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
# --------------------------------------------------------------------------------------------------
|
|
517
|
+
|
|
518
|
+
|
|
519
|
+
def is_first_monday(date_object: date | None = None) -> bool:
|
|
520
|
+
"""判断是否是周一"""
|
|
521
|
+
# 判断当天是否为当月的第一个星期一, 可以通过检查两个条件来实现:
|
|
522
|
+
#
|
|
523
|
+
# 今天是星期一 (weekday() 等于 0)
|
|
524
|
+
# 日期在 1 号到 7 号之间 (每个月的第一个星期一必然出现在前 7 天)
|
|
525
|
+
#
|
|
526
|
+
# weekday() 返回 0-6, 0 代表星期一
|
|
527
|
+
# 且日期必须在 1-7 号之间
|
|
528
|
+
try:
|
|
529
|
+
if date_object is None:
|
|
530
|
+
date_object = date.today()
|
|
531
|
+
return date_object.weekday() == 0 and 1 <= date_object.day <= 7
|
|
532
|
+
except Exception as e:
|
|
533
|
+
if DEBUG:
|
|
534
|
+
logger.exception(e)
|
|
535
|
+
else:
|
|
536
|
+
logger.error(e)
|
|
537
|
+
return False
|
|
538
|
+
|
|
539
|
+
|
|
540
|
+
# --------------------------------------------------------------------------------------------------
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
def markdown_to_html(markdown_file: str, html_file: str, title: str) -> bool:
|
|
544
|
+
|
|
545
|
+
info: str = "将 Markdown 转换为 HTML"
|
|
546
|
+
|
|
547
|
+
try:
|
|
548
|
+
|
|
549
|
+
logger.info(f"{info} [开始]")
|
|
550
|
+
|
|
551
|
+
# 读取 HTML模版 文件
|
|
552
|
+
logger.info(f"{info} [读取 HTML模版 文件]")
|
|
553
|
+
html_template_file = f"{resolve_path(__file__,parents=1)}/markdown_to_html.template"
|
|
554
|
+
with open(html_template_file, "r", encoding="utf-8") as _:
|
|
555
|
+
html_template = _.read()
|
|
556
|
+
|
|
557
|
+
# 读取 Markdown 文件
|
|
558
|
+
logger.info(f"{info} [读取 Markdown 文件: {markdown_file}]")
|
|
559
|
+
with open(markdown_file, "r", encoding="utf-8") as _:
|
|
560
|
+
markdown_content = _.read()
|
|
561
|
+
|
|
562
|
+
# 将 Markdown 转换为 HTML
|
|
563
|
+
logger.info(f"{info} [将 Markdown 转换为 HTML]")
|
|
564
|
+
# pylint: disable=E0606
|
|
565
|
+
html_body = markdown.markdown(markdown_content, extensions=["tables"]) # type: ignore
|
|
566
|
+
# pylint: enable=E0606
|
|
567
|
+
|
|
568
|
+
# 构造完整的 HTML
|
|
569
|
+
logger.info(f"{info} [构造完整的 HTML]")
|
|
570
|
+
html_content = re.sub(r"\{title\}", title, html_template)
|
|
571
|
+
html_content = re.sub(r"\{body\}", html_body, html_content)
|
|
572
|
+
|
|
573
|
+
# 保存为 HTML 文件
|
|
574
|
+
logger.info(f"{info} [保存为 HTML 文件: {html_file}]")
|
|
575
|
+
with open(html_file, "w", encoding="utf-8") as _:
|
|
576
|
+
_.write(html_content)
|
|
577
|
+
|
|
578
|
+
logger.success(f"{info} [成功]")
|
|
579
|
+
return True
|
|
580
|
+
|
|
581
|
+
except Exception as e:
|
|
582
|
+
if DEBUG:
|
|
583
|
+
logger.exception(e)
|
|
584
|
+
else:
|
|
585
|
+
logger.error(e)
|
|
586
|
+
return False
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|