MCPcopy
hub / github.com/chinesehuazhou/python-weekly / update_word_count

Function update_word_count

resources/weekly_workflow.py:498–512  ·  view source on GitHub ↗

更新文件中的字数统计 :param file_path: 文件路径 :param word_count: 字数统计结果

(file_path, word_count)

Source from the content-addressed store, hash-verified

496 return len(words)
497
498def update_word_count(file_path, word_count):
499 """
500 更新文件中的字数统计
501 :param file_path: 文件路径
502 :param word_count: 字数统计结果
503 """
504 print("Updating word count in the file...")
505 with open(file_path, 'r', encoding='utf-8') as f:
506 content = f.read()
507
508 # 使用正则表达式替换字数,同时处理有数字和无数字的情况
509 updated_content = re.sub(r'全文(\s*?)(\d+)?(\s*?)字', f'全文 {word_count} 字', content)
510
511 with open(file_path, 'w', encoding='utf-8') as f:
512 f.write(updated_content)
513
514def copy_to_archive(source_file, pub_date):
515 """

Callers 1

process_weeklyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected