Skip to content

Commit bf20e18

Browse files
Generate word_count and display in index.html
1 parent ab465de commit bf20e18

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

generate.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import contribute
2626
from completion import branches_from_devguide, get_completion, TranslatorsData
2727
from repositories import Language, get_languages_and_repos
28+
from word_count import get_word_count
2829

2930
generation_time = datetime.now(timezone.utc)
3031

@@ -107,6 +108,7 @@ class LanguageProjectData:
107108
completion_progress=(completion_progress := list(get_completion_progress())),
108109
generation_time=generation_time,
109110
duration=(datetime.now(timezone.utc) - generation_time).seconds,
111+
word_count=get_word_count(Path('clones', 'cpython', 'build', 'gettext')),
110112
)
111113

112114
Path('index.html').write_text(output)

template.html.jinja

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ main | <a href="metadata.html" target="_self">meta</a>
5252
{% endfor %}
5353
</tbody>
5454
</table>
55+
<p>There Python documentation currently has a wordcount of {{ word_count }}</p>
5556
<p>* the number in parentheses shows change in the last 30 days, included in the total completion</p>
5657
<p>For more information about translations, see the <a href="https://devguide.python.org/documentation/translating/">Python Developer’s Guide</a>.</p>
5758
<p>Last updated at {{ generation_time.strftime('%A, %-d %B %Y, %-H:%M:%S %Z') }} (in {{ duration // 60 }}:{{ "{:02}".format(duration % 60) }} minutes).</p>

word_count.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import os
2+
from polib import pofile
3+
4+
def _count_words(pot) -> int:
5+
pot = pofile(pot)
6+
word_count = 0
7+
for entry in pot:
8+
word_count += len(entry.msgid.split())
9+
return word_count
10+
11+
def get_word_count(dir) -> int:
12+
total_word_count = 0
13+
for root, dirs, files in os.walk(dir):
14+
for file in files:
15+
if file.endswith('.pot'):
16+
pot = os.path.join(root, file)
17+
total_word_count += _count_words(pot)
18+
return total_word_count

0 commit comments

Comments
 (0)