-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update download.py [getcard.py unfinished]
- Loading branch information
Showing
8 changed files
with
184 additions
and
85 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
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,35 @@ | ||
name: Update | ||
|
||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: "0 0 * * 0" | ||
|
||
permissions: | ||
contents: write | ||
|
||
jobs: | ||
update: | ||
name: Update Data | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.12' | ||
- name: Install Dependencies | ||
run: pip install -r ./requirements.txt | ||
- name: Update Data | ||
run: | | ||
cd script | ||
python download.py | ||
- name: Upload File | ||
run: | | ||
if [[ `git status --porcelain` ]]; then | ||
git add . | ||
git commit -m "Update Submodule" | ||
git push | ||
else | ||
echo Pass | ||
fi |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
script/__pycache__/ | ||
script/*.json | ||
script/data/* |
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 |
---|---|---|
@@ -1,24 +1,74 @@ | ||
import os | ||
import requests | ||
import json | ||
|
||
def download_file(url, filename): | ||
try: | ||
response = requests.get(url) | ||
response.raise_for_status() | ||
with open(filename, 'wb') as file: | ||
file.write(response.content) | ||
print(f"文件已下载并保存为: {filename}") | ||
except requests.exceptions.RequestException as e: | ||
print(f"下载文件时出错: {e}") | ||
def fetch_json(url): | ||
response = requests.get(url) | ||
response.raise_for_status() | ||
data = response.json() | ||
return data | ||
|
||
def combine(hide, birthday, people): | ||
print(hide, birthday, people) | ||
def load_json(file_path): | ||
with open(file_path, 'r', encoding='utf-8') as file: | ||
data = json.load(file) | ||
return data | ||
|
||
ren = { | ||
'出生': 'born', | ||
'Born': 'born', | ||
'逝世': 'departed', | ||
'Departed': 'departed', | ||
'昵称': 'alias', | ||
'Alias': 'alias', | ||
'地区': 'location', | ||
'Location': 'location', | ||
'年龄': 'age', | ||
'Age': 'age' | ||
} | ||
|
||
def get_json(path): | ||
info = load_json(f'./data/people/{path}/info.json') | ||
info_en = load_json(f'./data/people/{path}/info.en.json') | ||
|
||
data = {} | ||
for item in info['info']: | ||
data[ren[item[0]]] = item[1] | ||
|
||
data_en = {} | ||
for item in info_en['info']: | ||
data_en[ren[item[0]]] = item[1] | ||
|
||
def m_get(data_lang, id, none='None'): | ||
return data_lang[id] if (id in data_lang) else none | ||
|
||
assert m_get(info, 'id') == path | ||
|
||
content = { | ||
'id': path, | ||
'name': m_get(info, 'name'), | ||
'name_en': m_get(info_en, 'name'), | ||
'alias': m_get(data, 'alias', path), | ||
'alias_en': m_get(data_en, 'alias', path), | ||
'born': m_get(data, 'born', None), | ||
'departed': m_get(data, 'departed', None), | ||
'age': m_get(data, 'age', 'N/A'), | ||
'location': m_get(data, 'location', '未知'), | ||
'location_en': m_get(data_en, 'location', 'Unknown'), | ||
'avatar': './' + info['profileUrl'].format(path=path)[1:] | ||
} | ||
|
||
# print(path, content) | ||
|
||
return content | ||
|
||
def Main(): | ||
download_file('https://github.com/one-among-us/data/raw/refs/heads/main/data/hdata.json', 'hide.json') | ||
download_file('https://github.com/one-among-us/data/raw/refs/heads/gh-pages/birthday-list.json', 'birthday.json') | ||
download_file('https://github.com/one-among-us/data/raw/refs/heads/gh-pages/people-list.json', 'people.json') | ||
combine('hide.json', 'birthday.json', 'people.jspn') | ||
content = [] | ||
os.system('git clone https://github.com/one-among-us/data.git --single-branch --branch gh-pages --depth=1') | ||
for item in load_json('./data/people-home-list.json'): | ||
content.append(get_json(item['path'])) | ||
# print(content) | ||
with open('people.json', 'w', encoding='utf-8') as file: | ||
json.dump(content, file, ensure_ascii=False, indent=4) | ||
|
||
if __name__ == "__main__": | ||
Main() |
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 |
---|---|---|
@@ -1,27 +1,29 @@ | ||
def getcardl(i): | ||
def getcard_b(i): | ||
return { | ||
'name': '名字', | ||
'name_eng': 'Unknown', | ||
'remark': 'awa', | ||
'nickname': '这是昵称', | ||
'nickname_eng': 'meow', | ||
'name_en': 'Unknown', | ||
'id': 'awa', | ||
'alias': '这是昵称', | ||
'alias_en': 'meow', | ||
'date': '2099-99-99', | ||
'age': 100, | ||
'countdown': -1, | ||
'region': '未知', | ||
'region_eng': '>_<', | ||
'location': '未知', | ||
'location_en': '>_<', | ||
'avatar': 'https://avatars.githubusercontent.com/u/192512683' | ||
} | ||
|
||
def getcardr(i): | ||
def getcard_d(i): | ||
return { | ||
'name': '名字', | ||
'name_eng': 'Unknown', | ||
'remark': 'awa', | ||
'nickname': '这是昵称', | ||
'nickname_eng': 'meow', | ||
'name_en': 'Unknown', | ||
'id': 'awa', | ||
'alias': '这是昵称', | ||
'alias_en': 'meow', | ||
'date': '2099-99-99', | ||
'age': 100, | ||
'countdown': -1, | ||
'region': '未知', | ||
'region_eng': '>_<', | ||
'location': '未知', | ||
'location_en': '>_<', | ||
'avatar': 'https://avatars.githubusercontent.com/u/192512683' | ||
} |
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
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
Oops, something went wrong.