Created
August 9, 2013 21:13
-
-
Save aeroevan/6197254 to your computer and use it in GitHub Desktop.
Python replacement for https://gist.github.com/kurtisnelson/6188982
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 python | |
import os | |
import sys | |
import json | |
import argparse | |
import requests | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-a', '--application', | |
help='Application name sending the notification', | |
required=True) | |
parser.add_argument('-t', '--title', | |
help='Optional title of the notification') | |
parser.add_argument('-m', '--message', | |
help='Notification message', required=True) | |
parser.add_argument('-p', '--priority', action='store_true') | |
parser.add_argument('--token', | |
help='Optional token to use, defualts to $GLASS_TOKEN') | |
args = vars(parser.parse_args()) | |
url = None | |
if args['token']: | |
url = ''.join(['https://api.picar.us/openglass/notify/', | |
args['token']]) | |
else: | |
token = os.environ.get('GLASS_TOKEN') | |
if token is None: | |
sys.exit(' '.join(['Token not given via --token or', | |
'$GLASS_TOKEN environment variable'])) | |
else: | |
url = ''.join(['https://api.picar.us/openglass/notify/', token]) | |
requests.post(url, data=json.dumps({k: v for k, v in args.items() | |
if k != 'token'})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment