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
2 changes: 2 additions & 0 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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', 'Doc', 'build', 'gettext')),
)

Path('index.html').write_text(output)
Expand Down
1 change: 1 addition & 0 deletions template.html.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ main | <a href="metadata.html" target="_self">meta</a>
</tbody>
</table>
<p>* the number in parentheses shows change in the last 30 days, included in the total completion</p>
<p>The Python documentation currently has a word count of {{ '{:,}'.format(word_count) }}.</p>
<p>For more information about translations, see the <a href="https://devguide.python.org/documentation/translating/">Python Developer’s Guide</a>.</p>
<p>Last updated at {{ generation_time.strftime('%A, %-d %B %Y, %-H:%M:%S %Z') }} (in {{ duration // 60 }}:{{ "{:02}".format(duration % 60) }} minutes).</p>
</body>
Expand Down
20 changes: 20 additions & 0 deletions word_count.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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
Loading