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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ezKit
3
- Version: 2.0.32
3
+ Version: 2.0.34
4
4
  Summary: Easy Kit
5
5
  Author: septvean
6
6
  Author-email: septvean@gmail.com
@@ -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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ezKit
3
- Version: 2.0.32
3
+ Version: 2.0.34
4
4
  Summary: Easy Kit
5
5
  Author: septvean
6
6
  Author-email: septvean@gmail.com
@@ -4,7 +4,7 @@ from setuptools import find_packages, setup
4
4
 
5
5
  setup(
6
6
  name="ezKit",
7
- version="2.0.32",
7
+ version="2.0.34",
8
8
  author="septvean",
9
9
  author_email="septvean@gmail.com",
10
10
  description="Easy Kit",
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