-
-
Notifications
You must be signed in to change notification settings - Fork 214
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
Changes from 3 commits
5182be8
ed117aa
358a00b
212c2d7
862fb87
3baa6fc
d509e12
0ea058b
53986f2
5f8e511
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
mattwang44 marked this conversation as resolved.
Show resolved
Hide resolved
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. murmur: 雖然是我先開始的,但我覺得這邊用 shell script 爛透了XDD 有時間可以幫忙想一下有沒有更好的方案 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 好啊 我來研究怎麼新增至 makefile 好了 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
||
mattwang44 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
" |
Large diffs are not rendered by default.
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)} %" | ||
mattwang44 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return result | ||
|
||
|
||
def get_github_issue(): | ||
mattwang44 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
NUMBER_OF_ISSUES = 100 | ||
mattwang44 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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: | ||
mattwang44 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
title = issue['title'].split(" ") | ||
mattwang44 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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] | ||
mattwang44 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
filename = filename.split("/") | ||
mattwang44 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if len(filename) < 2: | ||
mattwang44 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 | ||
mattwang44 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
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}"): | ||
mattwang44 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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}" | ||
mattwang44 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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() | ||
mattwang44 marked this conversation as resolved.
Show resolved
Hide resolved
|
Uh oh!
There was an error while loading. Please reload this page.