从Git仓库移除.md文件但保留本地副本

This commit is contained in:
2026-04-26 20:28:19 +08:00
parent 7284386ded
commit d7c55d90ea
4 changed files with 911 additions and 12666 deletions

View File

@@ -1,51 +1,67 @@
import argparse
import re
with open(r'D:\Code\Python\followlist\source\output\reports\up_analysis_full_auto.md', 'r', encoding='utf-8') as f:
content = f.read()
# Pattern: Remove any bullet lines between '## N. xxx' section header and the next '### ' section
# Match: '## N.' followed by any content (not starting with '- '), then multiple ' - ' lines, then stop at '### '
# Use a pattern that captures from '## ' to the next '### '
# More specifically: match the block from '## N.' until the next '### ' that is NOT '### 最近10条标题'
# and remove any lines starting with ' - ' in between
lines = content.split('\n')
new_lines = []
i = 0
while i < len(lines):
line = lines[i]
new_lines.append(line)
# If we just added a section header '## N.'
if line.startswith('## '):
i += 1
# Skip lines until we hit either '### 最近10条标题' or another section marker
while i < len(lines):
curr = lines[i]
if curr.startswith('## '):
break
if curr.startswith('### '):
if '最近10条标题' in curr:
# Skip this title section and its bullets
i += 1 # skip '### 最近10条标题'
while i < len(lines) and lines[i].startswith(' - '):
i += 1
continue
else:
# This is another section like ### AI分析 - keep it
break
# Skip lines that are just basic info (主页, 标签, mid)
if curr.startswith('- ') and not curr.startswith(' - '):
i += 1
continue
# Skip actual bullet lines (the orphaned ones)
if curr.startswith(' - '):
i += 1
continue
new_lines.append(curr)
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(description="删除最近10条标题内容")
parser.add_argument(
"--input",
default="source/output/reports/up_analysis_full_auto.md",
help="输入报告路径",
)
parser.add_argument(
"--output",
help="输出报告路径(默认覆盖输入)",
)
return parser.parse_args()
def main():
args = parse_args()
input_file = args.input
output_file = args.output or input_file
with open(input_file, 'r', encoding='utf-8') as f:
content = f.read()
lines = content.split('\n')
new_lines = []
i = 0
while i < len(lines):
line = lines[i]
new_lines.append(line)
if line.startswith('## '):
i += 1
else:
i += 1
result = '\n'.join(new_lines)
# Clean multiple blank lines
result = re.sub(r'\n{3,}', '\n\n', result)
with open(r'D:\Code\Python\followlist\source\output\reports\up_analysis_full_auto.md', 'w', encoding='utf-8') as f:
f.write(result)
print('Done')
while i < len(lines):
curr = lines[i]
if curr.startswith('## '):
break
if curr.startswith('### '):
if '最近10条标题' in curr:
i += 1
while i < len(lines) and lines[i].startswith(' - '):
i += 1
continue
else:
break
if curr.startswith('- ') and not curr.startswith(' - '):
i += 1
continue
if curr.startswith(' - '):
i += 1
continue
new_lines.append(curr)
i += 1
else:
i += 1
result = '\n'.join(new_lines)
result = re.sub(r'\n{3,}', '\n\n', result)
with open(output_file, 'w', encoding='utf-8') as f:
f.write(result)
print(f'Done: {output_file}')
return 0
if __name__ == "__main__":
raise SystemExit(main())