Skip to content

Instantly share code, notes, and snippets.

@aeroevan
Created August 9, 2013 21:13
Show Gist options
  • Save aeroevan/6197254 to your computer and use it in GitHub Desktop.
Save aeroevan/6197254 to your computer and use it in GitHub Desktop.
#!/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