notification.py 790 B

1234567891011121314151617181920212223
  1. import config
  2. import urllib.request
  3. import urllib.parse
  4. from subprocess import run
  5. def notify(message):
  6. """usage : notify("message")
  7. """
  8. conf = config.notification
  9. for method in conf['methods']:
  10. if method == "free":
  11. data = urllib.parse.urlencode({
  12. 'user' : conf['free']['user'],
  13. 'pass' : conf['free']['pass'],
  14. 'msg' : message
  15. })
  16. urllib.request.urlopen("https://smsapi.free-mobile.fr/sendmsg?" + data)
  17. elif method == 'sendmail':
  18. run(['mail', '-s', conf['sendmail']['object'], conf['sendmail']['to']], input=message.encode(), check=True)
  19. elif method == 'print':
  20. print("[NOTIFICATION] " + message)
  21. else:
  22. raise NotImplementedError('notification method = ' + method + ' not known !')