Created
April 24, 2010 00:54
-
-
Save anonymous/377357 to your computer and use it in GitHub Desktop.
Sample code for sending self notifications to notifo
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 | |
# This code is part of the public domain | |
# user settings | |
USERNAME = "__username__goes__here__" | |
API_SECRET = "__secret__api__key__goes__here__" | |
# notify IO Info | |
URL = "https://%s:%s@api.notifo.com/v1/send_notification" % (USERNAME, API_SECRET) | |
# Actual Code | |
from optparse import OptionParser | |
from urllib import urlopen, urlencode | |
def parse_options(): | |
from optparse import OptionParser | |
parser = OptionParser() | |
parser.add_option("-l", "--label", dest="label", default="Me", | |
help="the label of the notification") | |
parser.add_option("-t", "--title", dest="title", default="Test", | |
help="the title of the notification") | |
parser.add_option("-b", "--body", dest="body", default="[None]", | |
help="the body of the notification") | |
parser.add_option("-u", "--uri", dest="uri", default=None, | |
help="The URI for the notification (Optional)") | |
return parser.parse_args() | |
def push(body="", title="Test", label="Me", uri=None): | |
data = { 'label':label, 'title':title, 'msg':body } | |
if uri: | |
data['uri'] = uri | |
data_str = urlencode(data) | |
return urlopen(URL, data_str) | |
def main(options, args): | |
for n in push(**vars(options)): | |
print n | |
if __name__ == '__main__': | |
(options, args) = parse_options() | |
main(options, args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment