瀏覽代碼

Add notification.py

Olivier Marty 8 年之前
父節點
當前提交
c9a6658690
共有 1 個文件被更改,包括 23 次插入0 次删除
  1. 23 0
      notification.py

+ 23 - 0
notification.py

@@ -0,0 +1,23 @@
+import config
+import urllib.request
+import urllib.parse
+from subprocess import run
+
+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 !')