mirror of
https://github.com/PaiGramTeam/PaiGram_Resources.git
synced 2024-09-28 03:46:24 +00:00
95 lines
2.7 KiB
Python
95 lines
2.7 KiB
Python
"""
|
|
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()
|