-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfill_missing.py
More file actions
114 lines (90 loc) · 3.55 KB
/
fill_missing.py
File metadata and controls
114 lines (90 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env python3
import os
import random
import subprocess
import datetime
from pathlib import Path
REPO_ROOT = Path(__file__).parent
def run_git(cmd):
return subprocess.run(cmd, cwd=REPO_ROOT, capture_output=True, text=True)
def get_safe_files():
safe_files = []
for ext in ['*.py', '*.md', '*.json', '*.txt', '*.yml', '*.html']:
for f in REPO_ROOT.rglob(ext):
if '__pycache__' in str(f) or '.git' in str(f):
continue
if any(x in str(f) for x in ['local_reports', 'analysis', 'assets']):
continue
try:
with open(f, 'r') as fp:
content = fp.read()
safe_files.append(f)
except:
pass
return safe_files
def create_commit(target_date, safe_files):
if not safe_files:
return False
f = random.choice(safe_files)
try:
with open(f, 'r', encoding='utf-8', errors='ignore') as fp:
content = fp.read()
new_content = content + f"\n# 补充提交 {random.randint(1, 1000)}\n"
with open(f, 'w', encoding='utf-8') as fp:
fp.write(new_content)
run_git(['git', 'add', str(f)])
dt = datetime.datetime.strptime(target_date, '%Y-%m-%d')
dt = dt.replace(hour=random.randint(9, 21), minute=random.randint(0, 59))
git_date = dt.strftime('%a %b %d %H:%M:%S %Y +0000')
env = os.environ.copy()
env['GIT_AUTHOR_DATE'] = git_date
env['GIT_COMMITTER_DATE'] = git_date
env['GIT_AUTHOR_NAME'] = 'norbertm2050'
env['GIT_AUTHOR_EMAIL'] = 'norbertm2050@gmail.com'
env['GIT_COMMITTER_NAME'] = 'norbertm2050'
env['GIT_COMMITTER_EMAIL'] = 'norbertm2050@gmail.com'
result = subprocess.run(
['git', 'commit', '-m', random.choice(['Update', 'Fix', 'Improve'])],
cwd=REPO_ROOT, env=env, capture_output=True, text=True
)
return result.returncode == 0
except:
return False
def main():
print("=== 补充缺失日期 ===\n")
run_git(['git', 'checkout', 'standalone-final'])
safe_files = get_safe_files()
# 获取已有日期
result = run_git(['git', 'log', '--format=%ad', '--date=short'])
existing = set(result.stdout.strip().split('\n'))
today = datetime.datetime.now().date()
start_date = today - datetime.timedelta(days=364)
# 找出缺失日期
missing = []
current = start_date
while current <= today:
ds = current.strftime('%Y-%m-%d')
if ds not in existing:
missing.append(ds)
current += datetime.timedelta(days=1)
print(f"缺失天数: {len(missing)}")
print(f"缺失日期: {missing[:10]}...\n")
# 补充提交
for date_str in missing:
for _ in range(random.randint(2, 4)):
create_commit(date_str, safe_files)
# 验证
result = run_git(['git', 'log', '--format=%ad', '--date=short'])
final_dates = set(result.stdout.strip().split('\n'))
coverage = sum(1 for d in final_dates
if start_date <= datetime.datetime.strptime(d, '%Y-%m-%d').date() <= today)
print(f"最终覆盖: {coverage}/365 天")
print(f"总提交数: {len(result.stdout.strip().split(chr(10)))}")
# 推送到GitHub
print("\n推送到GitHub...")
run_git(['git', 'push', '-u', 'fork', 'standalone-final:main', '--force'])
print("✅ 完成!")
if __name__ == "__main__":
main()
# 补充提交 156
# 补充提交 601