Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

""" 

Message delivery 

 

Various interfaces to messaging services. Currently: 

 

- ``pushover`` - a platform for sending and receiving push notifications 

 

is supported. 

 

AUTHORS: 

 

- Martin Albrecht (2012) - initial implementation 

""" 

from __future__ import absolute_import 

pushover_defaults = {"token": "Eql67F14ohOZJ0AtEBJJU7FiLAk8wK"} 

 

 

def pushover(message, **kwds): 

""" 

Send a push notification with ``message`` to ``user`` using https://pushover.net/. 

 

Pushover is a platform for sending and receiving push notifications. On the server side, it 

provides an HTTP API for queueing messages to deliver to devices. On the device side, iOS and 

Android clients receive those push notifications, show them to the user, and store them for 

offline viewing. 

 

An account on https://pushover.net is required and the Pushover app must be installed on your 

phone for this function to be able to deliver messages to you. 

 

INPUT: 

 

- ``message`` - your message 

 

- ``user`` - the user key (not e-mail address) of your user (or you), viewable when logged 

into the Pushover dashboard. (default: ``None``) 

 

- ``device`` - your user's device identifier to send the message directly to that device, 

rather than all of the user's devices (default: ``None``) 

 

- ``title`` - your message's title, otherwise uses your app's name (default: ``None``) 

 

- ``url`` - a supplementary URL to show with your message (default: ``None``) 

 

- ``url_title`` - a title for your supplementary URL (default: ``None``) 

 

- ``priority`` - set to 1 to display as high-priority and bypass quiet hours, or -1 to always 

send as a quiet notification (default: ``0``) 

 

- ``timestamp`` - set to a unix timestamp to have your message show with a particular time, 

rather than now (default: ``None``) 

 

- ``sound`` - set to the name of one of the sounds supported by device clients to override the 

user's default sound choice (default: ``None``) 

 

- ``token`` - your application's API token (default: Sage's default App token) 

 

EXAMPLES:: 

 

sage: import sage.misc.messaging 

sage: sage.misc.messaging.pushover("Hi, how are you?", user="XXX") # not tested 

 

To set default values populate ``pushover_defaults``:: 

 

sage: sage.misc.messaging.pushover_defaults["user"] = "USER_TOKEN" 

sage: sage.misc.messaging.pushover("Hi, how are you?") # not tested 

 

.. note:: 

 

You may want to populate ``sage.misc.messaging.pushover_defaults`` with default values such 

as the default user in ``$HOME/.sage/init.sage``. 

""" 

# import compatible with py2 and py3 

from six.moves import http_client as httplib 

from six.moves.urllib.parse import urlencode 

 

request = {"message": message} 

request.update(pushover_defaults) 

request.update(kwds) 

 

conn = httplib.HTTPSConnection("api.pushover.net:443") 

conn.request("POST", "/1/messages.json", 

urlencode(request), 

{"Content-type": "application/x-www-form-urlencoded"}) 

return conn.getresponse().status == 200