This repository has been archived by the owner on Jul 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 56
/
CLSniper.py
73 lines (67 loc) · 2.11 KB
/
CLSniper.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
# You must have both pokecli.py and web.py running for this to work.
# original by @sontek
# modified by @stolencatkarma
from dateutil import parser
from datetime import datetime
import requests
import time
from multiprocessing import Process
import pylru
# EDIT ONLY THESE TWO THINGS
users = [
'webpyusername1',
'webpyusername2',
'webpyusername3'
]
blacklist = ['rattata', 'pidgey']
# -------------------------
base_url = 'http://localhost:5000/%(user)s/snipe/%(coords)s'
rare_url = 'http://www.pokesnipers.com/api/v1/pokemon.json'
cache = pylru.lrucache(15)
def snipe(pokemon, user, coords):
print('Requesting %s for %s' % (pokemon, user))
try:
new_url = base_url % dict(user=user, coords=coords)
requests.get(new_url)
except Exception as e:
print("Couldn't do it... :( %s", e)
def get_latest_rares():
global blacklist
response = None
try:
response = requests.get(rare_url)
data = response.json()
except Exception as e:
if response:
error = response.text
else:
error = e
print("Couldn't decode the data", error)
return
rares = data['results']
for pokemon in rares:
until = parser.parse(pokemon['until']).replace(tzinfo=None)
coords = pokemon['coords']
name = pokemon['name']
# don't attempt ones that we've already sniped
if coords in cache:
print("We've already attempted %s, skipping..." % coords)
continue
# don't attempt ones that are already gone
if until > datetime.utcnow():
if name.lower() in blacklist:
continue
print('Found a pokemon we want!, %s at %s' % (name, coords))
cache[coords] = name
time.sleep(10)
processes = []
for user in users:
p = Process(target=snipe, args=(name, user, coords))
processes.append(p)
p.start()
for process in processes:
process.join()
while True:
print('Checking for new pokemon')
get_latest_rares()
time.sleep(30)