Skip to content

Commit 8cea780

Browse files
committed
improve error handling
1 parent b3e34b1 commit 8cea780

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

generate.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# /// script
2+
# dependencies = [
3+
# "gitpython",
4+
# "potodo",
5+
# "jinja2",
6+
# ]
7+
# ///
8+
from pathlib import Path
9+
from shutil import rmtree
10+
from tempfile import TemporaryDirectory
11+
from git import Repo, GitCommandError
12+
from potodo.potodo import scan_path
13+
from jinja2 import Template
14+
15+
completion_progress = []
16+
17+
with TemporaryDirectory() as tmpdir:
18+
for language in ('es', 'fr', 'id', 'it', 'ja', 'ko', 'pl', 'pt-br', 'tr', 'uk', 'zh-cn', 'zh-tw'):
19+
clone_path = Path(tmpdir, language)
20+
for branch in ('3.13', '3.12', '3.11', '3.10', '3.9'):
21+
try:
22+
Repo.clone_from(f'[email protected]:python/python-docs-{language}.git', clone_path, depth=1, branch=branch)
23+
except GitCommandError as e:
24+
print(f'failed to clone {language} {branch}')
25+
continue
26+
try:
27+
completion = scan_path(clone_path, no_cache=True, hide_reserved=False, api_url='').completion
28+
except OSError:
29+
print(f'failed to scan {language} {branch}')
30+
rmtree(clone_path)
31+
continue
32+
else:
33+
break
34+
completion_progress.append((language, completion, branch))
35+
print(completion_progress[-1])
36+
37+
template = Template("""
38+
<html lang="en">
39+
<body>
40+
<table>
41+
<tr><th>language</th><th>completion</th><th>branch</th></tr>
42+
{% for language, completion, branch in completion_progress | sort(attribute=1) | reverse %}
43+
<tr><td>{{ language }}</td><td>{{ completion | round(2) }}</td><td>{{ branch }}</td></tr>
44+
{% endfor %}
45+
</table>
46+
</body>
47+
</html>
48+
""")
49+
50+
output = template.render(completion_progress=completion_progress)
51+
52+
with open("index.html", "w") as file:
53+
file.write(output)

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
<tr><td>pl</td><td>5.57</td><td>3.13</td></tr>
2828

29-
<tr><td>it</td><td>0.0</td><td>3.13</td></tr>
29+
<tr><td>it</td><td>5.44</td><td>3.12</td></tr>
3030

3131
</table>
3232
</body>

0 commit comments

Comments
 (0)