更新代码

This commit is contained in:
2026-05-08 16:41:57 +08:00
parent 3996889769
commit 8a08df7f4a
5 changed files with 740 additions and 0 deletions
+78
View File
@@ -0,0 +1,78 @@
import json
import os
import re
from pathlib import Path
project_path = Path(__file__).parent.parent.absolute()
data_path = os.path.join(project_path, 'data')
def process_single_json(json_path):
with open(json_path, 'r', encoding='utf-8') as file:
json_content = json.load(file)
if 'eventid' not in json_content:
return {}
result_dict = {
"event_id": json_content['eventid'],
"language": json_content['lang'],
"event_name": json_content['eventName'],
"entry_type": json_content['entryType'],
"story_code": json_content['storyCode'],
"avg_tag": json_content['avgTag'],
"story_name": json_content['storyName'],
"story_introduction": json_content['storyInfo'],
}
story_content = []
for item in json_content['storyList']:
if item.get('prop') == 'Sticker' and item.get('attributes', {}).get('text'):
text = item.get('attributes', {}).get('text', '').replace('<i>', '').replace('</i>', '')
if text:
story_content.append({'role': 'voiceover', 'content': text})
elif item.get('attributes', {}).get('content'):
if item.get('attributes', {}).get('name'):
story_content.append({'role': item['attributes']['name'], 'content': item['attributes']['content']})
else:
story_content.append({'role': 'voiceover', 'content': item['attributes']['content']})
result_dict['story_content'] = story_content
return result_dict
def dump_data_to_json():
data_pool = {}
base_path = os.path.join(data_path, 'ArknightsStoryJson-main', 'zh_CN', 'gamedata')
for root, dirs, files in os.walk(base_path):
for file in files:
temp_dict = process_single_json(os.path.join(root, file))
if not temp_dict:
continue
if temp_dict['event_name'] not in data_pool:
data_pool[temp_dict['event_name']] = [temp_dict]
else:
data_pool[temp_dict['event_name']].append(temp_dict)
with open('data_pool.json', 'w', encoding='utf-8') as file:
file.write(json.dumps(data_pool, ensure_ascii=False))
if __name__ == '__main__':
with open('data_pool.json', 'r', encoding='utf-8') as file:
content = json.load(file)
target_dict = {'活动': [], '主线': [], "其它": [], '干员密录': []}
for key, item in content.items():
if item[0]['entry_type'] in ('ACTIVITY', 'MINI_ACTIVITY'):
target_dict['活动'].append(item)
elif item[0]['entry_type'] == 'MAINLINE':
target_dict['主线'].append(item)
elif item[0]['entry_type'] == 'EXTRA':
target_dict['其它'].append(item)
elif item[0]['entry_type'] == 'NONE':
target_dict['干员密录'].append(item)
else:
raise Exception('分类异常')
print('done')