Skip to content
This repository was archived by the owner on May 24, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pogom/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,17 @@ def get_config_site(self):
'config.html',
gmaps_key=config.get('GOOGLEMAPS_KEY', None),
accounts=config.get('ACCOUNTS', []),
pbkey=config.get('PB_KEY', None),
password=config.get('CONFIG_PASSWORD', None))

def post_config_site(self):
if not self.is_authenticated():
return redirect(url_for('login'))

config['GOOGLEMAPS_KEY'] = request.form.get('gmapsKey', '')


config['PB_KEY'] = request.form.get('pbkey', '')

pw = request.form.get('configPassword', None)
pw_changed = (pw != config.get('CONFIG_PASSWORD', None))
if pw_changed:
Expand Down Expand Up @@ -118,6 +121,7 @@ def post_config_site(self):
gmaps_key=config.get('GOOGLEMAPS_KEY', None),
accounts=config.get('ACCOUNTS', []),
password=config.get('CONFIG_PASSWORD', None),
pbkey=config.get('PB_KEY', None),
alert=True))
if pw_changed:
resp.set_cookie('auth', config['AUTH_KEY'])
Expand All @@ -137,6 +141,7 @@ def save_config(self):
with open(config_path, 'w') as f:
data = {'GOOGLEMAPS_KEY': config['GOOGLEMAPS_KEY'],
'CONFIG_PASSWORD': config['CONFIG_PASSWORD'],
'PB_KEY' : config['PB_KEY'],
'SCAN_LOCATIONS': self.scan_config.SCAN_LOCATIONS.values(),
'ACCOUNTS': config['ACCOUNTS']}
f.write(json.dumps(data))
Expand Down
25 changes: 23 additions & 2 deletions pogom/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
from datetime import datetime
from base64 import b64encode
import threading
import requests
import calendar
from . import config

from .utils import get_pokemon_name

Expand Down Expand Up @@ -115,12 +118,13 @@ class Gym(BaseModel):
longitude = FloatField()
last_modified = DateTimeField()


pokemonsfound = {} # pokemon already found
def parse_map(map_dict):
pokemons = {}
pokestops = {}
gyms = {}

mobilealert = {1,2,3,4,5,6,7,8,9} #lists the pokemon you want notifications for

cells = map_dict['responses']['GET_MAP_OBJECTS']['map_cells']
if sum(len(cell.keys()) for cell in cells) == len(cells) * 2:
log.warning("Received valid response but without any data. Possibly rate-limited?")
Expand All @@ -130,6 +134,23 @@ def parse_map(map_dict):
if p['encounter_id'] in pokemons:
continue # prevent unnecessary parsing

#pushbullet mobile
lat1 = str(p['latitude'])
lat2 = str(p['longitude'])
dtime = datetime.utcfromtimestamp((p['last_modified_timestamp_ms'] + p['time_till_hidden_ms']) / 1000.0)
unixtime = calendar.timegm(dtime.utctimetuple())
displaytime = datetime.fromtimestamp(unixtime).strftime('%H:%M:%S')
url1 = 'https://www.google.com/maps/place/' + lat1 + ',' + lat2 + '/@' + lat1 + ',' + lat2 + ',30z'
pbkey = config["PB_KEY"]
headers = {'Access-Token':str(pbkey)}
if pbkey is not None and p['pokemon_data']['pokemon_id'] in mobilealert and p['encounter_id'] not in pokemonsfound:
requests.post('https://api.pushbullet.com/v2/pushes', headers=headers, data = {'type':'link', 'title':get_pokemon_name(p['pokemon_data']['pokemon_id']) + " expires at " + str(displaytime), 'url':url1})

pokemonsfound[p['encounter_id']] = {
'encounter_id': b64encode(str(p['encounter_id'])),
'encounter_id2': p['encounter_id']
}

pokemons[p['encounter_id']] = {
'encounter_id': b64encode(str(p['encounter_id'])),
'spawnpoint_id': p['spawn_point_id'],
Expand Down
1 change: 1 addition & 0 deletions runserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def read_config(scan_config):
config['GOOGLEMAPS_KEY'] = c.get('GOOGLEMAPS_KEY', None)
config['CONFIG_PASSWORD'] = c.get('CONFIG_PASSWORD', None)
config['ACCOUNTS'] = c.get('ACCOUNTS', [])
config['PB_KEY'] = c.get('PB_KEY', None)
scan_config.update_scan_locations(c.get('SCAN_LOCATIONS', {}))

if config.get('CONFIG_PASSWORD', None):
Expand Down
4 changes: 4 additions & 0 deletions templates/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ <h1>PoGoMap Config</h1>
<input type="password" class="form-control" id="configPassword" name="configPassword" value="{{ password or ''}}">
<span id="configPasswordHelp" class="help-block">Protect this config with a password.</span>
</div>
<div class="form-group">
<label for="pbkey">PushButton API Key</label>
<input type="text" class="form-control" id="pbkey" name="pbkey" value="{{ pbkey or ''}}">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
<a href="../" class="btn btn-default">Back to Map</a>
</form>
Expand Down