Created
April 26, 2013 14:45
-
-
Save ErebusBat/5467839 to your computer and use it in GitHub Desktop.
Simple Boxcar.io notifier strategy for goxtool
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
import urllib.request, urllib.error, urllib.parse | |
import platform | |
import sys | |
import configparser | |
import os | |
from optparse import OptionParser | |
from time import time | |
def notify(username, password, sender, message): | |
url = 'https://boxcar.io/notifications' | |
values = { | |
'notification[from_screen_name]' : sender, | |
'notification[message]' : message, | |
'notification[from_remote_service_id]' : int(time()*100) | |
} | |
passman = urllib.request.HTTPPasswordMgrWithDefaultRealm() | |
passman.add_password(None, url, username, password) | |
authhandler = urllib.request.HTTPBasicAuthHandler(passman) | |
opener = urllib.request.build_opener(authhandler) | |
urllib.request.install_opener(opener) | |
data = urllib.parse.urlencode( values ) | |
try: | |
response = urllib.request.urlopen(url, data.encode('utf8')) | |
except IOError as e: | |
if (hasattr(e, 'reason')): | |
print('Error submitting http request:', e.reason) | |
return 1 | |
if (hasattr(e, 'code')): | |
print('Error submitting http request:', e.code) | |
return 1 | |
except Exception as e: | |
print('Unhandled error caught', e.str()) | |
return 1 | |
return 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment