Posted by: Eric Hansen
when relevant content is
added and updated.
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.