Skip to content

Commit b7412e5

Browse files
committed
Add links
1 parent c6e7ee3 commit b7412e5

File tree

4 files changed

+69
-20
lines changed

4 files changed

+69
-20
lines changed

completion.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import pathlib
2+
import shutil
3+
4+
import git
5+
from potodo import potodo
6+
7+
8+
def get_completion_and_branch(tmpdir: str, language: str) -> tuple[float, str]:
9+
clone_path = pathlib.Path(tmpdir, language)
10+
for branch in ('3.13', '3.12', '3.11', '3.10', '3.9'):
11+
try:
12+
git.Repo.clone_from(f'https://github.com/python/python-docs-{language}.git', clone_path, depth=1, branch=branch)
13+
except git.GitCommandError:
14+
print(f'failed to clone {language} {branch}')
15+
continue
16+
try:
17+
completion = potodo.scan_path(clone_path, no_cache=True, hide_reserved=False, api_url='').completion
18+
except OSError:
19+
print(f'failed to scan {language} {branch}')
20+
shutil.rmtree(clone_path)
21+
continue
22+
else:
23+
break
24+
return completion, branch

generate.py

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,36 @@
33
# "gitpython",
44
# "potodo",
55
# "jinja2",
6+
# "requests",
7+
# "humanize",
68
# ]
79
# ///
10+
import csv
11+
import io
12+
import zipfile
813
from datetime import datetime, timezone
914
from pathlib import Path
1015
from shutil import rmtree
1116
from tempfile import TemporaryDirectory
17+
from urllib.parse import urlencode
18+
19+
import humanize
20+
import requests
1221
from git import Repo, GitCommandError
1322
from potodo.potodo import scan_path
1423
from jinja2 import Template
1524

25+
import completion
26+
import visitors
27+
1628
completion_progress = []
1729
generation_time = datetime.now(timezone.utc)
1830

1931
with TemporaryDirectory() as tmpdir:
2032
for language in ('es', 'fr', 'id', 'it', 'ja', 'ko', 'pl', 'pt-br', 'tr', 'uk', 'zh-cn', 'zh-tw'):
21-
clone_path = Path(tmpdir, language)
22-
for branch in ('3.13', '3.12', '3.11', '3.10', '3.9'):
23-
try:
24-
Repo.clone_from(f'https://github.com/python/python-docs-{language}.git', clone_path, depth=1, branch=branch)
25-
except GitCommandError:
26-
print(f'failed to clone {language} {branch}')
27-
continue
28-
try:
29-
completion = scan_path(clone_path, no_cache=True, hide_reserved=False, api_url='').completion
30-
except OSError:
31-
print(f'failed to scan {language} {branch}')
32-
rmtree(clone_path)
33-
continue
34-
else:
35-
break
36-
completion_progress.append((language, completion, branch))
33+
completion_number, branch = completion.get_completion_and_branch(tmpdir, language)
34+
visitors_number = visitors.get_number_of_visitors(language)
35+
completion_progress.append((language, completion_number, branch, visitors_number))
3736
print(completion_progress[-1])
3837

3938
template = Template("""
@@ -46,16 +45,26 @@
4645
<h1>Python Docs Translation Dashboard</h1>
4746
<table>
4847
<thead>
49-
<tr><th>language</th><th>branch</th><th>completion</th></tr>
48+
<tr>
49+
<th>language</th>
50+
<th><a href="https://plausible.io/data-policy#how-we-count-unique-users-without-cookies">visitors<a/></th>
51+
<th>branch</th>
52+
<th>completion</th>
53+
</tr>
5054
</thead>
5155
<tbody>
52-
{% for language, completion, branch in completion_progress | sort(attribute=1) | reverse %}
56+
{% for language, completion, branch, visitors in completion_progress | sort(attribute=1) | reverse %}
5357
<tr>
5458
<td data-label="language">
5559
<a href="https://github.com/python/python-docs-{{ language }}" target="_blank">
5660
{{ language }}
5761
</a>
5862
</td>
63+
<td data-label="visitors">
64+
<a href="https://https://plausible.io/docs.python.org?filters=((contains,page,(/{{ language }}/)))" target="_blank">
65+
{{ visitors }}
66+
</a>
67+
</td>
5968
<td data-label="branch">{{ branch }}</td>
6069
<td data-label="completion">
6170
<div class="progress-bar" style="width: {{ completion | round(2) }}%;">{{ completion | round(2) }}%</div>

style.css

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ th, td {
99
border: 1px solid #ddd;
1010
padding: 8px 12px;
1111
text-align: left;
12+
white-space: nowrap;
1213
}
1314
th {
1415
background-color: #f4f4f4;
@@ -24,7 +25,7 @@ th {
2425
min-width: 50px;
2526
box-sizing: border-box;
2627
}
27-
td:nth-child(3) {
28+
td:last-child {
2829
width: 100%;
2930
}
3031
@media screen and (max-width: 600px) {
@@ -52,7 +53,7 @@ td:nth-child(3) {
5253
left: 10px;
5354
position: absolute;
5455
}
55-
td:nth-child(3) {
56+
td:last-child {
5657
width: inherit;
5758
}
5859
.progress-bar {

visitors.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import csv
2+
import io
3+
import urllib
4+
import zipfile
5+
6+
import humanize
7+
import requests
8+
9+
10+
def get_number_of_visitors(language: str) -> str:
11+
param = urllib.parse.urlencode({'filters': f'[["contains","event:page",["/{language}/"]]]'})
12+
r = requests.get(f'https://plausible.io/docs.python.org/export?{param}', timeout=10)
13+
with zipfile.ZipFile(io.BytesIO(r.content), 'r') as z, z.open('visitors.csv') as csv_file:
14+
csv_reader = csv.DictReader(io.TextIOWrapper(csv_file))
15+
return humanize.intword(sum(int(row["visitors"]) for row in csv_reader))

0 commit comments

Comments
 (0)