Browse Source

Change method into methods : allowing mutliple notifications

Olivier Marty 8 years ago
parent
commit
eeb872ab53
2 changed files with 15 additions and 15 deletions
  1. 1 1
      config.py
  2. 14 14
      notification.py

+ 1 - 1
config.py

@@ -16,7 +16,7 @@ sources = {
 # NOTIFICATIONS
 
 notification = {
-  'method' : 'print', # ou "free" ou "sendmail"
+  'methods' : ['print'], # "free", "sendmail"
   'free' : { # méthode "free" (sms api voir http://mobile.free.fr/ )
     'user' : '123456789',
     'pass' : 'wwwwwwwww'

+ 14 - 14
notification.py

@@ -7,17 +7,17 @@ def notify(message):
    """usage : notify("message")
    """
    conf = config.notification
-   method = conf['method']
-   if method == "free":
-      data = urllib.parse.urlencode({
-        'user' : conf['free']['user'],
-        'pass' : conf['free']['pass'],
-        'msg' : message
-      })
-      urllib.request.urlopen("https://smsapi.free-mobile.fr/sendmsg?" + data)
-   elif method == 'sendmail':
-      run(['mail', '-s', conf['sendmail']['object'], conf['sendmail']['to']], input=message.encode(), check=True)
-   elif method == 'print':
-      print(message)
-   else:
-      raise NotImplementedError('notification method = ' + method + ' not known !')
+   for method in conf['methods']:
+     if method == "free":
+        data = urllib.parse.urlencode({
+          'user' : conf['free']['user'],
+          'pass' : conf['free']['pass'],
+          'msg' : message
+        })
+        urllib.request.urlopen("https://smsapi.free-mobile.fr/sendmsg?" + data)
+     elif method == 'sendmail':
+        run(['mail', '-s', conf['sendmail']['object'], conf['sendmail']['to']], input=message.encode(), check=True)
+     elif method == 'print':
+        print(message)
+     else:
+        raise NotImplementedError('notification method = ' + method + ' not known !')