-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsort.py
More file actions
69 lines (62 loc) · 2.42 KB
/
sort.py
File metadata and controls
69 lines (62 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import os
import json
import shutil
def main():
# 创建文件夹
if os.path.exists('release'):
print('release文件夹已存在,是否删除?(y/n)')
if input().lower() == 'y':
shutil.rmtree('release')
else:
exit(0)
os.makedirs('release')
# 读取配置文件
with open('character.json', 'r', encoding='utf-8') as f:
config = json.load(f)
games = config['game_list']
# 读取表情包
stickers = os.walk('HoYoLab表情包')
stickers = list(stickers)
# 循环游戏
for game in games:
folders = config[game].keys()
for folder in folders:
folder_path = os.path.join('release', game, folder)
characters = config[game][folder]
for character in characters:
if not character:
continue
character_path = os.path.join(folder_path, character)
os.makedirs(character_path, exist_ok=True)
# 查找表情包
for sticker in stickers:
sticker_game = sticker[0].split('/')
if len(sticker_game) > 1:
if sticker_game[1] not in ('2022愚人节系列表情包',):
if sticker_game[1] != game:
continue
file_list = sticker[2]
for file in file_list:
if file is not None and character in file:
# 复制表情包
src = os.path.join(sticker[0], file)
dst = os.path.join(character_path, '_'.join([*(sticker[0].split('/')[2:]), file]))
shutil.copy(src, dst)
idx = sticker[2].index(file)
sticker[2][idx] = None
# 打印剩余表情包并保存到日志
log = []
for sticker in stickers:
if '.DS_Store' in sticker[2]:
sticker[2].remove('.DS_Store')
while None in sticker[2]:
sticker[2].remove(None)
if sticker[2]:
for file in sticker[2]:
line = os.path.join(*(sticker[0].split('/')[1:]), file)
log.append(line)
print(line)
with open('release/未使用表情包.log', 'w', encoding='utf-8') as f:
f.write('\n'.join(log))
if __name__ == '__main__':
main()