Skip to content

Commit

Permalink
Merge pull request #182 from web3suggest/main
Browse files Browse the repository at this point in the history
Update sync_status_readme.py
  • Loading branch information
muxin-web3 authored Dec 7, 2024
2 parents a44ef46 + 740fafc commit 1a3f434
Showing 1 changed file with 12 additions and 32 deletions.
44 changes: 12 additions & 32 deletions sync_status_readme.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 1a3f434

Please sign in to comment.