处理周刊的主函数 :param pub_date: 可选的发布日期,默认为当天 处理流程: 1. 拆分中英文版本(英文版自动保存到tmp目录,中文版覆盖原文件) 2. 统计中文版字数并更新 3. 复制中文版到项目归档目录 4. 生成中文版摘要文件(博客版和Github版) 5. 生成英文版摘要文件 6. 用已生成的中英摘要元数据更新 README 7. 发送消息版到Telegram 8. 自动公开 N-50 期全文(检测并替换 docs/ + astro-blog) 9. 自动调用 weekly_
(pub_date=None)
| 709 | |
| 710 | |
| 711 | def process_weekly(pub_date=None): |
| 712 | """ |
| 713 | 处理周刊的主函数 |
| 714 | :param pub_date: 可选的发布日期,默认为当天 |
| 715 | 处理流程: |
| 716 | 1. 拆分中英文版本(英文版自动保存到tmp目录,中文版覆盖原文件) |
| 717 | 2. 统计中文版字数并更新 |
| 718 | 3. 复制中文版到项目归档目录 |
| 719 | 4. 生成中文版摘要文件(博客版和Github版) |
| 720 | 5. 生成英文版摘要文件 |
| 721 | 6. 用已生成的中英摘要元数据更新 README |
| 722 | 7. 发送消息版到Telegram |
| 723 | 8. 自动公开 N-50 期全文(检测并替换 docs/ + astro-blog) |
| 724 | 9. 自动调用 weekly_save_count.py 刷新统计数据库 |
| 725 | """ |
| 726 | if pub_date is None: |
| 727 | pub_date = datetime.datetime.now().strftime('%Y-%m-%d') |
| 728 | |
| 729 | weekly_file = f'docs/{pub_date}-weekly.md' |
| 730 | tmp_en_file = f'docs/en/tmp/{pub_date}-weekly.md' |
| 731 | en_summary_file = f'docs/en/{pub_date}-weekly.md' |
| 732 | |
| 733 | if not os.path.exists(weekly_file): |
| 734 | print(f"File {weekly_file} does not exist.") |
| 735 | sys.exit(1) |
| 736 | |
| 737 | original_content_meta = get_front_matter(weekly_file) |
| 738 | weekly_no = extract_weekly_no(weekly_file) |
| 739 | |
| 740 | # 1. 拆分中英文版本 |
| 741 | print("1. Splitting Chinese and English versions...") |
| 742 | split_and_generate_files(weekly_file, tmp_en_file) |
| 743 | |
| 744 | # 2. 统计中文版字数并更新 |
| 745 | print("2. Counting words and updating...") |
| 746 | word_count = count_words(weekly_file) |
| 747 | update_word_count(weekly_file, word_count) |
| 748 | |
| 749 | # 3. 复制完整版文件到归档目录 |
| 750 | print("3. Copying files to archive...") |
| 751 | copy_to_archive(weekly_file, pub_date) |
| 752 | |
| 753 | # 4. 生成中文版周刊摘要 |
| 754 | print("4. Generating Chinese summary files...") |
| 755 | content_meta = get_front_matter(weekly_file) |
| 756 | content_body = content_to_string(read_md(weekly_file)) |
| 757 | write_to_md_file(weekly_no, content_meta, content_body, pub_date, weekly_file) |
| 758 | |
| 759 | # 5. 生成英文版周刊摘要 |
| 760 | print("5. Generating English blog summary...") |
| 761 | en_content_meta = None |
| 762 | if os.path.exists(tmp_en_file): |
| 763 | en_summary_file, en_content_meta = write_to_md_file_en(weekly_no, pub_date, tmp_en_file) |
| 764 | print(f"English blog summary generated: {en_summary_file}") |
| 765 | else: |
| 766 | print("Warning: English version file not found, skipping English summary generation.") |
| 767 | |
| 768 | # 6. 更新 README(使用已生成的中英周刊元数据) |
no test coverage detected