From bf20e1865daa366a24ee48354296b69d60a098e0 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Mon, 31 Mar 2025 19:27:09 +0100 Subject: [PATCH 1/5] Generate word_count and display in index.html --- generate.py | 2 ++ template.html.jinja | 1 + word_count.py | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+) create mode 100644 word_count.py diff --git a/generate.py b/generate.py index 611914034..e90781889 100644 --- a/generate.py +++ b/generate.py @@ -25,6 +25,7 @@ import contribute from completion import branches_from_devguide, get_completion, TranslatorsData from repositories import Language, get_languages_and_repos +from word_count import get_word_count generation_time = datetime.now(timezone.utc) @@ -107,6 +108,7 @@ class LanguageProjectData: completion_progress=(completion_progress := list(get_completion_progress())), generation_time=generation_time, duration=(datetime.now(timezone.utc) - generation_time).seconds, + word_count=get_word_count(Path('clones', 'cpython', 'build', 'gettext')), ) Path('index.html').write_text(output) diff --git a/template.html.jinja b/template.html.jinja index 252e07d32..35dc6c67e 100644 --- a/template.html.jinja +++ b/template.html.jinja @@ -52,6 +52,7 @@ main | meta {% endfor %} +

There Python documentation currently has a wordcount of {{ word_count }}

* the number in parentheses shows change in the last 30 days, included in the total completion

For more information about translations, see the Python Developer’s Guide.

Last updated at {{ generation_time.strftime('%A, %-d %B %Y, %-H:%M:%S %Z') }} (in {{ duration // 60 }}:{{ "{:02}".format(duration % 60) }} minutes).

diff --git a/word_count.py b/word_count.py new file mode 100644 index 000000000..bc0b3ca8f --- /dev/null +++ b/word_count.py @@ -0,0 +1,18 @@ +import os +from polib import pofile + +def _count_words(pot) -> int: + pot = pofile(pot) + word_count = 0 + for entry in pot: + word_count += len(entry.msgid.split()) + return word_count + +def get_word_count(dir) -> int: + total_word_count = 0 + for root, dirs, files in os.walk(dir): + for file in files: + if file.endswith('.pot'): + pot = os.path.join(root, file) + total_word_count += _count_words(pot) + return total_word_count From 062f0ae274015f5cf89c5d617442f5d6c2f45ca4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 31 Mar 2025 18:28:20 +0000 Subject: [PATCH 2/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- word_count.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/word_count.py b/word_count.py index bc0b3ca8f..b7c9f1972 100644 --- a/word_count.py +++ b/word_count.py @@ -1,6 +1,7 @@ import os from polib import pofile + def _count_words(pot) -> int: pot = pofile(pot) word_count = 0 @@ -8,6 +9,7 @@ def _count_words(pot) -> int: word_count += len(entry.msgid.split()) return word_count + def get_word_count(dir) -> int: total_word_count = 0 for root, dirs, files in os.walk(dir): From 9974d1ebd9ba85a93f424a1d6de30fd8aee82d9b Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Mon, 31 Mar 2025 20:25:33 +0100 Subject: [PATCH 3/5] Fix path and format number --- generate.py | 2 +- template.html.jinja | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/generate.py b/generate.py index e90781889..1d7493d85 100644 --- a/generate.py +++ b/generate.py @@ -108,7 +108,7 @@ class LanguageProjectData: completion_progress=(completion_progress := list(get_completion_progress())), generation_time=generation_time, duration=(datetime.now(timezone.utc) - generation_time).seconds, - word_count=get_word_count(Path('clones', 'cpython', 'build', 'gettext')), + word_count=get_word_count(Path('clones', 'cpython', 'Doc', 'build', 'gettext')), ) Path('index.html').write_text(output) diff --git a/template.html.jinja b/template.html.jinja index 35dc6c67e..569435fae 100644 --- a/template.html.jinja +++ b/template.html.jinja @@ -52,7 +52,7 @@ main | meta {% endfor %} -

There Python documentation currently has a wordcount of {{ word_count }}

+

The Python documentation currently has a wordcount of {{ '{:,}'.format(word_count) }}.

* the number in parentheses shows change in the last 30 days, included in the total completion

For more information about translations, see the Python Developer’s Guide.

Last updated at {{ generation_time.strftime('%A, %-d %B %Y, %-H:%M:%S %Z') }} (in {{ duration // 60 }}:{{ "{:02}".format(duration % 60) }} minutes).

From e4b2ed27d0ed58d3dbfefa525f6912e895d92a36 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Tue, 1 Apr 2025 16:25:00 +0100 Subject: [PATCH 4/5] Maciek's request --- template.html.jinja | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template.html.jinja b/template.html.jinja index 569435fae..688c2d763 100644 --- a/template.html.jinja +++ b/template.html.jinja @@ -52,8 +52,8 @@ main | meta {% endfor %} -

The Python documentation currently has a wordcount of {{ '{:,}'.format(word_count) }}.

* the number in parentheses shows change in the last 30 days, included in the total completion

+

The Python documentation currently has a wordcount of {{ '{:,}'.format(word_count) }}.

For more information about translations, see the Python Developer’s Guide.

Last updated at {{ generation_time.strftime('%A, %-d %B %Y, %-H:%M:%S %Z') }} (in {{ duration // 60 }}:{{ "{:02}".format(duration % 60) }} minutes).

From ae1f374b18b06c36d7e026bf113fa24ba0ed167f Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Tue, 1 Apr 2025 16:29:54 +0100 Subject: [PATCH 5/5] Split word-count --- template.html.jinja | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template.html.jinja b/template.html.jinja index 688c2d763..fc37ab1e4 100644 --- a/template.html.jinja +++ b/template.html.jinja @@ -53,7 +53,7 @@ main | meta

* the number in parentheses shows change in the last 30 days, included in the total completion

-

The Python documentation currently has a wordcount of {{ '{:,}'.format(word_count) }}.

+

The Python documentation currently has a word count of {{ '{:,}'.format(word_count) }}.

For more information about translations, see the Python Developer’s Guide.

Last updated at {{ generation_time.strftime('%A, %-d %B %Y, %-H:%M:%S %Z') }} (in {{ duration // 60 }}:{{ "{:02}".format(duration % 60) }} minutes).