-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathquery_tool.py
195 lines (189 loc) · 9.05 KB
/
query_tool.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
# coding:utf-8
from _prototype import plugin_prototype
import sys
import re
import os
from cross_platform import *
# start meta
__plugin_name__ = 'query infomation of player'
__author = 'fffonion'
__version__ = 0.40
hooks = {}
extra_cmd = {'q_item':'query_item', 'qi':'query_item', 'q_holo':'query_holo', 'qh':'query_holo', 'qgc':'query_guild_contribution','q_rank':'query_rank','qr':'query_rank'}
# end meta
# query item count
def query_item(plugin_vals):
def do(*args):
logger = plugin_vals['logger']
if 'player' not in plugin_vals or not plugin_vals['player'].item.db:
logger.error('玩家信息未初始化,请随便执行一个操作再试')
return
print(du8('%-17s%s' % ('物品', '个数')))
print('-' * 30)
for (i, [n, j]) in plugin_vals['player'].item.db.items():
if j > 0: # has
# calc utf-8 length
l1 = len(n) # ascii length
n = raw_du8(n)
l2 = len(n) # char count
print(safestr('%s%s%s' % (n, ' ' * int(15 - l2 - (l1 - l2) / 2), j)))
return do
# query holo cards
def query_holo(plugin_vals):
def do(*args):
logger = plugin_vals['logger']
if 'player' not in plugin_vals or not plugin_vals['player'].item.db:
logger.error('玩家信息未初始化,请随便执行一个操作再试')
return
print(du8('%s' % ('当前拥有以下闪卡')))
print('-' * 30)
_player = plugin_vals['player']
cache = []
for c in _player.card.cards:
if c.holography == 1:
ca = _player.card.db[c.master_card_id]
cache.append((ca[0], ca[1], c.lv, c.hp, c.power))
cache = sorted(cache, key = lambda l:(l[1], l[2]))
print('\n'.join(map(lambda x:du8('[%s] ☆%d Lv%d HP:%d ATK:%d' % x), cache)))
return do
def query_guild_contribution(plugin_vals):
def do(*args):
lines = []
if plugin_vals['loc'][:2] == 'cn':
lines += open('events_cn.log').read().split('\n')
elif plugin_vals['loc'] == 'tw':
lines += open('events_tw.log').read().split('\n')
else:
print(du8('不支持%s的查询'%plugin_vals['loc']))
return
if os.path.exists('.IGF.log'):
lines += open('.IGF.log').read().split('\n')
pname, total = plugin_vals['player'].item.db[8001]
cnt = 0
for l in lines:
c = re.findall(pname+'\]\:\+(\d+)\(',l)
if c:
cnt += int(c[0])
print(du8('公会贡献: %d/ %s'%(cnt,total or '?')))
return do
def query_rank(plugin_vals):
def do(*args):
logger = plugin_vals['logger']
loc = plugin_vals['loc']
if loc[:2] not in ['cn','tw']:
logger.error('排位查询不支持日服和韩服')
return
if loc == 'tw':
import _query_rank_tw_lib as _lib
import re
import urllib
if PYTHON3:
import urllib.request as urllib2
opener = urllib2.build_opener(urllib2.ProxyHandler(urllib.request.getproxies()))
else:
import urllib2
opener = urllib2.build_opener(urllib2.ProxyHandler(urllib.getproxies()))
def show_it(content):
strl = '\n%s\n%s\n' %(_lib.query_title(content),'-'*20)
for (k, v) in _lib.query_regex[_guild_mode + _coll_mode if not _country_mode else -1]:
try:
strl += '%s %s\n' % (k, v(content))
except IndexError:
pass
logger.info(strl)
_header = _lib.broswer_headers
_header['cookie'] = plugin_vals['cookie']
_header['User-Agent'] = plugin_vals['poster'].header['User-Agent']
_guild_mode = 2 if raw_inputd('查询个人排名(s)(默认)还是公会排名(g)> ') == 'g' else 0
_country_mode = 0
if not _guild_mode and _lib.query_country_id:#build country selection
ctotal = len(_lib.query_country_id)
while True:
print(du8('\n'.join(['%d.%s' % (i + 1, _lib.query_country_id[i][0]) for i in range(ctotal)])))
_sel = raw_input('> ')
if _sel.isdigit() and 0 < int(_sel) <= ctotal:
_country_mode = _lib.query_country_id[int(_sel) - 1][1]
break
while True:
_goto = raw_inputd('输入要查询的排名开始数,按回车显示自己所在区域> ')
if not _goto or (
_goto.isdigit() and \
((0<int(_goto)<=20000 and not _guild_mode) or (0<int(_goto)<=2000 and _guild_mode))):
break
logger.error('请输入%d以内0以上的数字' % (2000 if _guild_mode else 20000))
#automatically judge
if not _country_mode and ((_guild_mode and _lib.query_rev[2] and _lib.query_rev[3]) or \
(not _guild_mode and _lib.query_rev[0] and _lib.query_rev[1]) or _goto):
_coll_mode = 1 if raw_inputd('查询收集品排名(c)(默认)还是妖精加权排名(f)> ') != 'f' else 0
else:
_coll_mode = (1 if _lib.query_rev[3] else 0) if _guild_mode else \
(1 if _lib.query_rev[1] else 0)
#request
if _country_mode:
if _goto:
_gurl = _lib.query_goto[-1]
x = opener.open(urllib2.Request(_gurl % (_goto, _country_mode),headers = _header)).read()
else:
_gurl = _lib.query_country
x = opener.open(urllib2.Request(_gurl % _country_mode,headers = _header)).read()
elif _goto:
_gurl = _lib.query_goto[_guild_mode + _coll_mode]
x = opener.open(urllib2.Request(_gurl % _goto,headers = _header)).read()
# if True:
# x = open(r'z:/test.htm').read()
else:
_rev = _lib.query_rev[_guild_mode + _coll_mode]
if not _rev:
logger.error('版本不存在,可能是当前活动没有该排名\n请尝试升级_query_rank_lib,或指定排名区域查询')
return
if _lib.now >= _lib.query_lifetime:
logger.error('查询库已过期,请升级_query_rank_lib为新版本\n或指定排名区域查询')
return
_url = _lib.query_base % _rev
x = opener.open(urllib2.Request(_url, headers = _header)).read()
try:
show_it(_lib.pre(x))
except IndexError:
logger.warning('匹配失败,请重新登录;如果问题仍然存在,请更新插件')
else:#cn
from xml2dict import XML2Dict
po = plugin_vals['poster']
po.post('menu/menulist')
sel_rankid = 0
to_top = False
while True:
resp, ct = po.post('ranking/ranking', postdata='move=%d&ranktype_id=%d&top=%d' % (
1 if sel_rankid == 0 else 0, sel_rankid, 1 if to_top else 0))
ct = XML2Dict.fromstring(ct).response.body.ranking
ranktype_id = int(ct.ranktype_id)
allranks = ct.ranktype_list.ranktype
rank_name = allranks[ranktype_id - 1].title
try:
_user = ct.user_list.user
except KeyError:
logger.warning('暂未列入排行榜,请继续努力ww')
return
if not to_top:
me = [_i for _i in _user if _i.id == plugin_vals['player'].id][0]
logger.info(rank_name +
(not to_top and '\n排名:%s 点数:%s\n' % (me.rank, me.battle_event_point) or '\n') +
'可见区域内 Up:%s/%s Down:%s/%s' % (
_user[0].rank, _user[0].battle_event_point,
_user[-1].rank, _user[-1].battle_event_point)
)
while True:
_inp = raw_inputd('\n输入序号查询其他排行:(9.排名至顶 0.退出)\n%s\n> ' %
('\n'.join(map(lambda x : '%s.%s' % (x.id, x.title), allranks)))
) or '0'
if not _inp.isdigit():
continue
else:
if _inp == '0':
return
if _inp == '9':
to_top = True
else:
sel_rankid = int(_inp)
to_top = False
break
return do