Skip to content

Instantly share code, notes, and snippets.

@ErebusBat
Created April 26, 2013 14:45
Show Gist options
  • Save ErebusBat/5467839 to your computer and use it in GitHub Desktop.
Save ErebusBat/5467839 to your computer and use it in GitHub Desktop.
Simple Boxcar.io notifier strategy for goxtool
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