<commit_before># Standard Library Imports
import logging
# 3rd Party Imports
from pushbullet import PushBullet
# Local Imports
from ..Alarm import Alarm
from ..Utils import parse_boolean, require_and_remove_key, reject_leftover_parameters

log = logging.getLogger(__name__)
try_sending = Alarm.try_sending
replace = Alarm.replace


#####################################################  ATTENTION!  #####################################################
# You DO NOT NEED to edit this file to customize messages for services! Please see the Wiki on the correct way to
# customize services In fact, doing so will likely NOT work correctly with many features included in PokeAlarm.
#                               PLEASE ONLY EDIT IF YOU KNOW WHAT YOU ARE DOING!
#####################################################  ATTENTION!  #####################################################


class PushbulletAlarm(Alarm):
    _defaults = {
        'pokemon': {
            'title': "A wild <pkmn> has appeared!",
            'url': "<gmaps>",
            'body': "Available until <24h_time> (<time_left>)."
        },
        'pokestop': {
            'title': "Someone has placed a lure on a Pokestop!",
            'url': "<gmaps>",
            'body': "Lure will expire at <24h_time> (<time_left>)."
        },
        'gym': {
            'title': "A Team <old_team> gym has fallen!",
            'url': "<gmaps>",
            'body': "It is now controlled by <new_team>."
        },
        'egg': {
            'title': "A level <raid_level> raid is incoming!",
            'url': "<gmaps>",
            'body': "The egg will hatch <begin_24h_time> (<begin_time_left>)."
        },
        'raid': {
            'title': "A Raid is available against <pkmn>!",
            'url': "<gmaps>",
            'body': "The raid is available until <24h_time> (<time_left>)."
        }
    }


    # Gather settings and create alarm
    def __init__(self, settings):
        # Required Parameters
        self.__api_key = require_and_remove_key('api_key', settings, "'Pushbullet' type alarms.")
        self.__client = None

        # Optional Alarm Parameters
        self.__startup_message = parse_boolean(settings.pop('startup_message', "True"))
        self.__channel = settings.pop('channel', "True")
        self.__sender = None

        # Optional Alert Parameters
        self.__pokemon = self.create_alert_settings(settings.pop('pokemon', {}), self._defaults['pokemon'])
        self.__pokestop = self.create_alert_settings(settings.pop('pokestop', {}), self._defaults['pokestop'])
        self.__gym = self.create_alert_settings(settings.pop('gyms', {}), self._defaults['gym'])
        self.__egg = self.create_alert_settings(settings.pop('egg', {}), self._defaults['egg'])
        self.__raid = self.create_alert_settings(settings.pop('raid', {}), self._defaults['raid'])

        #  Warn user about leftover parameters
        reject_leftover_parameters(settings, "'Alarm level in Pushbullet alarm.")

        log.info("Pushbullet Alarm has been created!")

    # Establish connection with Pushbullet
    def connect(self):
        self.__client = PushBullet(self.__api_key)
        self.__sender = self.get_sender(self.__channel)
        self.__pokemon['sender'] = self.get_sender(self.__pokemon['channel'])
        self.__pokestop['sender'] = self.get_sender(self.__pokestop['channel'])
        self.__gym['sender'] = self.get_sender(self.__gym['channel'])

    def startup_message(self):
        if self.__startup_message:
            args = {
                "sender": self.__sender,
                "title": "PokeAlarm activated!",
                "message": "PokeAlarm has successully started!"
            }
            try_sending(log, self.connect, "PushBullet", self.push_note, args)
            log.info("Startup message sent!")

    # Set the appropriate settings for each alert
    def create_alert_settings(self, settings, default):
        alert = {
            'title': settings.pop('title', default['title']),
            'url': settings.pop('url', default['url']),
            'body': settings.pop('body', default['body']),
            'channel': settings.pop('channel', None)
        }<commit_msg>Fixed Egg/Raid notifications for Pushbullet.<commit_after># Standard Library Imports
import logging
# 3rd Party Imports
from pushbullet import PushBullet
# Local Imports
from ..Alarm import Alarm
from ..Utils import parse_boolean, require_and_remove_key, reject_leftover_parameters

log = logging.getLogger(__name__)
try_sending = Alarm.try_sending
replace = Alarm.replace


#####################################################  ATTENTION!  #####################################################
# You DO NOT NEED to edit this file to customize messages for services! Please see the Wiki on the correct way to
# customize services In fact, doing so will likely NOT work correctly with many features included in PokeAlarm.
#                               PLEASE ONLY EDIT IF YOU KNOW WHAT YOU ARE DOING!
#####################################################  ATTENTION!  #####################################################


class PushbulletAlarm(Alarm):
    _defaults = {
        'pokemon': {
            'title': "A wild <pkmn> has appeared!",
            'url': "<gmaps>",
            'body': "Available until <24h_time> (<time_left>)."
        },
        'pokestop': {
            'title': "Someone has placed a lure on a Pokestop!",
            'url': "<gmaps>",
            'body': "Lure will expire at <24h_time> (<time_left>)."
        },
        'gym': {
            'title': "A Team <old_team> gym has fallen!",
            'url': "<gmaps>",
            'body': "It is now controlled by <new_team>."
        },
        'egg': {
            'title': "A level <raid_level> raid is incoming!",
            'url': "<gmaps>",
            'body': "The egg will hatch <begin_24h_time> (<begin_time_left>)."
        },
        'raid': {
            'title': "A Raid is available against <pkmn>!",
            'url': "<gmaps>",
            'body': "The raid is available until <24h_time> (<time_left>)."
        }
    }


    # Gather settings and create alarm
    def __init__(self, settings):
        # Required Parameters
        self.__api_key = require_and_remove_key('api_key', settings, "'Pushbullet' type alarms.")
        self.__client = None

        # Optional Alarm Parameters
        self.__startup_message = parse_boolean(settings.pop('startup_message', "True"))
        self.__channel = settings.pop('channel', "True")
        self.__sender = None

        # Optional Alert Parameters
        self.__pokemon = self.create_alert_settings(settings.pop('pokemon', {}), self._defaults['pokemon'])
        self.__pokestop = self.create_alert_settings(settings.pop('pokestop', {}), self._defaults['pokestop'])
        self.__gym = self.create_alert_settings(settings.pop('gyms', {}), self._defaults['gym'])
        self.__egg = self.create_alert_settings(settings.pop('egg', {}), self._defaults['egg'])
        self.__raid = self.create_alert_settings(settings.pop('raid', {}), self._defaults['raid'])

        #  Warn user about leftover parameters
        reject_leftover_parameters(settings, "'Alarm level in Pushbullet alarm.")

        log.info("Pushbullet Alarm has been created!")

    # Establish connection with Pushbullet
    def connect(self):
        self.__client = PushBullet(self.__api_key)
        self.__sender = self.get_sender(self.__channel)
        self.__pokemon['sender'] = self.get_sender(self.__pokemon['channel'])
        self.__pokestop['sender'] = self.get_sender(self.__pokestop['channel'])
        self.__gym['sender'] = self.get_sender(self.__gym['channel'])
        self.__egg['sender'] = self.get_sender(self.__egg['channel'])
        self.__raid['sender'] = self.get_sender(self.__raid['channel'])

    def startup_message(self):
        if self.__startup_message:
            args = {
                "sender": self.__sender,
                "title": "PokeAlarm activated!",
                "message": "PokeAlarm has successully started!"
            }
            try_sending(log, self.connect, "PushBullet", self.push_note, args)
            log.info("Startup message sent!")

    # Set the appropriate settings for each alert
    def create_alert_settings(self, settings, default):
        alert = {
            'title': settings.pop('title', default['title']),
            'url': settings.pop('url', default['url']),
            'body': settings.pop('body', default['body']),
            'channel': settings.pop('channel', None)
        }
{'fraction_non_alphanumeric': 0.17319539695455075, 'fraction_numerical': 0.00209229338602813, 'mean_word_length': 2.8496644295302014, 'pattern_counts': {'":': 6, '<': 39, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2750827', 'n_tokens_mistral': 2486, 'n_tokens_neox': 2347, 'n_words': 600}