forked from friscoMad/PGLuminate
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathshadowcheck.py
249 lines (203 loc) · 7.77 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
247
248
249
import codecs
import logging
import os
import sys
from threading import Lock, Thread
from mrmime.utils import get_spinnable_pokestops
from pgnumbra.CSVAccProvider import CSVAccProvider
from pgnumbra.PGPoolAccProvider import PGPoolAccProvider
from pgnumbra.SingleLocationScanner import SingleLocationScanner
from pgnumbra.config import cfg_get, cfg_init
from pgnumbra.proxy import init_proxies, get_new_proxy
# ===========================================================================
from pgnumbra.spin import spin_pokestop
logging.basicConfig(level=logging.INFO,
format='%(asctime)s [%(threadName)16s][%(module)17s][%(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'
acc_stats = {
'good': 0,
'blind': 0,
'captcha': 0,
'banned': 0,
'error': 0
}
threads = []
# ===========================================================================
def remove_account_file(suffix):
fname = '{}-{}.csv'.format(FILE_PREFIX, suffix)
if os.path.isfile(fname):
os.remove(fname)
def check_thread(account_provider):
while True:
acc = account_provider.next()
if acc:
check_account(
SingleLocationScanner(acc['auth_service'], acc['username'], acc['password'], cfg_get('latitude'),
cfg_get('longitude'), cfg_get('hash_key_provider'), get_new_proxy()))
if cfg_get('max_good') and acc_stats['good'] >= cfg_get('max_good'):
if acc_stats['good'] == cfg_get('max_good'):
log.info("Found {} GOOD accounts. Exiting.".format(acc_stats['good']))
break;
else:
break
def check_account(acc):
try:
try:
response = acc.scan_once()
lvl = acc.get_stats('level')
if response:
spin_below_level = cfg_get("spin_below_level")
max_spins = cfg_get("max_spins")
if lvl < spin_below_level:
step_location = (acc.latitude, acc.longitude)
stops = get_spinnable_pokestops(response, step_location)
acc.log_info("Account is level {}. Trying to spin {} Pokestop(s) for XP.".format(lvl, min(max_spins,
len(stops))))
spins = 0
for stop in stops:
if spin_pokestop(acc, stop, step_location):
spins += 1
if spins >= max_spins:
break
else:
acc.log_info(
"Account already reached level {}. Not spinning any Pokestop.".format(spin_below_level))
except Exception as e:
log.exception("Error checking account {}: {}".format(acc.username, repr(e)))
try:
if acc.seen_pokemon:
if is_blind(acc):
log.info("Account {} is shadowbanned. :-(".format(acc.username))
save_to_file(acc, 'blind')
else:
log.info("Account {} is good. :-)".format(acc.username))
save_to_file(acc, 'good')
else:
if acc.is_banned():
save_to_file(acc, 'banned')
elif acc.has_captcha():
save_to_file(acc, 'captcha')
else:
save_to_file(acc, 'error')
save_account_info(acc)
except Exception as e:
log.exception(
"Error saving checked account {} to file: {}".format(acc.username, repr(e)))
finally:
acc.release(reason="Checked with PGNumbra")
del acc
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 codecs.open(fname, mode='a', encoding='utf-8') 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.get_stats('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,
bool(acc.is_warned()),
bool(acc.is_banned()),
bool(acc.get_state('banned')),
bool(acc.has_captcha()),
bool(is_blind(acc)),
acc.get_stats('level', ''),
acc.get_stats('experience', ''),
acc.get_stats('pokemons_encountered', ''),
acc.get_stats('pokeballs_thrown', ''),
acc.get_stats('pokemons_captured', ''),
acc.get_stats('poke_stop_visits', ''),
km_walked_str
)
write_line_to_file(ACC_INFO_FILE, line)
def init_account_info_file():
global acc_info_tmpl
acc_info_tmpl = '{:20} | {:4} | {:3} | {:4} | {:7} | {:5} | {:3} | {:8} | {:6} | {:5} | {:5} | {:5} | {:10}\n'
line = acc_info_tmpl.format(
'Username',
'Warn',
'Ban',
'BanF',
'Captcha',
'Blind',
'Lvl',
'XP',
'Enc',
'Thr.',
'Cap',
'Spins',
'Walked'
)
write_line_to_file(ACC_INFO_FILE, line)
def save_to_file(acc, suffix):
global acc_stats
acc_stats[suffix] = acc_stats.get(suffix, 0) + 1
fname = "{}-{}.csv".format(FILE_PREFIX, suffix)
line = u'{},{},{}\n'.format(acc.auth_service, acc.username, acc.password)
write_line_to_file(fname, line)
def is_blind(acc):
# We don't know if we did not search/find ANY Pokemon
if not acc.seen_pokemon:
return None
return acc.rareless_scans != 0
def log_results(key):
if acc_stats[key]:
log.info("{:7}: {}".format(key.upper(), acc_stats[key]))
# ===========================================================================
cfg_init(shadowcheck=True)
log.info("PGNumbra ShadowCheck starting up.")
# 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()
if cfg_get('accounts_file'):
account_provider = CSVAccProvider()
elif cfg_get('pgpool_url') and cfg_get('pgpool_num_accounts') > 0:
account_provider = PGPoolAccProvider()
else:
log.error(
"No idea which accounts you want to check. Use either --accounts-file or --pgpool-url with --pgpool-num-accounts.")
sys.exit()
init_account_info_file()
num_threads = cfg_get('threads')
log.info("Checking {} accounts with {} threads.".format(account_provider.get_num_accounts(), num_threads))
for i in range(0, num_threads):
t = Thread(target=check_thread, args=(account_provider,))
t.daemon = True
t.start()
threads.append(t)
# Wait for threads to end
for t in threads:
t.join()
log.info("All {} accounts processed.".format(account_provider.num_provided))
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.")