Skip to content

Add a Script to List Translate Progress by File and Show the Assignee #706

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

Merged
merged 10 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
28 changes: 28 additions & 0 deletions .github/workflows/mark_file.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: mark_file

on:
schedule:
- cron: '30 23 * * 5'

jobs:
ci:
runs-on: ubuntu-latest
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository.
contents: write
steps:
- uses: actions/checkout@v2

- name: Install poetry
uses: abatilo/actions-poetry@v2

- name: Execute Check Process
run: |
chmod +x .scripts/mark_file.sh
.scripts/mark_file.sh
shell: bash

- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Weekly Update -- Marking files
13 changes: 13 additions & 0 deletions .scripts/mark_file.sh
Copy link
Collaborator

@mattwang44 mattwang44 Nov 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

murmur: 雖然是我先開始的,但我覺得這邊用 shell script 爛透了XDD 有時間可以幫忙想一下有沒有更好的方案
例如 invoke 或加進 makefile 之類的

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好啊 我來研究怎麼新增至 makefile 好了
這個可以讓我到下個 pr 再處理嗎? 還是就一步到好XD

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

再開其他 PR 處理~

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh

WORK_DIR=.scripts
cd $WORK_DIR

source utils/install_poetry.sh

poetry lock
poetry install
poetry run bash -c "
python mark_file/main.py

"
1 change: 1 addition & 0 deletions .scripts/mark_file/dist/mark_file_20231114_223945.md

Large diffs are not rendered by default.

111 changes: 111 additions & 0 deletions .scripts/mark_file/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import polib
import os
import datetime
import requests


def entry_check(pofile):
lines_tranlated = len(pofile.translated_entries())
lines_untranlated = len(pofile.untranslated_entries())

if lines_tranlated == 0:
result = "❌"
elif lines_untranlated == 0:
result = "✅"
else:
lines_all = lines_tranlated + lines_untranlated
progress = lines_tranlated / lines_all
progress = round(progress*100, 2)
result = f"Ongoing, {str(progress)} %"

return result


def get_github_issue():
NUMBER_OF_ISSUES = 100

url = f"https://api.github.com/repos/python/python-docs-zh-tw/issues?per_page={NUMBER_OF_ISSUES}"
headers = {
"Accept": "application/vnd.github+json",
"X-GitHub-Api-Version": "2022-11-28"
}
r = requests.get(url=url, headers=headers)
result = r.json()

result_list = []
for issue in result:
title = issue['title'].split(" ")

if len(title) < 2:
continue
if title[0] != "翻譯" and title[0].lower() != "translate":
continue
if issue["assignee"] is None:
continue

filename = title[1]
if filename[0] == "`":
filename = filename[1:]
if filename[-1] == "`":
filename = filename[:-1]

filename = filename.split("/")
if len(filename) < 2:
continue
if filename[1][-3:] != ".po":
filename[1] += ".po"

result_list.append([filename, issue["assignee"]["login"]])

return result_list


def format_line_file(filename, result):
tmp = f" - {filename}"
tmp = f"{tmp}{'-' * (40-len(tmp))}{result}\r"
return tmp


def format_line_directory(dirname):
tmp = f"- {dirname}/\r"
return tmp


if __name__ == "__main__":

issue_list = get_github_issue()

directories = ["c-api", "distributing", "extending", "faq", "howto", "includes",
"installing", "library", "reference", "tutorial", "using", "whatsnew"]

summary = {}

for dir_name in directories:
summary[dir_name] = {}
for root, dirs, files in os.walk(f"../{dir_name}"):
for file in files:
if file.endswith(".po"):
filepath = os.path.join(root, file)
po = polib.pofile(filepath)
result = entry_check(po)
summary[dir_name][file] = result

for issue in issue_list:
title = issue[0]
assignee = issue[1]

try:
summary[title[0]][title[1]] += f", 💻 {assignee}"
except KeyError:
pass

writeliner = []
for dirname, filedict in summary.items():
writeliner.append(format_line_directory(dirname))
for filename, result in filedict.items():
writeliner.append(format_line_file(filename, result))

file = open(
f"mark_file/dist/mark_file_{datetime.datetime.today().strftime('%Y%m%d_%H%M%S')}.md", "w")
file.writelines(writeliner)
file.close()
Loading