|
1 | 1 | import json |
2 | | -import yaml |
3 | 2 | import os |
4 | 3 | import traceback |
5 | | -import tempfile |
6 | 4 | from datetime import datetime |
7 | | -from subprocess import Popen, PIPE |
8 | 5 | from pathlib import Path |
9 | 6 |
|
10 | 7 | from crowdin_api import CrowdinClient # type: ignore |
11 | | -from github import Github, Auth |
12 | 8 | from dotenv import load_dotenv |
13 | 9 |
|
14 | 10 |
|
15 | 11 | load_dotenv() # take environment variables |
16 | 12 |
|
17 | 13 |
|
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 | | - |
30 | 14 | class ScientificCrowdinClient: |
31 | 15 |
|
32 | 16 | def __init__(self, token: str, organization: str): |
@@ -145,37 +129,66 @@ def get_project_translators(self, project_name: str) -> dict: |
145 | 129 | return results |
146 | 130 |
|
147 | 131 |
|
148 | | -def generate_md_file(): |
| 132 | +def generate_md_file(data: dict) -> None: |
149 | 133 | """Generate a markdown file for the dashboard.""" |
150 | 134 | script_path = Path(__file__).resolve() |
151 | | - parent_dir = script_path.parent |
152 | | - |
153 | | - content '''--- |
| 135 | + parent_dir = script_path.parent.parent / 'content' |
| 136 | + content = '''--- |
154 | 137 | title: Translations Status |
155 | 138 | draft: false |
156 | 139 | --- |
157 | | -''' |
| 140 | +''' |
158 | 141 | 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 | + |
159 | 168 | with open(new_file_path, "w") as f: |
160 | 169 | f.write(content) |
161 | 170 |
|
162 | 171 |
|
163 | 172 | def main() -> None: |
164 | 173 | """Main function to run the script.""" |
165 | 174 | 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) |
179 | 192 | except Exception as e: |
180 | 193 | print(f"Error: {e}") |
181 | 194 | traceback.print_exc() |
|
0 commit comments