-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
277 lines (247 loc) · 8.59 KB
/
main.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
from medaldata import *
def gen_newid():
roomid = []
datatxt = open("vtbs.txt","r",encoding="utf8")
for line in datatxt:
datalist = line.split()
if datalist[-1] != "无":
roomid += [int(datalist[-1])]
ridset = set(roomid)
for item in vtblist:
ridset.discard(item)
print(ridset)
datatxt.close()
return list(ridset)
def dict_update(olddict:dict,newdict:dict):
old_item_list = list(olddict.items())
for item in old_item_list:
rid,oldmedal = item
newmedal = newdict.get(rid,None)
if "-" in str(rid):
print(',"'+str(rid)+'":"'+str(oldmedal)+'"')
if (oldmedal != newmedal) and (newmedal != None) and (oldmedal != "暂无粉丝勋章"):
for n in range(1,10):
if olddict.get(str(str(rid)+"-"+str(n)),None) == None:
break
print(',"'+str(rid)+'-'+str(n)+'":"'+str(oldmedal)+'"')
def gen_uid_list():
uid_list = []
datatxt = open("vtbs.txt","r",encoding="utf8")
for line in datatxt:
datalist = line.split()
if datalist[-2] != "无":
uid_list += [int(datalist[-2])]
uid_list.sort()
return uid_list
def gen_rid_to_uid_dict():
i=0
rid_to_uid_dict = dict()
datatxt = open("vtbs.txt","r",encoding="utf8")
for line in datatxt:
datalist = line.split()
if datalist[-1] != "无":
rid_to_uid_dict.update({int(datalist[-1]):int(datalist[-2])})
else:
i+=1
return rid_to_uid_dict
def gen_uid_to_rid_dict():
i=0
uid_to_rid_dict = dict()
datatxt = open("vtbs.txt","r",encoding="utf8")
for line in datatxt:
datalist = line.split()
if datalist[-1] != "无":
uid_to_rid_dict.update({int(datalist[-2]):int(datalist[-1])})
else:
i+=1
return uid_to_rid_dict
def gen_rid_to_name_dict():
rid_to_name_dict = dict()
datatxt = open("vtbs.txt","r",encoding="utf8")
for line in datatxt:
datalist = line.split()
if datalist[-1] != "无":
rid_to_name_dict.update({int(datalist[-1]):str(datalist[0])})
return rid_to_name_dict
def gen_name_to_rid_dict():
name_to_rid_dict = dict()
datatxt = open("vtbs.txt","r",encoding="utf8")
for line in datatxt:
datalist = line.split()
if datalist[-1] != "无":
name_to_rid_dict.update({str(datalist[0]):int(datalist[-1])})
return name_to_rid_dict
def gen_rid_to_fans_dict():
rid_to_fans_dict = dict()
datatxt = open("vtbs.txt","r",encoding="utf8")
for line in datatxt:
datalist = line.split()
if datalist[-1] != "无":
rid_to_fans_dict.update({int(datalist[-1]):int(datalist[1])})
return rid_to_fans_dict
def gen_uid_to_name_dict():
uid_to_name_dict = dict()
datatxt = open("vtbs.txt","r",encoding="utf8")
for line in datatxt:
datalist = line.split()
if datalist[-2] != "无":
uid_to_name_dict.update({int(datalist[-2]):str(datalist[0])})
return uid_to_name_dict
def find_not_logged_in_vtbs():
namedict = gen_rid_to_name_dict()
not_logged_list = []
for item in vtblist:
feedback = namedict.get(item)
if feedback == None:
not_logged_list += [item]
return not_logged_list
def find_rid_by_medal(mname:str):
rid = []
for key,value in vtb_fan_medal_dict.items():
if value == mname:
rid += [key]
if rid == []:
return ["Does Not Exist"]
else:
return rid
def old_medal_rid(oldrid:str):
new = ""
for char in oldrid:
if char != "-":
new += char
else:
break
return int(new)
def get_info_by_medal(mname:str,namedict,uiddict,showfans=False):
try:
name = []
uid = []
roomid = find_rid_by_medal(mname)
isold = False
if "-" in str(roomid[0]) and len(roomid) == 1:
isold = True
roomid[0] = old_medal_rid(roomid[0])
for item in roomid:
nametemp = namedict.get(item,"Name Not Found")
name += [nametemp]
for item in roomid:
uidtemp = uiddict.get(item,"Does Not Exist")
uid += [uidtemp]
if isold == True:
print("此勋章已经不再被使用")
print("勋章名: "+str(mname)+"\n用户名: "+str(name)+
"\n UID: "+str(uid)+"\n房间号: "+str(roomid))
if showfans == True:
fansdict = gen_rid_to_fans_dict()
fans = fansdict.get(roomid,"Does Not Exist")
print("粉丝数:"+str(fans))
return [name,uid,roomid]
except Exception as error:
print(error)
print("An ERROR Occurred")
return None
def get_info_by_rid(roomid:int,namedict,uiddict,showfans=False):
name = namedict.get(roomid,"Name Not Found")
uid = uiddict.get(roomid,"Does Not Exist")
medal = vtb_fan_medal_dict.get(roomid,"Does Not Exist")
old_medals = []
for i in range(1,11):
temp = vtb_fan_medal_dict.get(str(roomid)+"-"+str(i),"Does Not Exist")
if temp != "Does Not Exist" :
old_medals += [str(temp)]
print("用户名: "+str(name)+"\n UID: "+str(uid)+
"\n房间号: "+str(roomid)+"\n勋章名: "+str(medal))
if showfans == True:
fansdict = gen_rid_to_fans_dict()
fans = fansdict.get(roomid,"Does Not Exist")
print("粉丝数:"+str(fans)+" ("+data_version+")")
if old_medals != []:
print("曾用勋章:"+str(old_medals))
return [name,uid,roomid,medal,old_medals]
def gen_fst_list():
medallist = list(vtb_fan_medal_dict.items())
fstlist = []
for obj in medallist:
rid, name = obj
if name == "粉丝团":
fstlist += [rid]
return fstlist
def gen_none_list():
medallist = list(vtb_fan_medal_dict.items())
nonelist = []
for obj in medallist:
rid, name = obj
if name == "暂无粉丝勋章":
nonelist += [rid]
return nonelist
def gen_update_list(fanlimit=900):
nonelist = gen_none_list()
fansdict = gen_rid_to_fans_dict()
update_list = []
for item in nonelist:
current_fans = fansdict.get(int(item),0)
if current_fans >= fanlimit:
update_list += [item]
return update_list
def search_by_str(stri,name_to_riddict=None):
if name_to_riddict == None:
name_to_riddict = gen_name_to_rid_dict()
keylist = list(name_to_riddict.keys())
result_name = []
for item in keylist:
temp = item.upper()
if stri.upper() in temp:
result_name += [item]
result_rid = []
for name in result_name:
rid = name_to_riddict.get(name)
result_rid += [rid]
if result_rid != []:
batch(result_rid,showfans=False)
length = str(len(result_rid))
if length != "1":
print(length+" Results")
else:
print(length+" Result")
else:
print("No Result")
return result_rid
def batch(datalist:list,showfans=True):
print("-------------------")
namedict = gen_rid_to_name_dict()
uiddict = gen_rid_to_uid_dict()
for item in datalist:
try:
inputdata = int(item)
livedata = get_info_by_rid(item,namedict,uiddict,showfans)
except:
medaldata = get_info_by_medal(item,namedict,uiddict,showfans)
print("-------------------")
def main():
exit = False
print("当前数据库版本:"+data_version)
namedict = gen_rid_to_name_dict()
name_to_riddict = gen_name_to_rid_dict()
uiddict = gen_rid_to_uid_dict()
while not exit:
print("-------------------")
inputdata = str(input("请输入粉丝勋章名/房间号: "))
if inputdata.upper() == "E":
break
try:
inputdata = int(inputdata)
livedata = get_info_by_rid(inputdata,namedict,uiddict)
except:
if (":" in inputdata) or (";" in inputdata)\
or (":" in inputdata) or (";" in inputdata):
print("搜索模式")
inputdata = inputdata.replace(":","").replace(";","")\
.replace(":","").replace(";","")
search_by_str(inputdata,name_to_riddict)
else:
medaldata = get_info_by_medal(inputdata,namedict,uiddict)
print("-------------------")
if str(input("退出? Y/y: ")).upper() == "Y":
exit = True
if __name__ == "__main__":
main()