mirror of
https://github.com/Schrolli91/BOSWatch.git
synced 2025-12-06 07:42:03 +01:00
PEP8 changes to pushover
This commit is contained in:
parent
f92ce0d5f8
commit
cf1b5b3fc4
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -9,3 +9,5 @@ log/
|
||||||
\.pydevproject
|
\.pydevproject
|
||||||
|
|
||||||
\.settings/
|
\.settings/
|
||||||
|
|
||||||
|
\.idea/
|
||||||
|
|
|
||||||
|
|
@ -9,31 +9,32 @@ Pushover-Plugin to send FMS-, ZVEI- and POCSAG - messages to Pushover Clients
|
||||||
@requires: Pushover-Configuration has to be set in the config.ini
|
@requires: Pushover-Configuration has to be set in the config.ini
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import logging # Global logger
|
import logging # Global logger
|
||||||
import httplib #for the HTTP request
|
import httplib # for the HTTP request
|
||||||
import urllib
|
import urllib
|
||||||
from includes import globalVars # Global variables
|
from includes import globalVars # Global variables
|
||||||
|
|
||||||
#from includes.helper import timeHandler
|
# from includes.helper import timeHandler
|
||||||
from includes.helper import configHandler
|
from includes.helper import configHandler
|
||||||
from includes.helper import wildcardHandler
|
from includes.helper import wildcardHandler
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
#
|
#
|
||||||
# onLoad (init) function of plugin
|
# onLoad (init) function of plugin
|
||||||
# will be called one time by the pluginLoader on start
|
# will be called one time by the pluginLoader on start
|
||||||
#
|
#
|
||||||
def onLoad():
|
def onLoad():
|
||||||
"""
|
"""
|
||||||
While loading the plugins by pluginLoader.loadPlugins()
|
While loading the plugins by pluginLoader.loadPlugins()
|
||||||
this onLoad() routine is called one time for initialize the plugin
|
this onLoad() routine is called one time for initialize the plugin
|
||||||
|
|
||||||
@requires: nothing
|
@requires: nothing
|
||||||
|
|
||||||
@return: nothing
|
@return: nothing
|
||||||
"""
|
"""
|
||||||
# nothing to do for this plugin
|
# nothing to do for this plugin
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
@ -41,112 +42,112 @@ def onLoad():
|
||||||
# Main function of Pushover-plugin
|
# Main function of Pushover-plugin
|
||||||
# will be called by the alarmHandler
|
# will be called by the alarmHandler
|
||||||
#
|
#
|
||||||
def run(typ,freq,data):
|
def run(typ, freq, data):
|
||||||
"""
|
"""
|
||||||
This function is the implementation of the Pushover-Plugin.
|
This function is the implementation of the Pushover-Plugin.
|
||||||
It will send the data to Pushover API
|
It will send the data to Pushover API
|
||||||
|
|
||||||
@type typ: string (FMS|ZVEI|POC)
|
@type typ: string (FMS|ZVEI|POC)
|
||||||
@param typ: Typ of the dataset
|
@param typ: Typ of the dataset
|
||||||
@type data: map of data (structure see readme.md in plugin folder)
|
@type data: map of data (structure see readme.md in plugin folder)
|
||||||
@param data: Contains the parameter
|
@param data: Contains the parameter
|
||||||
@type freq: string
|
@type freq: string
|
||||||
@keyword freq: frequency of the SDR Stick
|
@keyword freq: frequency of the SDR Stick
|
||||||
|
|
||||||
@requires: Pushover-Configuration has to be set in the config.ini
|
@requires: Pushover-Configuration has to be set in the config.ini
|
||||||
|
|
||||||
@return: nothing
|
@return: nothing
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
if configHandler.checkConfig("Pushover"): #read and debug the config
|
if configHandler.checkConfig("Pushover"): # read and debug the config
|
||||||
|
|
||||||
if typ == "FMS":
|
if typ == "FMS":
|
||||||
#
|
#
|
||||||
# building message for FMS
|
# building message for FMS
|
||||||
#
|
#
|
||||||
|
|
||||||
message = globalVars.config.get("Pushover", "fms_message")
|
|
||||||
title = globalVars.config.get("Pushover", "fms_title")
|
|
||||||
priority = globalVars.config.get("Pushover", "fms_prio")
|
|
||||||
logging.debug("Sending message: %s", message)
|
|
||||||
|
|
||||||
elif typ == "ZVEI":
|
|
||||||
#
|
|
||||||
# building message for ZVEI
|
|
||||||
#
|
|
||||||
message = globalVars.config.get("Pushover", "zvei_message")
|
|
||||||
title = globalVars.config.get("Pushover", "zvei_title")
|
|
||||||
priority = globalVars.config.get("Pushover", "zvei_prio")
|
|
||||||
logging.debug("Sending message: %s", message)
|
|
||||||
|
|
||||||
elif typ == "POC":
|
|
||||||
|
|
||||||
#
|
|
||||||
# Pushover-Request
|
|
||||||
#
|
|
||||||
logging.debug("send Pushover for %s", typ)
|
|
||||||
|
|
||||||
if data["function"] == '1':
|
|
||||||
priority = globalVars.config.get("Pushover", "SubA")
|
|
||||||
elif data["function"] == '2':
|
|
||||||
priority = globalVars.config.get("Pushover", "SubB")
|
|
||||||
elif data["function"] == '3':
|
|
||||||
priority = globalVars.config.get("Pushover", "SubC")
|
|
||||||
elif data["function"] == '4':
|
|
||||||
priority = globalVars.config.get("Pushover", "SubD")
|
|
||||||
else:
|
|
||||||
priority = 0
|
|
||||||
message = globalVars.config.get("Pushover", "poc_message")
|
|
||||||
title = globalVars.config.get("Pushover", "poc_title")
|
|
||||||
|
|
||||||
else:
|
|
||||||
logging.warning("Invalid type: %s", typ)
|
|
||||||
|
|
||||||
try:
|
|
||||||
# replace the wildcards
|
|
||||||
message = wildcardHandler.replaceWildcards(message,data)
|
|
||||||
title = wildcardHandler.replaceWildcards(title,data)
|
|
||||||
|
|
||||||
# start the connection
|
|
||||||
conn = httplib.HTTPSConnection("api.pushover.net:443")
|
|
||||||
conn.request("POST", "/1/messages.json",
|
|
||||||
urllib.urlencode({
|
|
||||||
"token": globalVars.config.get("Pushover", "api_key"),
|
|
||||||
"user": globalVars.config.get("Pushover", "user_key"),
|
|
||||||
"message": message,
|
|
||||||
"html": globalVars.config.get("Pushover", "html"),
|
|
||||||
"title": title,
|
|
||||||
"priority": priority,
|
|
||||||
"retry": globalVars.config.get("Pushover", "retry"),
|
|
||||||
"expire": globalVars.config.get("Pushover", "expire")
|
|
||||||
}),{"Content-type": "application/x-www-form-urlencoded"})
|
|
||||||
|
|
||||||
except:
|
message = globalVars.config.get("Pushover", "fms_message")
|
||||||
logging.error("cannot send Pushover request")
|
title = globalVars.config.get("Pushover", "fms_title")
|
||||||
logging.debug("cannot send Pushover request", exc_info=True)
|
priority = globalVars.config.get("Pushover", "fms_prio")
|
||||||
return
|
logging.debug("Sending message: %s", message)
|
||||||
|
|
||||||
try:
|
elif typ == "ZVEI":
|
||||||
#
|
#
|
||||||
# check Pushover-Response
|
# building message for ZVEI
|
||||||
#
|
#
|
||||||
response = conn.getresponse()
|
message = globalVars.config.get("Pushover", "zvei_message")
|
||||||
if str(response.status) == "200": #Check Pushover Response and print a Log or Error
|
title = globalVars.config.get("Pushover", "zvei_title")
|
||||||
logging.debug("Pushover response: %s - %s" , str(response.status), str(response.reason))
|
priority = globalVars.config.get("Pushover", "zvei_prio")
|
||||||
else:
|
logging.debug("Sending message: %s", message)
|
||||||
logging.warning("Pushover response: %s - %s" , str(response.status), str(response.reason))
|
|
||||||
except: #otherwise
|
|
||||||
logging.error("cannot get Pushover response")
|
|
||||||
logging.debug("cannot get Pushover response", exc_info=True)
|
|
||||||
return
|
|
||||||
|
|
||||||
finally:
|
elif typ == "POC":
|
||||||
logging.debug("close Pushover-Connection")
|
|
||||||
try:
|
|
||||||
request.close()
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
except:
|
#
|
||||||
logging.error("unknown error")
|
# Pushover-Request
|
||||||
logging.debug("unknown error", exc_info=True)
|
#
|
||||||
|
logging.debug("send Pushover for %s", typ)
|
||||||
|
|
||||||
|
if data["function"] == '1':
|
||||||
|
priority = globalVars.config.get("Pushover", "SubA")
|
||||||
|
elif data["function"] == '2':
|
||||||
|
priority = globalVars.config.get("Pushover", "SubB")
|
||||||
|
elif data["function"] == '3':
|
||||||
|
priority = globalVars.config.get("Pushover", "SubC")
|
||||||
|
elif data["function"] == '4':
|
||||||
|
priority = globalVars.config.get("Pushover", "SubD")
|
||||||
|
else:
|
||||||
|
priority = 0
|
||||||
|
message = globalVars.config.get("Pushover", "poc_message")
|
||||||
|
title = globalVars.config.get("Pushover", "poc_title")
|
||||||
|
|
||||||
|
else:
|
||||||
|
logging.warning("Invalid type: %s", typ)
|
||||||
|
|
||||||
|
try:
|
||||||
|
# replace the wildcards
|
||||||
|
message = wildcardHandler.replaceWildcards(message, data)
|
||||||
|
title = wildcardHandler.replaceWildcards(title, data)
|
||||||
|
|
||||||
|
# start the connection
|
||||||
|
conn = httplib.HTTPSConnection("api.pushover.net:443")
|
||||||
|
conn.request("POST", "/1/messages.json",
|
||||||
|
urllib.urlencode({
|
||||||
|
"token": globalVars.config.get("Pushover", "api_key"),
|
||||||
|
"user": globalVars.config.get("Pushover", "user_key"),
|
||||||
|
"message": message,
|
||||||
|
"html": globalVars.config.get("Pushover", "html"),
|
||||||
|
"title": title,
|
||||||
|
"priority": priority,
|
||||||
|
"retry": globalVars.config.get("Pushover", "retry"),
|
||||||
|
"expire": globalVars.config.get("Pushover", "expire")
|
||||||
|
}), {"Content-type": "application/x-www-form-urlencoded"})
|
||||||
|
|
||||||
|
except:
|
||||||
|
logging.error("cannot send Pushover request")
|
||||||
|
logging.debug("cannot send Pushover request", exc_info=True)
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
#
|
||||||
|
# check Pushover-Response
|
||||||
|
#
|
||||||
|
response = conn.getresponse()
|
||||||
|
if str(response.status) == "200": # Check Pushover Response and print a Log or Error
|
||||||
|
logging.debug("Pushover response: %s - %s", str(response.status), str(response.reason))
|
||||||
|
else:
|
||||||
|
logging.warning("Pushover response: %s - %s", str(response.status), str(response.reason))
|
||||||
|
except: # otherwise
|
||||||
|
logging.error("cannot get Pushover response")
|
||||||
|
logging.debug("cannot get Pushover response", exc_info=True)
|
||||||
|
return
|
||||||
|
|
||||||
|
finally:
|
||||||
|
logging.debug("close Pushover-Connection")
|
||||||
|
try:
|
||||||
|
request.close()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
except:
|
||||||
|
logging.error("unknown error")
|
||||||
|
logging.debug("unknown error", exc_info=True)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue