Usage Examples¶
Chump’s meant to be easy to use. Sending a message is just as simple as in the example above, but there’s more you can do.
Creating and sending a message yourself¶
If you’d like to send messages yourself, just swap out
send_message()
for create_message()
:
>>> message = user.create_message("Happy birthday, chuck!")
>>> message.is_sent, message.id
(False, None)
>>> message.send()
True
>>> message.is_sent, message.id, str(message.sent_at)
(True, 'fZSrekCvxi2vnpVADWBNchAGrllDi4cZ', '1993-12-17 06:03:45+00:00')
Sending messages with additional parameters¶
Chump supports all the message parameters outlined in Pushover’s
API Docs. Any of these parameters can be
optionally supplied as kwargs
:
>>> message = user.create_message(
... title="No Crackers, Gromit!",
... message="<b>We've forgotten the crackers!</b>",
... html=True,
... sound='intermission'
... )
>>> (str(message), message.sound)
('(No Crackers, Gromit!) <b>We've forgotten the crackers!</b>', 'intermission')
And Chump will raise the appropriate exceptions if your kwargs
violate the
API restrictions:
>>> message = user.create_message(
... "Gromit, we have a problem!"
... sound='this is not a sound'
... )
ValueError: Bad sound: must be in ('alien', 'bike', 'bugle',
'cashregister', 'classical', 'climb', 'cosmic', 'echo', 'falling',
'gamelan', 'incoming', 'intermission', 'magic', 'mechanical', 'none',
'persistent', 'pianobar', 'pushover', 'siren', 'spacealarm', 'tugboat',
'updown'), was 'this is not a sound'
All parameters are exposed as attributes in the Message
,
so you can change them later.
Sending an emergency message¶
Pushover’s emergency messages have a few additions over standard messages. They
require dismissal from the user, and if not dismissed they’ll keep popping up
every retry
seconds until timeout
seconds from when they were sent.
When the user acknowledges the message, callback
will be pinged by
Pushover’s servers, but you can also check in on the message’s status by
calling poll()
:
>>> message = user.send_message(
... "Do something, Gromit!",
... priority=chump.EMERGENCY
... )
>>> message.is_sent, message.id, message.is_acknowledged
(True, 'eChnqsE5nZyefIbTVMuS9cfDV77mMaN9', False)
>>> message.poll()
False
>>> str(message.acknowledged_at)
'1995-12-24 06:10:39+00:00'
poll()
returns True
whilst the message
has not been acknowledged, so you can use it cleanly as a condition in
while loops.