Skip to content

Instantly share code, notes, and snippets.

@joelparker
Created January 10, 2013 00:37
Show Gist options
  • Save joelparker/4498369 to your computer and use it in GitHub Desktop.
Save joelparker/4498369 to your computer and use it in GitHub Desktop.
Send a success or failure push notification from my slow build machine to my phone using Parse.com. When I get a push notification I know to go back to my terminal. The python is pretty much cut and paste from Parse's Rest API tutorial. An example: #Use build.sh instead of make build.sh 2>&1 | tee foo
#!/bin/bash
my_pwd=`pwd`
run_make_from_pwd="(cd ${my_pwd} && make)"
python ~/bin/push_build_status.py "${run_make_from_pwd}"
import json,httplib
import os
#From the Dashboard of your Parse app
APPLICATION_ID = "CHANGE ME"
REST_API_KEY = "CHANGE ME TOO"
COMMAND_SUCCESS_MESSAGE = "BUILD Finished"
COMMAND_FAILED_MESSAGE = "BUILD Failed"
def run_system_command(cmd):
return os.system(cmd)
def send_push_notification(msg):
connection = httplib.HTTPSConnection('api.parse.com', 443)
connection.connect()
connection.request('POST', '/1/push', json.dumps({
"channels": [""
],
"data": {
"alert": msg,
"sound": "default"
}
}), {
"X-Parse-Application-Id": APPLICATION_ID,
"X-Parse-REST-API-Key": REST_API_KEY,
"Content-Type": "application/json"
})
result = json.loads(connection.getresponse().read())
if __name__ == "__main__":
try:
command = os.sys.argv[1]
result = run_system_command(command)
if result == 0:
send_push_notification( COMMAND_SUCCESS_MESSAGE)
else:
send_push_notification(COMMAND_FAILED_MESSAGE)
except IndexError:
print "Please provide a command to run"
exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment