Skip to content
This repository has been archived by the owner on Sep 21, 2021. It is now read-only.

Commit

Permalink
Remove filters since they already existed anyway, and added documenta…
Browse files Browse the repository at this point in the history
…tion. Implemented distance_limit
  • Loading branch information
karlhe committed Jul 21, 2016
1 parent ec9f80e commit c7ee273
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 23 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ Instead of from the command-line, all arguments are read from a `config.json` fi

See `config.json.sample`.

Optional arguments:

* `distance_limit`: Given an Integer representing meters, only shows Pokemon within the limit. Only applies if `step_limit=1`.
* `only`: Comma-separated list of Pokemon to notify on. Cannot be used at the same time as `ignore`.
* `ignore`: Comma-separated list of Pokemon to ignore. Cannot be used at the same time as `only`.

It is also recommended to use your own Google Maps API key, set it in `credentials.json`.

See `credentials.json.sample`.
Expand Down
1 change: 0 additions & 1 deletion config.json.sample
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"password": "abc123",
"step_limit": 1,
"location": "123 Fake Street, Springfield, IL",
"notify": "dragonite, charizard",
"slack_key": "abc123",
"slack_channel": "#pokemon"
}
17 changes: 16 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,8 @@ def get_args():
"only": None,
"onlylure": False,
"port": 5000,
"step_limit": 4
"step_limit": 4,
"distance_limit": None
}
# load config file
with open('config.json') as data_file:
Expand Down Expand Up @@ -649,9 +650,11 @@ def process_step(args, api_endpoint, access_token, profile_response,
pokename = pokemonsJSON[pokeid]
if args.ignore:
if pokename.lower() in ignore or pokeid in ignore:
debug("{} was on the `ignore` list.".format(pokename))
continue
elif args.only:
if pokename.lower() not in only and pokeid not in only:
debug("{} was not on the `only` list.".format(pokename))
continue

disappear_timestamp = time.time() + poke.TimeTillHiddenMs \
Expand All @@ -662,6 +665,17 @@ def process_step(args, api_endpoint, access_token, profile_response,
transform_from_wgs_to_gcj(Location(poke.Latitude,
poke.Longitude))

# Skip Pokemon outside of distance_limit
# This only really makes sense if step_limit = 1, otherwise you get a swiss cheese map
if int(args.step_limit) == 1 and args.distance_limit:
origin_coords = (step_lat, step_long)
poke_coords = (poke.Latitude, poke.Longitude)
distance = distance_in_meters(origin_coords, poke_coords)
if distance > int(args.distance_limit):
debug("Pokemon {} skipped due to being {}m away.".format(pokename, distance))
continue
else:
debug("Pokemon {} found {}m away.".format(pokename, distance))

pokemon_obj = {
"lat": poke.Latitude,
Expand All @@ -672,6 +686,7 @@ def process_step(args, api_endpoint, access_token, profile_response,
}

if poke.SpawnPointId not in pokemons:
debug("Notifying about {}".format(pokename))
notifier.pokemon_found(pokemon_obj)

pokemons[poke.SpawnPointId] = pokemon_obj
Expand Down
22 changes: 1 addition & 21 deletions notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,14 @@
from datetime import datetime
import requests

wanted_pokemon = None
unwanted_pokemon = None

# Initialize object
def init():
# global pushbullet_client, wanted_pokemon
global wanted_pokemon, unwanted_pokemon, slack_key, slack_channel
global slack_key, slack_channel
# load pushbullet key
with open('config.json') as data_file:
data = json.load(data_file)

# get list of pokemon to send notifications for
if "notify" in data:
wanted_pokemon = _str( data["notify"] ).split(",")
wanted_pokemon = [a.lower() for a in wanted_pokemon]
if "ignore" in data:
unwanted_pokemon = _str( data["ignore"] ).split(",")
unwanted_pokemon = [a.lower() for a in unwanted_pokemon]

# get slack details
slack_key = _str( data["slack_key"] )
slack_channel = _str( data["slack_channel"] )
Expand All @@ -35,15 +24,6 @@ def _str(s):
def pokemon_found(pokemon):
# get name
pokename = _str( pokemon["name"] ).lower()
# check array
if wanted_pokemon:
if not pokename in wanted_pokemon:
return
if unwanted_pokemon:
if pokename in unwanted_pokemon:
return

print("Found {}".format(pokename))

# get address
coords = "{}, {}".format(str(pokemon["lat"]), str(pokemon["lng"]))
Expand Down
4 changes: 4 additions & 0 deletions transform.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from math import sqrt, sin, cos
from geopy.distance import vincenty

a = 6378245.0
ee = 0.00669342162296594323
Expand Down Expand Up @@ -45,6 +46,9 @@ def transform_long(x, y):
lon += (150.0 * sin(x / 12.0 * pi) + 300.0 * sin(x / 30.0 * pi)) * 2.0 / 3.0
return lon

# Approximates distance between 2 GPS coordinates in meters
def distance_in_meters(point_a, point_b):
return vincenty(point_a, point_b).meters

class Location:
def __init__(self, latitude, longitude):
Expand Down

0 comments on commit c7ee273

Please sign in to comment.