This repository has been archived by the owner on Aug 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
歷史提交: * ci: 新增貢獻者 readme 換行腳本 * test: 測試 * test: 修改成另一個方式 * test: 更多測試 * test: 給 github token * test: 修正 group 是空值 * test: 修正 ci * test: 繼續測試 * test: 獨立出來 * test: 小小修正 * chore: 完成!
- Loading branch information
Showing
2 changed files
with
94 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
"""Simple Contributors Html table generator""" | ||
import os | ||
import json | ||
import requests | ||
|
||
GITHUB_TOKEN = os.environ.get("GITHUB_TOKEN") | ||
AUTH_HEADER = {'Authorization': f'Bearer {GITHUB_TOKEN}'} | ||
|
||
def get_github_user_name(api_url: str, default_name: str): | ||
""" | ||
Using api url to get and retrun user name | ||
""" | ||
|
||
response = requests.get(api_url, headers=AUTH_HEADER, timeout=6) | ||
|
||
if response.status_code == 200: | ||
json_data = json.loads(response.content) | ||
return json_data["name"] if json_data["name"] is not None else default_name | ||
else: | ||
print("ERROR, not successful to get user data") | ||
|
||
def get_contributors_list(): | ||
""" | ||
Using GitHub contributors api to get list, and return needs info list | ||
""" | ||
response = requests.get("https://api.github.com/repos/xMikux/ModsTranslationPack/contributors?per_page=100", headers=AUTH_HEADER, timeout=6) | ||
contributor_list = [] | ||
|
||
if response.status_code == 200: | ||
json_data = json.loads(response.content) | ||
|
||
for data in json_data: | ||
if "[bot]" not in data["login"]: | ||
user_name = get_github_user_name(data["url"], data["login"]) | ||
html_url = data["html_url"] | ||
avatar_url = data["avatar_url"] | ||
|
||
user_info = { | ||
"user_name": user_name, | ||
"html_url": html_url, | ||
"avatar_url": avatar_url | ||
} | ||
|
||
contributor_list.append(user_info) | ||
|
||
return contributor_list | ||
|
||
def generate_html_list(user_list: dict): | ||
""" | ||
Generate contributor html table list | ||
""" | ||
|
||
html_table = "<table>\n <tr>\n" | ||
|
||
for i, user in enumerate(user_list, 1): | ||
html_table += ' <td align="center">\n' | ||
html_table += f' <a href="{user["html_url"]}" title="{user["user_name"]}">\n' | ||
html_table += f' <img src="{user["avatar_url"]}" width="100;" alt="{user["user_name"]}"/>\n' | ||
html_table += f' <br /><sub><b>{user["user_name"]}</b></sub>\n' | ||
html_table += ' </a>\n' | ||
html_table += ' </td>\n' | ||
|
||
if i % 7 == 0 and i != len(user_list): | ||
html_table += " </tr>\n <tr>\n" | ||
|
||
html_table += " </tr>\n</table>" | ||
|
||
return html_table | ||
|
||
if __name__ == "__main__": | ||
api_list = get_contributors_list() | ||
html_list = generate_html_list(api_list) | ||
print(html_list) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters