Last active
May 7, 2020 22:04
-
-
Save tiwo/4e479621b4ebe9d34c715b0e78c53308 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env python3 | |
import http.client | |
import urllib | |
import argparse | |
import sys | |
import logging | |
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG) | |
log = logging.getLogger(__name__) | |
def parse_args(): | |
argparser = argparse.ArgumentParser( | |
description="Send a message via pushover.net") | |
argparser.add_argument( | |
"--to", metavar="RECIPIENT_TOKEN", | |
required=True, | |
dest="recipient") | |
argparser.add_argument( | |
"--application", metavar="APP_TOKEN", | |
required=True, | |
dest="app") | |
argparser.add_argument( | |
"--title", metavar="TEXT", | |
required=False, | |
dest="title") | |
return argparser.parse_args() | |
def send(app_token, recipient_token, message, title=None): | |
payload = { | |
"token": app_token, | |
"user": recipient_token, | |
"message": message, | |
} | |
if title is not None: | |
payload["title"] = title | |
conn = http.client.HTTPSConnection("api.pushover.net:443") | |
conn.request("POST", | |
"/1/messages.json", | |
urllib.parse.urlencode(payload), | |
{ "Content-type": "application/x-www-form-urlencoded" }) | |
return conn.getresponse() | |
if __name__ == "__main__": | |
args = parse_args() | |
message=sys.stdin.read() | |
send(args.app, args.recipient, message, args.title) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment