Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions completion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import pathlib
import shutil

import git
from potodo import potodo


def get_completion_and_branch(tmpdir: str, language: str) -> tuple[float, str]:
clone_path = pathlib.Path(tmpdir, language)
for branch in ('3.13', '3.12', '3.11', '3.10', '3.9'):
try:
git.Repo.clone_from(f'https://github.com/python/python-docs-{language}.git', clone_path, depth=1, branch=branch)
except git.GitCommandError:
print(f'failed to clone {language} {branch}')
continue
try:
completion = potodo.scan_path(clone_path, no_cache=True, hide_reserved=False, api_url='').completion
except OSError:
print(f'failed to scan {language} {branch}')
shutil.rmtree(clone_path)
continue
else:
break
return completion, branch
42 changes: 20 additions & 22 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,25 @@
# "gitpython",
# "potodo",
# "jinja2",
# "requests",
# ]
# ///
from datetime import datetime, timezone
from pathlib import Path
from shutil import rmtree
from tempfile import TemporaryDirectory
from git import Repo, GitCommandError
from potodo.potodo import scan_path

from jinja2 import Template

import completion
import visitors

completion_progress = []
generation_time = datetime.now(timezone.utc)

with TemporaryDirectory() as tmpdir:
for language in ('es', 'fr', 'id', 'it', 'ja', 'ko', 'pl', 'pt-br', 'tr', 'uk', 'zh-cn', 'zh-tw'):
clone_path = Path(tmpdir, language)
for branch in ('3.13', '3.12', '3.11', '3.10', '3.9'):
try:
Repo.clone_from(f'https://github.com/python/python-docs-{language}.git', clone_path, depth=1, branch=branch)
except GitCommandError:
print(f'failed to clone {language} {branch}')
continue
try:
completion = scan_path(clone_path, no_cache=True, hide_reserved=False, api_url='').completion
except OSError:
print(f'failed to scan {language} {branch}')
rmtree(clone_path)
continue
else:
break
completion_progress.append((language, completion, branch))
completion_number, branch = completion.get_completion_and_branch(tmpdir, language)
visitors_number = visitors.get_number_of_visitors(language)
completion_progress.append((language, completion_number, branch, visitors_number))
print(completion_progress[-1])

template = Template("""
Expand All @@ -46,16 +34,26 @@
<h1>Python Docs Translation Dashboard</h1>
<table>
<thead>
<tr><th>language</th><th>branch</th><th>completion</th></tr>
<tr>
<th>language</th>
<th><a href="https://plausible.io/data-policy#how-we-count-unique-users-without-cookies">visitors<a/></th>
<th>branch</th>
<th>completion</th>
</tr>
</thead>
<tbody>
{% for language, completion, branch in completion_progress | sort(attribute=1) | reverse %}
{% for language, completion, branch, visitors in completion_progress | sort(attribute=1) | reverse %}
<tr>
<td data-label="language">
<a href="https://github.com/python/python-docs-{{ language }}" target="_blank">
{{ language }}
</a>
</td>
<td data-label="visitors">
<a href="https://https://plausible.io/docs.python.org?filters=((contains,page,(/{{ language }}/)))" target="_blank">
{{ '{:,}'.format(visitors) }}
</a>
</td>
<td data-label="branch">{{ branch }}</td>
<td data-label="completion">
<div class="progress-bar" style="width: {{ completion | round(2) }}%;">{{ completion | round(2) }}%</div>
Expand Down
8 changes: 6 additions & 2 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ th, td {
border: 1px solid #ddd;
padding: 8px 12px;
text-align: left;
white-space: nowrap;
}
th {
background-color: #f4f4f4;
Expand All @@ -24,7 +25,10 @@ th {
min-width: 50px;
box-sizing: border-box;
}
td:nth-child(3) {
td:nth-child(2) {
text-align: right;
}
td:last-child {
width: 100%;
}
@media screen and (max-width: 600px) {
Expand Down Expand Up @@ -52,7 +56,7 @@ td:nth-child(3) {
left: 10px;
position: absolute;
}
td:nth-child(3) {
td:last-child {
width: inherit;
}
.progress-bar {
Expand Down
14 changes: 14 additions & 0 deletions visitors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import csv
import io
import urllib
import zipfile

import requests


def get_number_of_visitors(language: str) -> int:
param = urllib.parse.urlencode({'filters': f'[["contains","event:page",["/{language}/"]]]'})
r = requests.get(f'https://plausible.io/docs.python.org/export?{param}', timeout=10)
with zipfile.ZipFile(io.BytesIO(r.content), 'r') as z, z.open('visitors.csv') as csv_file:
csv_reader = csv.DictReader(io.TextIOWrapper(csv_file))
return sum(int(row["visitors"]) for row in csv_reader)
Loading