BOSWatch 3
Python Script to receive and decode German BOS Information with rtl_fm and multimon-NG
 
Loading...
Searching...
No Matches
plugin.telegram.BoswatchPlugin Class Reference

Description of the Plugin. More...

Public Member Functions

 __init__ (self, config)
 Do not change anything here!
 
 onLoad (self)
 Called by import of the plugin.
 
 fms (self, bwPacket)
 Called on FMS alarm.
 
 pocsag (self, bwPacket)
 Called on POCSAG alarm.
 
 zvei (self, bwPacket)
 Called on ZVEI alarm.
 
 msg (self, bwPacket)
 Called on MSG packet.
 
- Public Member Functions inherited from plugin.pluginBase.PluginBase
 setup (self)
 Called before alarm can be inherited.
 
 teardown (self)
 Called after alarm can be inherited.
 
 onUnload (self)
 Called on shutdown of boswatch can be inherited.
 
 parseWildcards (self, msg)
 Return the message with parsed wildcards.
 

Data Fields

 bot
 
- Data Fields inherited from plugin.pluginBase.PluginBase
 config
 

Protected Member Functions

 _sendMessage (self, message)
 
 _sendLocation (self, lat, lon)
 
- Protected Member Functions inherited from plugin.pluginBase.PluginBase
 _cleanup (self)
 Cleanup routine calls onUnload() directly.
 
 _run (self, bwPacket)
 start an complete running turn of an plugin.
 
 _getStatistics (self)
 Returns statistical information's from last plugin run.
 

Additional Inherited Members

- Protected Attributes inherited from plugin.pluginBase.PluginBase
 _pluginName
 
 _bwPacket
 
 _sumTime
 
 _cumTime
 
 _setupTime
 
 _alarmTime
 
 _teardownTime
 
 _runCount
 
 _setupErrorCount
 
 _alarmErrorCount
 
 _teardownErrorCount
 
- Static Protected Attributes inherited from plugin.pluginBase.PluginBase
list _pluginsActive = []
 

Detailed Description

Description of the Plugin.

Constructor & Destructor Documentation

◆ __init__()

plugin.telegram.BoswatchPlugin.__init__ (   self,
  config 
)

Do not change anything here!

Reimplemented from plugin.pluginBase.PluginBase.

56 def __init__(self, config):
57 r"""!Do not change anything here!"""
58 super().__init__(__name__, config) # you can access the config class on 'self.config'
59

Member Function Documentation

◆ onLoad()

plugin.telegram.BoswatchPlugin.onLoad (   self)

Called by import of the plugin.

Reimplemented from plugin.pluginBase.PluginBase.

60 def onLoad(self):
61 r"""!Called by import of the plugin"""
62 if self.config.get("queue", default=True):
63 q = mq.MessageQueue()
64 request = Request(con_pool_size=8)
65 self.bot = MQBot(token=self.config.get("botToken", default=""), request=request, mqueue=q)
66 print('queue')
67 else:
68 self.bot = telegram.Bot(token=self.config.get("botToken"))
69 print('normal')
70

◆ fms()

plugin.telegram.BoswatchPlugin.fms (   self,
  bwPacket 
)

Called on FMS alarm.

Parameters
bwPacketbwPacket instance

Reimplemented from plugin.pluginBase.PluginBase.

71 def fms(self, bwPacket):
72 r"""!Called on FMS alarm
73
74 @param bwPacket: bwPacket instance"""
75 msg = self.parseWildcards(self.config.get("message_fms", default="{FMS}"))
76 self._sendMessage(msg)
77

◆ pocsag()

plugin.telegram.BoswatchPlugin.pocsag (   self,
  bwPacket 
)

Called on POCSAG alarm.

Parameters
bwPacketbwPacket instance

Reimplemented from plugin.pluginBase.PluginBase.

78 def pocsag(self, bwPacket):
79 r"""!Called on POCSAG alarm
80
81 @param bwPacket: bwPacket instance"""
82 msg = self.parseWildcards(self.config.get("message_pocsag", default="{RIC}({SRIC})\n{MSG}"))
83 self._sendMessage(msg)
84
85 if bwPacket.get("lat") is not None and bwPacket.get("lon") is not None:
86 logging.debug("Found coordinates in packet")
87 (lat, lon) = (bwPacket.get("lat"), bwPacket.get("lon"))
88 self._sendLocation(lat, lon)
89

◆ zvei()

plugin.telegram.BoswatchPlugin.zvei (   self,
  bwPacket 
)

Called on ZVEI alarm.

Parameters
bwPacketbwPacket instance

Reimplemented from plugin.pluginBase.PluginBase.

90 def zvei(self, bwPacket):
91 r"""!Called on ZVEI alarm
92
93 @param bwPacket: bwPacket instance"""
94 msg = self.parseWildcards(self.config.get("message_zvei", default="{TONE}"))
95 self._sendMessage(msg)
96

◆ msg()

plugin.telegram.BoswatchPlugin.msg (   self,
  bwPacket 
)

Called on MSG packet.

Parameters
bwPacketbwPacket instance

Reimplemented from plugin.pluginBase.PluginBase.

97 def msg(self, bwPacket):
98 r"""!Called on MSG packet
99
100 @param bwPacket: bwPacket instance"""
101 msg = self.parseWildcards(self.config.get("message_msg"))
102 self._sendMessage(msg)
103

◆ _sendMessage()

plugin.telegram.BoswatchPlugin._sendMessage (   self,
  message 
)
protected
104 def _sendMessage(self, message):
105 for chatId in self.config.get("chatIds", default=[]):
106 try:
107 # Send Message via Telegram
108 logging.info("Sending message to " + chatId)
109 self.bot.send_message(chat_id=chatId, text=message)
110
111 except Unauthorized:
112 logging.exception("Error while sending Telegram Message, please Check your api-key")
113 except (TimedOut, NetworkError):
114 logging.exception("Error while sending Telegram Message, please Check your connectivity")
115 except (BadRequest, TelegramError):
116 logging.exception("Error while sending Telegram Message")
117 except Exception as e:
118 logging.exception("Unknown Error while sending Telegram Message: " + str(type(e).__name__) + ": " + str(e))
119

◆ _sendLocation()

plugin.telegram.BoswatchPlugin._sendLocation (   self,
  lat,
  lon 
)
protected
120 def _sendLocation(self, lat, lon):
121 for chatId in self.config.get("chatIds", default=[]):
122 try:
123 # Send Location via Telegram
124 if lat is not None and lon is not None:
125 logging.info("Sending location to " + chatId)
126 self.bot.sendLocation(chat_id=chatId, latitude=lat, longitude=lon)
127
128 except Unauthorized:
129 logging.exception("Error while sending Telegram Message, please Check your api-key")
130 except (TimedOut, NetworkError):
131 logging.exception("Error while sending Telegram Message, please Check your connectivity")
132 except (BadRequest, TelegramError):
133 logging.exception("Error while sending Telegram Message")
134 except Exception as e:
135 logging.exception("Unknown Error while sending Telegram Message: " + str(type(e).__name__) + ": " + str(e))

Field Documentation

◆ bot

plugin.telegram.BoswatchPlugin.bot