-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathamiibos.py
81 lines (52 loc) · 1.85 KB
/
amiibos.py
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
70
71
72
73
74
75
76
77
78
79
80
import os
import zipfile
def unzip(zipFile):
print('开始解压'+zipFile)
path = 'file/amiibo/'
zFile = zipfile.ZipFile(path + os.sep + zipFile, "r")
for file in zFile.namelist():
if file.rsplit('.', 1)[1].lower() in {'bin','BIN'}:
zFile.extract(file,path)
#文件名 空格改为_,并且改为小写
oldName = path + os.sep + file # os.sep添加系统分隔符
newName = path + os.sep + file.replace(' ','_').lower()
#print(file.lower())
os.rename(oldName,newName)
zFile.close()
os.remove(path+ os.sep + zipFile) # 删除压缩包
print('解压完毕,'+zipFile+'已删除')
def save(cmd):
msg ='\n'
for _ in cmd:
msg += _
path = 'file/scriptcopy.txt'
with open(path,'w') as f:
f.write(msg)
def sendCMD(cmd):
return cmd+'\n'
def readAmiibo():
cmd = list()
# print('开始读取全部的amiibo')
path = 'file/amiibo/'
fileList=os.listdir(path)
cmd.append(sendCMD('DOWN'))
cmd.append(sendCMD('2000'))
for amiibo in fileList:
if amiibo.rsplit('.', 1)[1].lower() == 'bin':
cmd.append(sendCMD('Y'))
cmd.append(sendCMD('amiibo '+amiibo))
cmd.append(sendCMD('FOR 4'))
cmd.append(sendCMD('A'))
cmd.append(sendCMD('1000'))
cmd.append(sendCMD('NEXT'))
# print('amiibo全部读取完毕')
cmd.append(sendCMD('B'))
cmd.append(sendCMD('2000'))
cmd.append(sendCMD('B'))
return cmd
def run(zipName):
#解压上传的压缩包
unzip(zipName)
#批量读取amiibo
a = readAmiibo()
save(a)