Achievements

This commit is contained in:
xtaodada 2023-02-16 21:03:32 +08:00
parent 5237c31d22
commit 18f70e07e7
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
7 changed files with 99 additions and 2 deletions

View File

@ -26,7 +26,8 @@ jobs:
run: |
export FILE_PATH="${{ vars.FILE_PATH }}"
python main.py
cp calendar.json Resources/calendar.json
python achievements.py
cp src/calendar.json Resources/calendar.json
- name: Commit changes
uses: EndBug/add-and-commit@v9

94
achievements.py Normal file
View File

@ -0,0 +1,94 @@
"""
Achievements data extractor
src:
achievements.xlsx https://docs.qq.com/sheet/DS01hbnZwZm5KVnBB?tab=BB08J2
achievements.py https://github.com/KimigaiiWuyi/GenshinUID/blob/main/GenshinUID/tools/get_achievement_json.py
"""
import json
import warnings
from pathlib import Path
from openpyxl import Workbook, load_workbook
from openpyxl.worksheet.worksheet import Worksheet
from pydantic import BaseModel
warnings.filterwarnings('ignore', category=UserWarning, module='openpyxl')
import_path = "src/achievements.xlsx"
export_path = Path("Resources")
wb: Workbook = load_workbook(import_path)
ws_daily: Worksheet = wb['成就相关每日委托']
ws_all: Worksheet = wb['正式服成就汇总']
result_daily = []
result_all = []
class BaseAchievement(BaseModel):
name: str
desc: str
guide: str
link: str
class Achievement(BaseAchievement):
book: str
class TaskAchievement(BaseAchievement):
task: str
def load_daily_achievements():
is_first = False
for row in range(3, 100):
ach = TaskAchievement(
task=ws_daily.cell(row, 3).value or "",
name=ws_daily.cell(row, 4).value or "",
desc=ws_daily.cell(row, 5).value or "",
guide=ws_daily.cell(row, 6).value or "",
link=ws_daily.cell(row, 6).hyperlink.target if ws_daily.cell(row, 6).hyperlink else '',
)
if not ach.task:
if is_first:
break
is_first = True
continue
else:
is_first = False
task_list = ach.task.split('\n')
for t in task_list:
if t.startswith('('):
continue
ach.task = t
result_daily.append(ach.dict())
def load_all_achievements(book: Worksheet, loop: int, bn: int, an: int, dn: int, gn: int):
for row in range(3, loop):
ach = Achievement(
book=book.cell(row, bn).value or "",
name=book.cell(row, an).value or "",
desc=book.cell(row, dn).value or "",
guide=book.cell(row, gn).value or "",
link=book.cell(row, gn).hyperlink.target if book.cell(row, gn).hyperlink else '',
)
if not ach.book:
break
result_all.append(ach.dict())
def save_achievements():
export_path.mkdir(parents=True, exist_ok=True)
with open(export_path / 'achievements_daily.json', 'w', encoding='utf-8') as f:
json.dump(result_daily, f, indent=4, ensure_ascii=False)
with open(export_path / 'achievements_all.json', 'w', encoding='utf-8') as f:
json.dump(result_all, f, indent=4, ensure_ascii=False)
if __name__ == '__main__':
load_all_achievements(ws_all, 1000, 5, 6, 7, 11)
load_daily_achievements()
save_achievements()

View File

@ -36,7 +36,7 @@ async def save_file(file_name: str) -> None:
async def save_file_list() -> None:
async with aiofiles.open("files.txt", "r", encoding="utf-8") as f:
async with aiofiles.open("src/files.txt", "r", encoding="utf-8") as f:
file_list = (await f.read()).splitlines()
tasks = [save_file(file) for file in file_list]

View File

@ -1,3 +1,5 @@
httpx==0.23.3
python-dotenv==0.21.1
aiofiles==23.1.0
openpyxl==3.1.1
pydantic==1.10.5

BIN
src/achievements.xlsx Normal file

Binary file not shown.