From 740fafcc821efd83a61cec80afb3b4a577cf44df Mon Sep 17 00:00:00 2001 From: stualan <128948691+stualan@users.noreply.github.com> Date: Tue, 19 Nov 2024 15:33:15 +0800 Subject: [PATCH] Update sync_status_readme.py --- sync_status_readme.py | 44 ++++++++++++------------------------------- 1 file changed, 12 insertions(+), 32 deletions(-) diff --git a/sync_status_readme.py b/sync_status_readme.py index 62122d9..6dc6e0c 100644 --- a/sync_status_readme.py +++ b/sync_status_readme.py @@ -8,9 +8,9 @@ # Constants START_DATE = datetime.fromisoformat(os.environ.get( - 'START_DATE', '2024-10-08T00:00:00+00:00')).replace(tzinfo=pytz.UTC) + 'START_DATE', '2024-06-24T00:00:00+00:00')).replace(tzinfo=pytz.UTC) END_DATE = datetime.fromisoformat(os.environ.get( - 'END_DATE', '2024-10-28T23:59:59+00:00')).replace(tzinfo=pytz.UTC) + 'END_DATE', '2024-07-14T23:59:59+00:00')).replace(tzinfo=pytz.UTC) DEFAULT_TIMEZONE = 'Asia/Shanghai' FILE_SUFFIX = os.environ.get('FILE_SUFFIX', '.md') README_FILE = 'README.md' @@ -80,46 +80,26 @@ def get_user_timezone(file_content): return pytz.timezone(DEFAULT_TIMEZONE) -# def extract_content_between_markers(file_content): -# start_index = file_content.find(Content_START_MARKER) -# end_index = file_content.find(Content_END_MARKER) -# if start_index == -1 or end_index == -1: -# logging.warning("Content_START_MARKER markers not found in the file") -# return "" -# return file_content[start_index + len(Content_START_MARKER):end_index].strip() - - def extract_content_between_markers(file_content): - first_start = file_content.find(Content_START_MARKER) - if first_start == -1: - logging.warning("Content_START_MARKER not found in the file") - return "" - - # 从第一个标记之后开始搜索第二个标记对 - second_start = file_content.find(Content_START_MARKER, first_start + len(Content_START_MARKER)) - if second_start == -1: - logging.warning("Second Content_START_MARKER not found in the file") - return "" - - end_index = file_content.find(Content_END_MARKER, second_start) - if end_index == -1: - logging.warning("Content_END_MARKER not found after second start marker") + start_index = file_content.find(Content_START_MARKER) + end_index = file_content.find(Content_END_MARKER) + if start_index == -1 or end_index == -1: + logging.warning("Content_START_MARKER markers not found in the file") return "" - - return file_content[second_start + len(Content_START_MARKER):end_index].strip() + return file_content[start_index + len(Content_START_MARKER):end_index].strip() def find_date_in_content(content, local_date): date_patterns = [ r'###\s*' + local_date.strftime("%Y.%m.%d"), r'###\s*' + local_date.strftime("%Y.%m.%d").replace('.0', '.'), - r'###\s*' + local_date.strftime("%m.%d").lstrip('0').replace('.0', '.'), + r'###\s*' + + local_date.strftime("%m.%d").lstrip('0').replace('.0', '.'), r'###\s*' + local_date.strftime("%Y/%m/%d"), - r'###\s*' + local_date.strftime("%m/%d").lstrip('0').replace('/0', '/'), - r'###\s*' + local_date.strftime("%m.%d").zfill(5), - r'###\s*' + local_date.strftime("%Y.%m.%d") # 新增:完整年月日格式 + r'###\s*' + + local_date.strftime("%m/%d").lstrip('0').replace('/0', '/'), + r'###\s*' + local_date.strftime("%m.%d").zfill(5) ] - combined_pattern = '|'.join(date_patterns) return re.search(combined_pattern, content)