Skip to content

Commit

Permalink
Clean up (PokemonGoF#562)
Browse files Browse the repository at this point in the history
* Removed ignore and only from global config, cleaned up

* Reintroduced support for additional Flask init kwargs
  • Loading branch information
favll authored and DerScreever committed Jul 20, 2016
1 parent 8655486 commit 95c292a
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
credentials.json
static/dist/
node_modules/
venv/
4 changes: 1 addition & 3 deletions pogom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@
'ROOT_PATH': None,
'ORIGINAL_LATITUDE': None,
'ORIGINAL_LONGITUDE': None,
'GMAPS_KEY' : None,
'IGNORE' : None,
'ONLY' : None
'GMAPS_KEY': None
}
7 changes: 3 additions & 4 deletions pogom/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@


class Pogom(Flask):
def __init__(self, name):
super(Pogom, self).__init__(name)
def __init__(self, import_name, **kwargs):
super(Pogom, self).__init__(import_name, **kwargs)
self.json_encoder = CustomJSONEncoder
self.route("/", methods=['GET'])(self.fullmap)
self.route("/pokemons", methods=['GET'])(self.pokemons)
Expand All @@ -26,8 +26,7 @@ def fullmap(self):
gmaps_key=config['GMAPS_KEY'])

def pokemons(self):
return jsonify(Pokemon.get_active(ignore=config['IGNORE'],
only=config['ONLY']))
return jsonify(Pokemon.get_active())

def pokestops(self):
return jsonify([p for p in Pokestop.select().dicts()])
Expand Down
2 changes: 1 addition & 1 deletion pogom/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
class APIKeyException(Exception):
pass
pass
13 changes: 8 additions & 5 deletions pogom/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class Meta:


class Pokemon(BaseModel):
IGNORE = None
ONLY = None

# We are base64 encoding the ids delivered by the api
# because they are too big for sqlite to handle
encounter_id = CharField(primary_key=True)
Expand All @@ -30,7 +33,7 @@ class Pokemon(BaseModel):
disappear_time = DateTimeField()

@classmethod
def get_active(cls, ignore, only):
def get_active(cls):
query = (Pokemon
.select()
.where(Pokemon.disappear_time > datetime.now())
Expand All @@ -41,11 +44,11 @@ def get_active(cls, ignore, only):
p['pokemon_name'] = get_pokemon_name(p['pokemon_id'])
pokemon_name = p['pokemon_name'].lower()
pokemon_id = str(p['pokemon_id'])
if ignore:
if pokemon_name in ignore or pokemon_id in ignore:
if cls.IGNORE:
if pokemon_name in cls.IGNORE or pokemon_id in cls.IGNORE:
continue
if only:
if pokemon_name not in only and pokemon_id not in only:
if cls.ONLY:
if pokemon_name not in cls.ONLY and pokemon_id not in cls.ONLY:
continue
pokemons.append(p)

Expand Down
1 change: 1 addition & 0 deletions pogom/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def search(args):
i += 1
time.sleep(REQ_SLEEP)


def search_loop(args):
while True:
search(args)
Expand Down
8 changes: 4 additions & 4 deletions runserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pogom.app import Pogom
from pogom.utils import get_args, insert_mock_data, load_credentials
from pogom.search import search_loop
from pogom.models import create_tables
from pogom.models import create_tables, Pokemon
from pogom.pgoapi.utilities import get_pos_by_name

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -48,9 +48,9 @@ def start_locator_thread(args):
config['ORIGINAL_LONGITUDE'] = position[1]

if args.ignore:
config['IGNORE'] = [i.lower().strip() for i in args.ignore.split(',')]
Pokemon.IGNORE = [i.lower().strip() for i in args.ignore.split(',')]
elif args.only:
config['ONLY'] = [i.lower().strip() for i in args.only.split(',')]
Pokemon.ONLY = [i.lower().strip() for i in args.only.split(',')]

if not args.mock:
start_locator_thread(args)
Expand All @@ -60,7 +60,7 @@ def start_locator_thread(args):
app = Pogom(__name__)
config['ROOT_PATH'] = app.root_path
if args.gmaps_key is not None:
config['GMAPS_KEY'] = args.gmaps_key
config['GMAPS_KEY'] = args.gmaps_key
else:
config['GMAPS_KEY'] = load_credentials(os.path.dirname(os.path.realpath(__file__)))['gmaps_key']
app.run(threaded=True, debug=args.debug, host=args.host, port=args.port)

0 comments on commit 95c292a

Please sign in to comment.