Last active
July 19, 2017 19:15
-
-
Save robinkunde/59c6ea6a25fb31baf0836c4557ff8682 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python3 | |
import os | |
import argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument('message') | |
parser.add_argument('--start', type=int, help='Pass start timestamp to append run time to notification') | |
parser.add_argument('--apikey', type=str, help='Pushover API key (can also be implicitly defined as ENV variable in $PUSHOVER_API_KEY)', default=os.getenv('PUSHOVER_API_KEY', '')) | |
parser.add_argument('--userkey', type=str, help='Pushover user key (can also be implicitly defined as ENV variable in $PUSHOVER_USER_KEY)', default=os.getenv('PUSHOVER_USER_KEY', '')) | |
args = parser.parse_args() | |
if args.apikey == "" or args.userkey == "": | |
print('error: API key and user key must either be passed as arguments or set in environment variables $PUSHOVER_API_KEY and $PUSHOVER_USER_KEY') | |
exit(1) | |
message = args.message | |
if args.start != None: | |
import time | |
import datetime | |
now = int(time.time()) | |
duration = now - args.start | |
message += " (run time: {0})".format(datetime.timedelta(seconds=duration)) | |
# you can install chump using pip | |
from chump import Application | |
app = Application(args.apikey) | |
app.is_authenticated | |
user = app.get_user(args.userkey) | |
message = user.send_message(message) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
usage: