BOSWatch/plugins/yowsup/yowsup.py

67 lines
2.1 KiB
Python
Raw Normal View History

2016-10-29 15:46:36 +02:00
#!/usr/bin/python
# -*- coding: cp1252 -*-
"""
Yowsup-Plugin to dispatch POCSAG - messages to WhatsApp Numbers or Chats
@author: fwmarcel
@requires: yowsup2 has to be installed
whatsapp number and password
yowsup-Configuration has to be set in the config.ini
"""
2016-11-20 13:05:24 +01:00
import logging
2016-10-29 15:46:36 +02:00
import subprocess
import shlex
import os
2016-11-20 13:05:24 +01:00
from includes import globalVars
2016-10-29 15:46:36 +02:00
2016-11-20 13:37:29 +01:00
#from includes.helper import timeHandler
2016-10-29 15:46:36 +02:00
from includes.helper import wildcardHandler
from includes.helper import configHandler
def onLoad():
return
def run(typ,freq,data):
try:
if configHandler.checkConfig("yowsup"):
empfaenger = globalVars.config.get("yowsup", "empfaenger")
sender = globalVars.config.get("yowsup", "sender")
password = globalVars.config.get("yowsup", "password")
devnull = open(os.devnull, "wb")
2016-11-20 13:05:24 +01:00
2016-10-29 15:46:36 +02:00
if typ == "FMS":
text = globalVars.config.get("yowsup","fms_message")
2016-11-20 13:05:24 +01:00
text = wildcardHandler.replaceWildcards(text, data)
2016-10-29 15:46:36 +02:00
cmd = 'yowsup-cli demos -l ' + sender + ':' + password + ' -s ' + empfaenger + ' "' + text + '" -M'
2016-10-29 15:47:35 +02:00
subprocess.call(shlex.split(cmd), stdout=devnull, stderr=devnull)
2016-10-29 15:46:36 +02:00
logging.debug("Message has been sent")
elif typ == "ZVEI":
text = globalVars.config.get("yowsup","zvei_message")
2016-11-20 13:05:24 +01:00
text = wildcardHandler.replaceWildcards(text, data)
2016-10-29 15:46:36 +02:00
cmd = 'yowsup-cli demos -l ' + sender + ':' + password + ' -s ' + empfaenger + ' "' + text + '" -M'
2016-10-29 15:47:35 +02:00
subprocess.call(shlex.split(cmd), stdout=devnull, stderr=devnull)
2016-10-29 15:46:36 +02:00
logging.debug("Message has been sent")
elif typ == "POC":
try:
text = globalVars.config.get("yowsup","poc_message")
2016-11-20 13:05:24 +01:00
text = wildcardHandler.replaceWildcards(text, data)
2016-10-29 15:46:36 +02:00
cmd = 'yowsup-cli demos -l ' + sender + ':' + password + ' -s ' + empfaenger + ' "' + text + '" -M'
subprocess.call(shlex.split(cmd), stdout=devnull, stderr=devnull)
logging.debug("Message has been sent")
except:
logging.error("Message not send")
logging.debug("Message not send")
return
else:
logging.warning("Invalid Typ: %s", typ)
except:
logging.error("unknown error")
logging.debug("unknown error", exc_info=True)