Browse Source

First steps to v0.2

- Setup script (was not in Git ?!?)
- Bug fix in get_credentials (bad URL)
- Support for new options from AppNotifications 2.0 (icon_url, subtitle...)
- Better UTF-8 support
Thomas Jost 11 years ago
parent
commit
a8c71c46f5
3 changed files with 47 additions and 10 deletions
  1. 4
    0
      .gitignore
  2. 19
    10
      notifications.py
  3. 24
    0
      setup.py

+ 4
- 0
.gitignore View File

@@ -1 +1,5 @@
1 1
 *.pyc
2
+MANIFEST
3
+build/
4
+dist/
5
+*.egg-info/

+ 19
- 10
notifications.py View File

@@ -1,4 +1,5 @@
1 1
 #!/usr/bin/env python
2
+# -*- coding: utf-8 -*-
2 3
 
3 4
 # Copyright (c) 2009, Thomas Jost <thomas.jost@gmail.com>
4 5
 # 
@@ -29,7 +30,7 @@ the message to be sent.
29 30
 """
30 31
 
31 32
 __author__ = "Thomas Jost <thomas.jost@gmail.com>"
32
-__version__ = "0.1"
33
+__version__ = "0.2"
33 34
 
34 35
 
35 36
 import sys
@@ -51,28 +52,30 @@ def get_credentials(email, password):
51 52
     data = urllib.urlencode(data)
52 53
 
53 54
     # Send them
54
-    u = urllib.urlopen(SEND_URL, data)
55
+    u = urllib.urlopen(CREDENTIALS_URL, data)
55 56
     success = (u.getcode() == 200)
56
-    if not success: return False
57
+    if not success:
58
+        return False
57 59
 
58 60
     # Parse the XML response
59 61
     response = u.read()
60 62
     u.close()
61 63
     doc = xml.dom.minidom.parseString(response)
62 64
     token = doc.getElementsByTagName("single-access-token")
63
-    if len(token) == 0: return False
65
+    if len(token) == 0:
66
+        return False
64 67
     return token[0].firstChild.data
65 68
 
66 69
 
67
-def send(credentials, message, title=None, long_message=None,
68
-         long_message_preview=None, message_level=0, silent=False,
70
+def send(credentials, message, title=None, subtitle=None, long_message=None,
71
+         long_message_preview=None, icon_url = None, message_level=0, silent=False,
69 72
          action_loc_key=None, run_command=None, sound=1, debug=False):
70 73
     """Send a notification, waiting for the message to be sent.
71 74
 
72 75
     The first two arguments (credentials  and message) are mandatory, all of the
73 76
     others are optional. They are  the same as the various identifiers described
74 77
     in    the   documentation    of    the   Notifications    HTTP   REST    API
75
-    (http://appnotifications.com/account/rest_api).
78
+    (http://developer.appnotifications.com/p/user_notifications.html).
76 79
 
77 80
     When  `debug` is  set  to `True`,  the XML  result  of the  HTTP request  is
78 81
     displayed on `sys.stderr`.
@@ -92,8 +95,8 @@ def send(credentials, message, title=None, long_message=None,
92 95
     data['user_credentials'] = credentials
93 96
     data['notification[message]'] = message
94 97
 
95
-    for key in ("title", "long_message", "long_message_preview",
96
-                "message_level", "action_loc_key", "run_command"):
98
+    for key in ("title", "subtitle", "long_message", "long_message_preview",
99
+                "icon_url", "message_level", "action_loc_key", "run_command"):
97 100
         value = locals()[key]
98 101
         if value is not None:
99 102
             data['notification[%s]' % key] = value
@@ -107,7 +110,13 @@ def send(credentials, message, title=None, long_message=None,
107 110
         data['notification[sound]'] = "%d.caf" % sound
108 111
 
109 112
     # Encode the data
110
-    data = urllib.urlencode(data)
113
+    try:
114
+        data = urllib.urlencode(data)
115
+    except UnicodeEncodeError:
116
+        for k in data:
117
+            if type(data[k]) is unicode:
118
+                data[k] = data[k].encode('utf-8')
119
+        data = urllib.urlencode(data)
111 120
 
112 121
     # Send the notification
113 122
     u = urllib.urlopen(SEND_URL, data)

+ 24
- 0
setup.py View File

@@ -0,0 +1,24 @@
1
+#!/usr/bin/env python
2
+
3
+from setuptools import setup
4
+from notifications import __version__
5
+
6
+setup(name="notifications",
7
+      version=__version__,
8
+      description="Client for the iPhone/iPod Touch `Notifications' app",
9
+      author="Thomas Jost",
10
+      author_email="thomas.jost@gmail.com",
11
+      license="ISC",
12
+      py_modules=['notifications'],
13
+      classifiers=[
14
+          'Development Status :: 4 - Beta',
15
+          'Intended Audience :: Developers',
16
+          'Intended Audience :: End Users/Desktop',
17
+          'Intended Audience :: System Administrators',
18
+          'License :: OSI Approved :: BSD License',
19
+          'Operating System :: OS Independent',
20
+          'Programming Language :: Python',
21
+          'Topic :: Communications',
22
+          'Topic :: Internet :: WWW/HTTP',
23
+      ]
24
+)

Loading…
Cancel
Save