forked from friscoMad/PGLuminate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shadowcheck.py
246 lines (203 loc) · 6.67 KB
/
shadowcheck.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
import logging
import os
from Queue import Queue
from multiprocessing.pool import ThreadPool
from threading import Lock
from pgnumbra.SingleLocationScanner import SingleLocationScanner
from pgnumbra.config import cfg_get, cfg_set
from pgnumbra.proxy import init_proxies, get_new_proxy
# ===========================================================================
logging.basicConfig(level=logging.INFO,
format='%(asctime)s [%(threadName)16s][%(module)14s][%(levelname)8s] %(message)s')
log = logging.getLogger(__name__)
# Silence some loggers
logging.getLogger('pgoapi').setLevel(logging.WARNING)
# ===========================================================================
FILE_PREFIX = 'accounts'
ACC_INFO_FILE = FILE_PREFIX + '-info.txt'
COMMON_POKEMON = [
16, # Pidgey
19, # Rattata
23, # Ekans
27, # Sandshrew
29, # Nidoran F
32, # Nidoran M
41, # Zubat
43, # Oddish
46, # Paras
52, # Meowth
54, # Psyduck
60, # Poliwag
69, # Bellsprout
72, # Tentacool
74, # Geodude
77, # Ponyta
81, # Magnemite
98, # Krabby
118, # Goldeen
120, # Staryu
129, # Magikarp
161, # Sentret
165, # Ledyba
167, # Spinarak
177, # Natu
183, # Marill
187, # Hoppip
191, # Sunkern
194, # Wooper
198, # Murkrow
209, # Snubbull
218 # Slugma
]
acc_stats = {
'good': 0,
'blind': 0,
'captcha': 0,
'banned': 0,
'error': 0
}
# ===========================================================================
def remove_account_file(suffix):
fname = '{}-{}.csv'.format(FILE_PREFIX, suffix)
if os.path.isfile(fname):
os.remove(fname)
def check_account(torch):
try:
torch.scan_once()
except Exception as e:
log.exception("Error checking account {}".format(torch.username))
try:
if torch.pokemon:
if is_blind(torch):
log.info("Account {} is shadowbanned. :-(".format(torch.username))
save_to_file(torch, 'blind')
else:
log.info("Account {} is good. :-)".format(torch.username))
save_to_file(torch, 'good')
else:
if torch.is_banned():
save_to_file(torch, 'banned')
elif torch.has_captcha():
save_to_file(torch, 'captcha')
else:
save_to_file(torch, 'error')
save_account_info(torch)
except Exception as e:
log.exception(
"Error saving checked account {} to file".format(torch.username))
del torch
def write_line_to_file(fname, line):
# Poor mans locking. Only 1 thread at any time, please. Super-defensive!
if not hasattr(write_line_to_file, 'lock'):
write_line_to_file.lock = Lock()
write_line_to_file.lock.acquire()
with open(fname, 'a') as f:
f.write(line)
f.close()
write_line_to_file.lock.release()
def save_account_info(acc):
global acc_info_tmpl
def bool(x):
return '' if x is None else ('Yes' if x else 'No')
km_walked_f = acc.player_stats.get('km_walked')
if km_walked_f:
km_walked_str = '{:.1f} km'.format(km_walked_f)
else:
km_walked_str = ''
line = acc_info_tmpl.format(
acc.username,
acc.player_stats.get('level', ''),
acc.player_stats.get('experience', ''),
bool(acc.is_warned()),
bool(acc.is_banned()),
bool(acc.has_captcha()),
bool(is_blind(acc)),
acc.player_stats.get('pokemons_encountered', ''),
acc.player_stats.get('pokeballs_thrown', ''),
acc.player_stats.get('pokemons_captured', ''),
acc.player_stats.get('poke_stop_visits', ''),
km_walked_str
)
write_line_to_file(ACC_INFO_FILE, line)
def init_account_info_file(torches):
global acc_info_tmpl
max_username_len = 4
for t in torches:
max_username_len = max(max_username_len, len(t.username))
acc_info_tmpl = '{:' + str(
max_username_len) + '} | {:3} | {:8} | {:4} | {:3} | {:7} | {:5} | {:6} | {:5} | {:5} | {:5} | {:10}\n'
line = acc_info_tmpl.format(
'Username',
'Lvl',
'XP',
'Warn',
'Ban',
'Captcha',
'Blind',
'Enc',
'Thr.',
'Cap',
'Spins',
'Walked'
)
write_line_to_file(ACC_INFO_FILE, line)
def save_to_file(torch, suffix):
global acc_stats
acc_stats[suffix] = acc_stats.get(suffix, 0) + 1
fname = "{}-{}.csv".format(FILE_PREFIX, suffix)
line = '{},{},{}\n'.format(torch.auth_service, torch.username, torch.password)
write_line_to_file(fname, line)
def is_blind(torch):
# We don't know if we did not search/find ANY Pokemon
if not torch.pokemon:
return None
for pid in torch.pokemon:
if pid not in COMMON_POKEMON:
return False
return True
def log_results(key):
if acc_stats[key]:
log.info("{:7}: {}".format(key.upper(), acc_stats[key]))
# ===========================================================================
log.info("ShadowCheck starting up.")
lat = cfg_get('latitude')
lng = cfg_get('longitude')
# Delete result files.
remove_account_file('good')
remove_account_file('blind')
remove_account_file('captcha')
remove_account_file('banned')
remove_account_file('error')
if os.path.isfile(ACC_INFO_FILE):
os.remove(ACC_INFO_FILE)
init_proxies()
# This test must include nearby Pokemon to work properly.
cfg_set('include_nearby', True)
torches = []
check_queue = Queue()
with open(cfg_get('accounts_file'), 'r') as f:
for num, line in enumerate(f, 1):
fields = line.split(",")
fields = map(str.strip, fields)
torches.append(
SingleLocationScanner(fields[0], fields[1], fields[2], lat, lng,
cfg_get('hash_key'), get_new_proxy()))
init_account_info_file(torches)
num_threads = cfg_get('shadowcheck_threads')
log.info("Checking {} accounts with {} threads.".format(len(torches), num_threads))
pool = ThreadPool(num_threads)
pool.map(check_account, torches)
pool.close()
pool.join()
log.info("All {} accounts processed.".format(len(torches)))
log_results('good')
log_results('blind')
log_results('captcha')
log_results('banned')
log_results('error')
if acc_stats['good'] == 0 and acc_stats['blind'] > 0:
log.warning("================= WARNING =================")
log.warning("NONE of the accounts saw ANY rare Pokemon.")
log.warning("Either they are all blind or there are in fact")
log.warning("no rare Pokemon near this location right now.")
log.warning("Try again with a different location to be sure.")