Created
July 17, 2022 11:22
-
-
Save icecore2/00e020f5c7a8434b34b347c9c11b935d to your computer and use it in GitHub Desktop.
Pushover service with pushing message.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Full page of API: https://pushover.net/api | |
# Get tokens page: https://pushover.net/#apps | |
import requests | |
class PushOverHandler: | |
def __init__(self,token, user_token): | |
self.token = token | |
self.user_token = user_token | |
self.messages_service_url = 'https://api.pushover.net/1/messages.json' | |
self.sound = 'pianobar' | |
def send_message(self,message, title=None): | |
message_sound = None | |
if self.sound: | |
message_sound = self.sound | |
response = requests.post( | |
url=self.messages_service_url, | |
params={ | |
"token": self.token, | |
"user": self.user_token, | |
"message": message, | |
"title": title, | |
"sound": message_sound | |
} | |
) | |
if __name__ == '__main__': | |
API_TOKEN = '<API_TOKEN>' | |
USER_TOKEN = '<USER_TOKEN>' | |
pushover_handler = PushOverHandler(token=API_TOKEN, user_token=USER_TOKEN) | |
pushover_handler.send_message(message="Hello world! - message", title="Hello world! - title") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment