|
3 | 3 | # "gitpython", |
4 | 4 | # "potodo", |
5 | 5 | # "jinja2", |
| 6 | +# "requests", |
| 7 | +# "humanize", |
6 | 8 | # ] |
7 | 9 | # /// |
| 10 | +import csv |
| 11 | +import io |
| 12 | +import zipfile |
8 | 13 | from datetime import datetime, timezone |
9 | 14 | from pathlib import Path |
10 | 15 | from shutil import rmtree |
11 | 16 | from tempfile import TemporaryDirectory |
| 17 | +from urllib.parse import urlencode |
| 18 | + |
| 19 | +import humanize |
| 20 | +import requests |
12 | 21 | from git import Repo, GitCommandError |
13 | 22 | from potodo.potodo import scan_path |
14 | 23 | from jinja2 import Template |
15 | 24 |
|
| 25 | +import completion |
| 26 | +import visitors |
| 27 | + |
16 | 28 | completion_progress = [] |
17 | 29 | generation_time = datetime.now(timezone.utc) |
18 | 30 |
|
19 | 31 | with TemporaryDirectory() as tmpdir: |
20 | 32 | 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)) |
37 | 36 | print(completion_progress[-1]) |
38 | 37 |
|
39 | 38 | template = Template(""" |
|
46 | 45 | <h1>Python Docs Translation Dashboard</h1> |
47 | 46 | <table> |
48 | 47 | <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> |
50 | 54 | </thead> |
51 | 55 | <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 %} |
53 | 57 | <tr> |
54 | 58 | <td data-label="language"> |
55 | 59 | <a href="https://github.com/python/python-docs-{{ language }}" target="_blank"> |
56 | 60 | {{ language }} |
57 | 61 | </a> |
58 | 62 | </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> |
59 | 68 | <td data-label="branch">{{ branch }}</td> |
60 | 69 | <td data-label="completion"> |
61 | 70 | <div class="progress-bar" style="width: {{ completion | round(2) }}%;">{{ completion | round(2) }}%</div> |
|
0 commit comments