-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_dashboard.py
More file actions
executable file
Β·180 lines (158 loc) Β· 6.64 KB
/
Copy pathgenerate_dashboard.py
File metadata and controls
executable file
Β·180 lines (158 loc) Β· 6.64 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/usr/bin/env python3
import re
from pathlib import Path
ROOT = Path(__file__).parent
# Repositories configuration
REPOS = {
"advent-of-code": {
"title": "π Advent of Code",
"url": "https://github.com/LorranSutter/advent-of-code",
"branch": "main",
},
"everybody-codes": {
"title": "π¦ Everybody Codes",
"url": "https://github.com/LorranSutter/everybody-codes",
"branch": "main",
},
"flip-flop-codes": {
"title": "π Flip Flop Codes",
"url": "https://github.com/LorranSutter/flip-flop-codes",
"branch": "main",
},
"leet-code": {
"title": "π‘ LeetCode",
"url": "https://github.com/LorranSutter/leet-code",
"branch": "main",
},
"URI-Online-Judge": {
"title": "π URI Online Judge",
"url": "https://github.com/LorranSutter/URI-Online-Judge",
"branch": "main",
}
}
def extract_summary_block(readme_path: Path) -> str:
"""Extracts everything between <!-- SUMMARY:START --> and <!-- SUMMARY:END -->."""
if not readme_path.exists():
return ""
content = readme_path.read_text()
match = re.search(r"<!-- SUMMARY:START -->\s*(.*?)\s*<!-- SUMMARY:END -->", content, re.DOTALL)
if match:
return match.group(1).strip()
return ""
def rewrite_relative_links(text: str, repo_url: str, branch: str) -> str:
"""Replaces relative links like [name](./path) with absolute GitHub links."""
# Matches [text](./path/to/thing)
pattern = r"\[([^\]]+)\]\(\./([^\)]*)\)"
replacement = rf"[\1]({repo_url}/tree/{branch}/\2)"
return re.sub(pattern, replacement, text)
def parse_stats(text: str, repo_id: str):
"""Parses solved numbers from the 'Overall' line in the summary."""
if not text:
return None
if repo_id in ("advent-of-code", "everybody-codes", "flip-flop-codes"):
# Pattern: > **Overall: 95/100 parts solved (95%)**
match = re.search(r"Overall:\s*(\d+)/(\d+)\s*parts solved", text)
if match:
return {
"solved": int(match.group(1)),
"total": int(match.group(2)),
"type": "parts"
}
elif repo_id in ("leet-code", "URI-Online-Judge"):
# Try matching the badge format first: Solved%20Challenges-X-
match = re.search(r"Solved%20Challenges-(\d+)-", text)
if match:
return {
"solved": int(match.group(1)),
"total": None,
"type": "problems"
}
# Fallback pattern: > **Overall: X problems solved**
match = re.search(r"Overall:\s*(\d+)\s*problems solved", text)
if match:
return {
"solved": int(match.group(1)),
"total": None,
"type": "problems"
}
return None
def main():
dashboard_readme = ROOT / "README.md"
if not dashboard_readme.exists():
print(f"β οΈ README.md not found at {dashboard_readme}")
return
extracted_sections = {}
stats = {}
for repo_id, config in REPOS.items():
sibling_readme = ROOT.parent / repo_id / "README.md"
raw_summary = extract_summary_block(sibling_readme)
if raw_summary:
# Extract statistics
repo_stats = parse_stats(raw_summary, repo_id)
if repo_stats:
stats[repo_id] = repo_stats
# Clean up the local summary header (e.g. remove "## π Progress" since we make our own structure)
clean_summary = re.sub(r"^## π Progress\s*\n", "", raw_summary)
# Rewrite links
rewritten = rewrite_relative_links(clean_summary, config["url"], config["branch"])
extracted_sections[repo_id] = rewritten
else:
extracted_sections[repo_id] = f"*(No stats available for {config['title']})*"
# Build the dashboard content
lines = []
lines.append("## π Consolidated Progress")
lines.append("")
# Calculate Grand Totals
total_challenges = 0
aoc_solved = stats.get("advent-of-code", {}).get("solved", 0)
aoc_total = stats.get("advent-of-code", {}).get("total", 0)
ebc_solved = stats.get("everybody-codes", {}).get("solved", 0)
ebc_total = stats.get("everybody-codes", {}).get("total", 0)
ffc_solved = stats.get("flip-flop-codes", {}).get("solved", 0)
ffc_total = stats.get("flip-flop-codes", {}).get("total", 0)
lc_solved = stats.get("leet-code", {}).get("solved", 0)
uri_solved = stats.get("URI-Online-Judge", {}).get("solved", 0)
total_challenges = aoc_solved + ebc_solved + ffc_solved + lc_solved + uri_solved
# Overall Badge-like summary
lines.append(f"> ### π **Grand Total: {total_challenges} coding challenges completed!**")
lines.append(">")
if "advent-of-code" in stats:
lines.append(f"> - **Advent of Code**: {aoc_solved}/{aoc_total} parts ({aoc_solved/aoc_total*100:.1f}%)")
if "everybody-codes" in stats:
lines.append(f"> - **Everybody Codes**: {ebc_solved}/{ebc_total} parts ({ebc_solved/ebc_total*100:.1f}%)")
if "flip-flop-codes" in stats:
lines.append(f"> - **Flip Flop Codes**: {ffc_solved}/{ffc_total} parts ({ffc_solved/ffc_total*100:.1f}%)")
if "leet-code" in stats:
lines.append(f"> - **LeetCode**: {lc_solved} problems solved")
if "URI-Online-Judge" in stats:
lines.append(f"> - **URI Online Judge**: {uri_solved} problems solved")
lines.append("")
# Detail sections for each repo
for repo_id, config in REPOS.items():
lines.append(f"### [{config['title']}]({config['url']})")
lines.append("")
lines.append(extracted_sections[repo_id])
lines.append("")
lines.append("---")
lines.append("")
# Remove the trailing horizontal rule
if lines and lines[-2] == "---":
lines = lines[:-3]
unified_summary = "\n".join(lines).strip()
# Inject into the dashboard README
content = dashboard_readme.read_text()
start_marker = "<!-- SUMMARY:START -->"
end_marker = "<!-- SUMMARY:END -->"
block = f"{start_marker}\n{unified_summary}\n{end_marker}"
if start_marker in content and end_marker in content:
pattern = re.compile(
re.escape(start_marker) + r".*?" + re.escape(end_marker),
re.DOTALL,
)
new_content = pattern.sub(block, content)
dashboard_readme.write_text(new_content)
print(f"β
Successfully updated {dashboard_readme}")
else:
print("β Could not find markers in README.md. Please make sure <!-- SUMMARY:START --> and <!-- SUMMARY:END --> exist.")
if __name__ == "__main__":
main()