Ejemplo n.º 1
0
    def send_message(self, message='', **kwargs):
        """Send a message to a Simplepush user."""
        from simplepush import send, send_encrypted

        title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)

        if self._password:
            send_encrypted(self._device_key, self._password, self._salt, title,
                           message, event=self._event)
        else:
            send(self._device_key, title, message, event=self._event)
Ejemplo n.º 2
0
    def send_message(self, message='', **kwargs):
        """Send a message to a Simplepush user."""
        from simplepush import send, send_encrypted

        title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)

        if self._password:
            send_encrypted(self._device_key,
                           self._password,
                           self._salt,
                           title,
                           message,
                           event=self._event)
        else:
            send(self._device_key, title, message, event=self._event)
Ejemplo n.º 3
0
def validate_input(entry: dict[str, str]) -> dict[str, str] | None:
    """Validate user input."""
    try:
        if CONF_PASSWORD in entry:
            send_encrypted(
                entry[CONF_DEVICE_KEY],
                entry[CONF_PASSWORD],
                entry[CONF_PASSWORD],
                "HA test",
                "Message delivered successfully",
            )
        else:
            send(entry[CONF_DEVICE_KEY], "HA test",
                 "Message delivered successfully")
    except UnknownError:
        return {"base": "cannot_connect"}

    return None
Ejemplo n.º 4
0
def send_online_following_simplepush():
    global config, previous_online_following, online_following
    for channel in [
            x for x in online_following
            if x['name'] not in previous_online_following
    ]:
        nsfw_string = ' (NSFW)' if channel['adult'] else ''
        title = 'Picarto user %s online!%s' % (channel['name'], nsfw_string)
        msg = '%s is now streaming%s, check it out! https://picarto.tv/%s' % (
            channel['name'], nsfw_string, channel['name'])
        if (len(config['simplepush_key']) > 0):
            simplepush.send(config['simplepush_key'], title, msg)
        if (len(config['ifttt_key']) > 0):
            body = {"value1": channel['name']}
            url = "https://maker.ifttt.com/trigger/picarto_online/with/key/%s" % (
                config['ifttt_key'])
            r = requests.post(url, data=body)
        if (len(config['ifttt_key']) + len(config['simplepush_key']) > 0):
            print("Sent notification about %s" % (channel['name']))
Ejemplo n.º 5
0
class SimplePushNotificationService(BaseNotificationService):
    """Implementation of the notification service for Simplepush."""
    def __init__(self, config: dict[str, Any]) -> None:
        """Initialize the Simplepush notification service."""
        self._device_key: str = config[CONF_DEVICE_KEY]
        self._event: str | None = config.get(CONF_EVENT)
        self._password: str | None = config.get(CONF_PASSWORD)
        self._salt: str | None = config.get(CONF_SALT)

    def send_message(self, message: str, **kwargs: Any) -> None:
        """Send a message to a Simplepush user."""
        title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)

        # event can now be passed in the service data
        event = None
        if data := kwargs.get(ATTR_DATA):
            event = data.get(ATTR_EVENT)

        # use event from config until YAML config is removed
        event = event or self._event

        try:
            if self._password:
                send_encrypted(
                    self._device_key,
                    self._password,
                    self._salt,
                    title,
                    message,
                    event=event,
                )
            else:
                send(self._device_key, title, message, event=event)

        except BadRequest:
            _LOGGER.error("Bad request. Title or message are too long")
        except UnknownError:
            _LOGGER.error("Failed to send the notification")
Ejemplo n.º 6
0
def send_training_complete_push(title, desc):
    if simplepush_key:
        send(simplepush_key, title, desc, 'trainingComplete')
Ejemplo n.º 7
0
r = requests.get('https://hacker-news.firebaseio.com/v0/topstories.json')

simplepush_id = "{{ SIX CHARACTER SIMPLEPUSH ID HERE }}"
hn_id = ""
i = 0
score = 0

# Fetches the details from the first 30 story IDs (since the HN homepage contains 30 stories).
while i < 30:
    hn_id = json.loads(r.text)[i]
    r2 = requests.get('https://hacker-news.firebaseio.com/v0/item/' +
                      str(hn_id) + '.json?print=pretty')
    # Gets the score of the ID
    score = json.loads(r2.text)['score']
    # Checks if the score is bigger than 500 and proceeds if it is.
    if score > 500:
        print("\nHN ID: " + str(hn_id))
        # Open the history file
        with open(".hn-to-simplepush.history", "r+") as history_file:
            # Checks if the ID is already in the notification history.
            line_found = any(str(hn_id) in line for line in history_file)
            print("line_found = " + str(line_found))
            if not line_found:
                # Append the ID to a file so that this ID wouldn't trigger notifications over and over again every time you run the script.
                history_file.write(str(hn_id) + "\n")
                # Send a Simplepush notification
                send(simplepush_id,
                     json.loads(r2.text)['title'],
                     json.loads(r2.text)['url'])
    i = i + 1
Ejemplo n.º 8
0
if __name__ == '__main__':

    while (True):
        # Example for exchanging driver license
        appointments = get_termins(DMV, 'FS Umschreibung Ausländischer FS')
        if appointments:
            t = time.localtime()
            current_time = time.strftime("%H:%M:%S", t)
            print(current_time)
            apps = appointments["Termin FS Allgemeinschalter_G"][
                'appoints'].values()
            for a in apps:
                if a:
                    # Replace the first param with the key you get on your app.
                    # https://simplepush.io/
                    send("HuxgBB", "Appointments Available", a, len(a))
            print(
                json.dumps(appointments,
                           sort_keys=True,
                           indent=4,
                           separators=(',', ': ')))
        time.sleep(600)

    # # Example for Anmeldung
    # appointments = get_termins(CityHall, 'An- oder Ummeldung - Einzelperson')

    # # Example for NE with Blue Card
    # appointments = get_termins(ForeignLabor, 'Werkverträge')

    # # Example for KFZ and car registration
    # appointments = get_termins(KFZ, 'ZUL Fabrikneues Fahrzeug')