Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Bring back visitors tracking #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import contribute
import build_status
from visitors import get_number_of_visitors
from completion import branches_from_devguide, get_completion, TranslatorsData
from repositories import get_languages_and_repos, Language

Expand Down Expand Up @@ -68,10 +69,12 @@ def get_project_data(
built = language.code in languages_built
if repo:
completion, translators_data, branch, change = get_completion(clones_dir, repo)
visitors_num = get_number_of_visitors(language.code, http) if built else 0
else:
completion = 0.0
translators_data = TranslatorsData(0, False)
change = 0.0
visitors_num = 0
branch = None
return LanguageProjectData(
language,
Expand All @@ -80,6 +83,7 @@ def get_project_data(
completion,
change,
translators_data,
visitors_num,
built,
in_switcher=languages_built.get(language.code),
uses_platform=language.code in contribute.pulling_from_transifex,
Expand All @@ -95,6 +99,7 @@ class LanguageProjectData:
completion: float
change: float
translators: TranslatorsData
visitors: int
built: bool
in_switcher: bool | None
uses_platform: bool
Expand Down
2 changes: 1 addition & 1 deletion style.css
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ th {
.progress-bar.low + .progress-bar-outer-label {
display: inline-block;
}
td[data-label="translators"] {
td[data-label="visitors"], td[data-label="translators"] {
text-align: right;
}
td[data-label="completion"] {
Expand Down
9 changes: 9 additions & 0 deletions template.html.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<tr>
<th>language</th>
<th>switcher</th>
<th>visitors*</th>
<th>translators</th>
<th>completion</th>
</tr>
Expand All @@ -29,6 +30,13 @@
<a href="https://docs.python.org/{{ project.language.code }}/" target="_blank">✗</a>
{% endif %}
</td>
<td data-label="visitors">
{% if project.visitors %}
<a href="https://plausible.io/docs.python.org?filters=((contains,page,(/{{ project.language.code }}/)))" target="_blank">
{{ '{:,}'.format(project.visitors) }}
</a>
{% endif %}
</td>
<td data-label="translators">
{% if project.translators.link %}<a href="{{ project.translators.link }}" target="_blank">{% endif %}
{{ project.translators.number }}
Expand All @@ -42,6 +50,7 @@
{% endfor %}
</tbody>
</table>
<p>* sum of <a href="https://plausible.io/data-policy#how-we-count-unique-users-without-cookies" target="_blank">daily unique visitors</a> since 8 June 2024</p>
<p>For more information about translations, see the <a href="https://devguide.python.org/documentation/translating/" target="_blank">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
21 changes: 21 additions & 0 deletions visitors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import urllib.parse
from logging import info

from urllib3 import PoolManager, Retry


def get_number_of_visitors(language: str, http: PoolManager) -> int:
params = urllib.parse.urlencode(
{'filters': f'[["contains","event:page",["/{language}/"]]]', 'period': 'all'}
)
response = http.request(
'GET',
f'https://plausible.io/api/stats/docs.python.org/top-stats/?{params}',
retries=Retry(status_forcelist=(500, 502), backoff_factor=1, backoff_jitter=1),
)
info(f'visitors {response.status=} ({language=})')
return response.json()['top_stats'][0]['value']


if __name__ == '__main__':
print(get_number_of_visitors('pl', PoolManager()))
Loading