Skip to content

Commit 3d944d8

Browse files
committed
Generate status file with tables for each project
1 parent 8b5176f commit 3d944d8

3 files changed

Lines changed: 52 additions & 37 deletions

File tree

.github/workflows/deploy_website.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ on:
44
push:
55
branches:
66
- main
7+
schedule:
8+
- cron: "0 12 * * SUN" # Every Sunday at noon
79
workflow_dispatch:
810

911
concurrency:
@@ -36,10 +38,10 @@ jobs:
3638
- name: Install Dart Sass Embedded # Installs dart-sass
3739
run: sudo snap install dart-sass-embedded
3840

39-
- name: Install python and dependencies
41+
- name: Install python
4042
uses: actions/setup-python@v5
4143
with:
42-
python-version: '3.13'
44+
python-version: '3.8'
4345

4446
- name: Build with Hugo
4547
run: |

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ themes: themes/scientific-python-hugo-theme
2424
html: ## Build site in `./public`
2525
html: themes content/shortcodes.md
2626
python -m pip install --upgrade pip
27-
python -m pip install crowdin-api-client pygithub python-dotenv
27+
python -m pip install crowdin-api-client python-dotenv
2828
python scripts/update_dashboard.py
2929
hugo
3030

scripts/update_dashboard.py

Lines changed: 47 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,16 @@
11
import json
2-
import yaml
32
import os
43
import traceback
5-
import tempfile
64
from datetime import datetime
7-
from subprocess import Popen, PIPE
85
from pathlib import Path
96

107
from crowdin_api import CrowdinClient # type: ignore
11-
from github import Github, Auth
128
from dotenv import load_dotenv
139

1410

1511
load_dotenv() # take environment variables
1612

1713

18-
def parse_input() -> dict:
19-
gh_input = {
20-
# Automations Bot account
21-
"username": "scientificpythontranslations",
22-
"crowdin_token": os.environ["CROWDIN_TOKEN"],
23-
# Provided by gpg action based on organization secrets
24-
# "name": os.environ["GPG_NAME"],
25-
# "email": os.environ["GPG_EMAIL"],
26-
}
27-
return gh_input
28-
29-
3014
class ScientificCrowdinClient:
3115

3216
def __init__(self, token: str, organization: str):
@@ -145,37 +129,66 @@ def get_project_translators(self, project_name: str) -> dict:
145129
return results
146130

147131

148-
def generate_md_file():
132+
def generate_md_file(data: dict) -> None:
149133
"""Generate a markdown file for the dashboard."""
150134
script_path = Path(__file__).resolve()
151-
parent_dir = script_path.parent
152-
153-
content '''---
135+
parent_dir = script_path.parent.parent / 'content'
136+
content = '''---
154137
title: Translations Status
155138
draft: false
156139
---
157-
'''
140+
'''
158141
new_file_path = parent_dir / "status.md"
142+
for crowdin_project in sorted(data, key=lambda x: x.lower()):
143+
project_id = data[crowdin_project]["project_id"]
144+
content += f"\n## {crowdin_project}\n"
145+
content += """\n<table>
146+
<tr>
147+
<th>Language</th>
148+
<th>Translators</th>
149+
<th>Completion %</th>
150+
<th>Approval %</th>
151+
</tr>
152+
"""
153+
status = data[crowdin_project]["status"]
154+
for language_id, _ in sorted(status.items(), key=lambda item: (item[1]['progress'], item[1]['approval']), reverse=True):
155+
print(language_id)
156+
url = f'https://scientific-python.crowdin.com/u/projects/{project_id}/l/{language_id}'
157+
content += f"""<tr>
158+
<td><a href='{url}'>{data[crowdin_project]['status'][language_id]['language_name']} ({language_id})</a></td>
159+
<td>{len(data[crowdin_project]['translators'][language_id])}</td>
160+
<td>{data[crowdin_project]['status'][language_id]['progress']}</td>
161+
<td>{data[crowdin_project]['status'][language_id]['approval']}</td>
162+
</tr>"""
163+
164+
content += "\n</table>\n\n"
165+
166+
content += f"\n\n---\n\nLast updated: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n"
167+
159168
with open(new_file_path, "w") as f:
160169
f.write(content)
161170

162171

163172
def main() -> None:
164173
"""Main function to run the script."""
165174
try:
166-
gh_input = parse_input()
167-
# crowdin_project = gh_input["crowdin_project"]
168-
# client = ScientificCrowdinClient(
169-
# token=gh_input["crowdin_token"], organization="Scientific-python"
170-
# )
171-
# valid_languages = client.get_valid_languages(
172-
# crowdin_project,
173-
# int(gh_input["translation_percentage"]),
174-
# int(gh_input["approval_percentage"]),
175-
# )
176-
# translators = client.get_project_translators(
177-
# crowdin_project,
178-
# )
175+
client = ScientificCrowdinClient(
176+
token=os.environ["CROWDIN_TOKEN"], organization="Scientific-python"
177+
)
178+
projects = client.get_projects()
179+
data = {}
180+
for crowdin_project, project_id in sorted(projects.items()):
181+
print(f"Project: {crowdin_project} ({project_id})")
182+
project_status = client.get_project_status(crowdin_project)
183+
translators = client.get_project_translators(
184+
crowdin_project,
185+
)
186+
data[crowdin_project] = {
187+
"status": project_status,
188+
"translators": translators,
189+
"project_id": project_id,
190+
}
191+
generate_md_file(data)
179192
except Exception as e:
180193
print(f"Error: {e}")
181194
traceback.print_exc()

0 commit comments

Comments
 (0)