I.T. Security and Linux Administration

Oct 31 2012   4:45PM GMT

[Python] Send notifications to your phone using Pushover

Eric Hansen Eric Hansen Profile: Eric Hansen

Sure there’s Python modules out there that let you use Pushover, a smartphone service that lets you send notifications from any device to your phone, but all of them I’ve seen so far limit your messages to 512.  This makes perfect sense in that Pushover limits messages to 512 characters.  However, that’s not to say you can’t send bigger messages per-say.

Before continuing I will say I haven’t test this code (but it is based off of the code Pushover.net provides for Python).  The reason being is I don’t feel there’s a need to pay $5 for the app (on Android, not sure if it has a price on the Apple store).  However, I still feel this script will serve a use.

The script it self can be found here: https://github.com/SecurityForUs/PushOverPy/blob/master/pushover.py and uses redis to store information (feel free to modify it).  You do need to set your API token and key that Pushover gives you when you initialize the class (i.e.: po = PushOver(token=”…”, key=”…”)), but after that everything is pretty much smooth sailing.

The sendmsg() method does what most others do as well, which is meet the bare minimum of pushing a message to your phone.  However, this one also takes it a step further and fully supports all of the API’s features for sending a message (as of this writing).  This includes sending it to a specific device, back/future timestamp it, send URLs, prioritize it, etc…  It was one feature that does separate my class from others, but as I said before it also sends messages that are longer than 512 characters.

What it does is break messages up into chunks, so every (by default) 512 characters it will push out a notification.  Now, if you’re sending such big messages in the first place you might want to think about what you can eliminate, but otherwise this will meet your needs.  Other scripts I’ve seen will only get the first 512, and/or raise an exception saying that the message is too big.

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: