Skip to content

Commit

Permalink
filter on sponsor and park
Browse files Browse the repository at this point in the history
  • Loading branch information
evilmoses authored and billyjbryant committed Feb 25, 2018
1 parent 911c92c commit b5e1f48
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 0 deletions.
6 changes: 6 additions & 0 deletions PokeAlarm/Events/EggEvent.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ def __init__(self, data):
str, data.get('description'), Unknown.REGULAR).strip()
self.gym_image = check_for_none(
str, data.get('url'), Unknown.REGULAR)
self.gym_sponsor = check_for_none(
int, data.get('sponsor'), Unknown.SMALL)
self.gym_park = check_for_none(
str, data.get('park'), Unknown.REGULAR)

# Gym Team (this is only available from cache)
self.current_team_id = check_for_none(
Expand Down Expand Up @@ -95,6 +99,8 @@ def generate_dts(self, locale, timezone, units):
'gym_name': self.gym_name,
'gym_description': self.gym_description,
'gym_image': self.gym_image,
'gym_sponsor': self.gym_sponsor,
'gym_park': self.gym_park,
'team_id': self.current_team_id,
'team_name': locale.get_team_name(self.current_team_id),
'team_leader': locale.get_leader_name(self.current_team_id)
Expand Down
6 changes: 6 additions & 0 deletions PokeAlarm/Events/RaidEvent.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ def __init__(self, data):
str, data.get('description'), Unknown.REGULAR).strip()
self.gym_image = check_for_none(
str, data.get('url'), Unknown.REGULAR)
self.gym_sponsor = check_for_none(
int, data.get('sponsor'), Unknown.SMALL)
self.gym_park = check_for_none(
str, data.get('park'), Unknown.REGULAR)

# Gym Team (this is only available from cache)
self.current_team_id = check_for_none(
Expand Down Expand Up @@ -208,6 +212,8 @@ def generate_dts(self, locale, timezone, units):
'gym_name': self.gym_name,
'gym_description': self.gym_description,
'gym_image': self.gym_image,
'gym_sponsor': self.gym_sponsor,
'gym_park': self.gym_park,
'team_id': self.current_team_id,
'team_name': locale.get_team_name(self.current_team_id),
'team_leader': locale.get_leader_name(self.current_team_id)
Expand Down
21 changes: 21 additions & 0 deletions PokeAlarm/Filters/EggFilter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Standard Library Imports
import operator
import re
# 3rd Party Imports
# Local Imports
from . import BaseFilter
Expand Down Expand Up @@ -51,6 +52,18 @@ def __init__(self, name, data):
limit=BaseFilter.parse_as_set(
GymUtils.create_regex, 'gym_name_excludes', data))

# Gym sponsor
self.gym_sponsor_index_contains = self.evaluate_attribute(
event_attribute='gym_sponsor', eval_func=GymUtils.match_regex_dict,
limit=BaseFilter.parse_as_set(
re.compile, 'gym_sponsor_index_contains', data))

# Gym park
self.gym_park_contains = self.evaluate_attribute( # f.gp matches e.gp
event_attribute='gym_park', eval_func=GymUtils.match_regex_dict,
limit=BaseFilter.parse_as_set(
re.compile, 'gym_park_contains', data))

# Team Info
self.old_team = self.evaluate_attribute( # f.ctis contains m.cti
event_attribute='current_team_id', eval_func=operator.contains,
Expand Down Expand Up @@ -93,6 +106,14 @@ def to_dict(self):
if self.gym_name_contains is not None:
settings['gym_name_matches'] = self.gym_name_contains

# Gym Sponsor
if self.gym_sponsor_index_contains is not None:
settings['gym_sponsor_matches'] = self.gym_sponsor_index_contains

# Gym Park
if self.gym_park_contains is not None:
settings['gym_park_matches'] = self.gym_park_contains

# Geofences
if self.geofences is not None:
settings['geofences'] = self.geofences
Expand Down
21 changes: 21 additions & 0 deletions PokeAlarm/Filters/RaidFilter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Standard Library Imports
import operator
import re
# 3rd Party Imports
# Local Imports
from . import BaseFilter
Expand Down Expand Up @@ -78,6 +79,18 @@ def __init__(self, name, data):
limit=BaseFilter.parse_as_set(
GymUtils.create_regex, 'gym_name_excludes', data))

# Gym sponsor
self.gym_sponsor_index_contains = self.evaluate_attribute(
event_attribute='gym_sponsor', eval_func=GymUtils.match_regex_dict,
limit=BaseFilter.parse_as_set(
re.compile, 'gym_sponsor_index_contains', data))

# Gym park
self.gym_park_contains = self.evaluate_attribute(
event_attribute='gym_park', eval_func=GymUtils.match_regex_dict,
limit=BaseFilter.parse_as_set(
re.compile, 'gym_park_contains', data))

# Team Info
self.old_team = self.evaluate_attribute( # f.ctis contains m.cti
event_attribute='current_team_id', eval_func=operator.contains,
Expand Down Expand Up @@ -132,6 +145,14 @@ def to_dict(self):
if self.gym_name_contains is not None:
settings['gym_name_matches'] = self.gym_name_contains

# Gym Sponsor
if self.gym_sponsor_index_contains is not None:
settings['gym_sponsor_matches'] = self.gym_sponsor_index_contains

# Gym Park
if self.gym_park_contains is not None:
settings['gym_park_matches'] = self.gym_park_contains

# Geofences
if self.geofences is not None:
settings['geofences'] = self.geofences
Expand Down
4 changes: 4 additions & 0 deletions tools/webhook_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ def set_init(webhook_type):
"message": {
"gym_id": 0,
"gym_name": "unknown",
"park": None,
"sponsor": 4,
"level": 5,
"latitude": 37.7876146,
"longitude": -122.390624
Expand All @@ -137,6 +139,8 @@ def set_init(webhook_type):
"message": {
"gym_id": 0,
"gym_name": "unknown",
"park": "Test Park",
"sponsor": 4,
"pokemon_id": 150,
"cp": 12345,
"move_1": 123,
Expand Down

0 comments on commit b5e1f48

Please sign in to comment.