diff --git a/config.json b/config.json index 1722e86..2e3973a 100644 --- a/config.json +++ b/config.json @@ -8,6 +8,8 @@ [lat1,long1, lat2,long2], [lat1,long1, lat2,long2] ], + "web_hooks": [ + ], "stepsPerPassPerWorker": 300, "scanDelay": 10.5 -} \ No newline at end of file +} diff --git a/requirements.txt b/requirements.txt index bf7b58c..bb68b16 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,11 @@ -protobuf>=3.0.0a3 -requests==2.10.0 -s2sphere==0.2.4 +future==0.15.2 +geojson==1.3.3 +geopy==1.11.0 gpsoauth==0.3.0 +protobuf==3.0.0 protobuf-to-dict==0.1.0 -geojson -six -xxhash +pycryptodomex==3.4.2 +requests==2.10.0 +s2sphere==0.2.4 +six==1.10.0 +xxhash==0.6.1 diff --git a/track.py b/track.py index bb0e0bc..12d1e60 100644 --- a/track.py +++ b/track.py @@ -9,9 +9,13 @@ from pgoapi import pgoapi from pgoapi import utilities as util +from pgoapi.exceptions import ServerSideRequestThrottlingException from s2sphere import CellId, LatLng +import requests +from base64 import b64encode + pokes = [] spawns = [] Shash = {} @@ -36,7 +40,7 @@ def withinWork(lat, lng): def curSec(): return (60 * time.gmtime().tm_min) + time.gmtime().tm_sec - + def timeDif(a,b):#timeDif of -1800 to +1800 secs dif = a-b if (dif < -1800): @@ -56,7 +60,33 @@ def SbSearch(Slist, T): else: last = mp return first + +def sendToWebHook(data, p): + if not 'web_hooks' in config or len(config['web_hooks']) < 1: + return + payload = { + "type": "pokemon", + "message": { + "encounter_id": b64encode(str(p['encounter_id'])), + "spawnpoint_id": data["sid"], + "latitude": data["lat"], + "longitude": data["lng"], + "pokemon_id": data["pid"], + "disappear_time": (data["time"]+900000)/1000, + "last_modified_time": p["last_modified_timestamp_ms"], + "time_until_hidden_ms": p["time_till_hidden_ms"] + } + } + + for url in config['web_hooks']: + try: + requests.post(url, json=push, timeout=(None, 1)) + except requests.exceptions.ReadTimeout: + print 'Response timeout on webhook endpoint %s' % url + except requests.exceptions.RequestException as e: + print e + def worker(wid,Tthreads): global spawns, Shash, going #make own spawn list @@ -66,10 +96,10 @@ def worker(wid,Tthreads): print 'work list for worker {} is {} scans long'.format(wid,len(ownSpawns)) #find start position pos = SbSearch(ownSpawns, (curSec()+3540)%3600) - + api = pgoapi.PGoApi(provider=config['auth_service'], username=config['users'][wid]['username'], password=config['users'][wid]['password'], position_lat=0, position_lng=0, position_alt=0) api.activate_signature(utils.get_encryption_lib_path()) - + while True: #iterate over while not paused: @@ -119,10 +149,12 @@ def worker(wid,Tthreads): timeSpawn = (curTime+(wild['time_till_hidden_ms']))-900000 if wild['spawn_point_id'] == sid: gotit = True - pokes.append({'time':timeSpawn, 'sid':wild['spawn_point_id'], 'lat':wild['latitude'], 'lng':wild['longitude'], 'pid':wild['pokemon_data']['pokemon_id'], 'cell':CellId.from_lat_lng(LatLng.from_degrees(wild['latitude'], wild['longitude'])).to_token()}) + curPoke = {'time':timeSpawn, 'sid':wild['spawn_point_id'], 'lat':wild['latitude'], 'lng':wild['longitude'], 'pid':wild['pokemon_data']['pokemon_id'], 'cell':CellId.from_lat_lng(LatLng.from_degrees(wild['latitude'], wild['longitude'])).to_token()} + pokes.append(curPoke) + sendToWebHook(curPoke, wild) global Pfound Pfound += 1 - + elif wild['spawn_point_id'] not in Shash: print 'found new spawn' gmSpawn = time.gmtime(timeSpawn//1000) @@ -138,6 +170,7 @@ def worker(wid,Tthreads): pos += 1 if timeDif(ownSpawns[pos]['time'],secSpawn)>0:#only bother to add it to the found pokes, if it has missed its scan window pokeLog = {'time':timeSpawn, 'sid':wild['spawn_point_id'], 'lat':wild['latitude'], 'lng':wild['longitude'], 'pid':wild['pokemon_data']['pokemon_id'], 'cell':CellId.from_lat_lng(LatLng.from_degrees(wild['latitude'], wild['longitude'])).to_token()} + sendToWebHook(pokeLog, wild) pokes.append(pokeLog) Pfound += 1 else: @@ -234,10 +267,10 @@ def main(): f = open('pokes.json','w') json.dump(pokes,f) f.close() - + with open('spawns.json','w') as file: json.dump(spawns,file) file.close() if __name__ == '__main__': - main() \ No newline at end of file + main()