Initial
This commit is contained in:
65
pushover.py
Executable file
65
pushover.py
Executable file
@@ -0,0 +1,65 @@
|
||||
import os
|
||||
import argparse
|
||||
|
||||
import requests
|
||||
|
||||
|
||||
def get_args():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--message', type=str, help='Message text')
|
||||
parser.add_argument('--title', type=str, help='Message title')
|
||||
parser.add_argument('--url', type=str, help='Supplementary URL to show with your message')
|
||||
parser.add_argument('--url_title', type=str, help='title for your supplementary URL, otherwise just the URL is shown')
|
||||
parser.add_argument('--device', type=str, help='Device name to send the message directly to')
|
||||
parser.add_argument('--priority', type=str, help='Notification priority (low-to-high: -2 to 1)')
|
||||
parser.add_argument('--sound', type=str, help='The name of a supported sound (https://pushover.net/api#sounds; custom sounds are supported)')
|
||||
args = parser.parse_args()
|
||||
return args
|
||||
|
||||
def main():
|
||||
args = get_args()
|
||||
|
||||
token = os.environ['PUSHOVER_APP_TOKEN']
|
||||
user = os.environ['PUSHOVER_USER_TOKEN']
|
||||
|
||||
msg: str = args.message
|
||||
title: str | None = args.title if args.title else None
|
||||
url: str | None = args.url if args.url else None
|
||||
url_title: str | None = args.url_title if args.url_title else None
|
||||
device: str | None = args.device if args.device else None
|
||||
priority: str | None = args.priority if args.priority else None
|
||||
sound: str | None = args.sound if args.sound else None
|
||||
|
||||
if not msg:
|
||||
print('No message provided')
|
||||
return
|
||||
|
||||
payload = {
|
||||
'token' : token,
|
||||
'user' : user,
|
||||
'message' : msg
|
||||
}
|
||||
if title:
|
||||
payload['title'] = title
|
||||
if url:
|
||||
payload['url'] = url
|
||||
if url_title:
|
||||
payload['url_title'] = url_title
|
||||
if device:
|
||||
payload['device'] = device
|
||||
if priority:
|
||||
payload['priority'] = priority
|
||||
if sound:
|
||||
payload['sound'] = sound
|
||||
|
||||
response = requests.post(
|
||||
url='https://api.pushover.net/1/messages.json',
|
||||
headers={'Content-Type': 'application/x-www-form-urlencoded'},
|
||||
data=payload,
|
||||
timeout=60
|
||||
)
|
||||
response.raise_for_status()
|
||||
print(response.text)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Reference in New Issue
Block a user