mirror of
https://github.com/BOSWatch/BW3-Core.git
synced 2025-12-06 07:12:04 +01:00
resolve threads (:
This commit is contained in:
parent
c7f99bcfcb
commit
a12af18b54
|
|
@ -45,7 +45,7 @@ geoRegex|Regex Capture-Group zum Herausfiltern der Adresse|
|
||||||
---
|
---
|
||||||
## Paket Modifikationen
|
## Paket Modifikationen
|
||||||
|
|
||||||
- Im Paket werden die Felder `lat` und `lng` hinterlegt
|
- Im Paket werden die Felder `lat` und `lon` hinterlegt
|
||||||
|
|
||||||
---
|
---
|
||||||
## Zusätzliche Wildcards
|
## Zusätzliche Wildcards
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,9 @@
|
||||||
---
|
---
|
||||||
|
|
||||||
## Beschreibung
|
## Beschreibung
|
||||||
Mit diesem Plugin ist es moeglich, Telegram-Nachrichten für POCSAG-Alarmierungen zu senden. Außerdem werden Locations versenden, wenn die Felder `lat` und `lng` im Paket definiert sind.
|
Mit diesem Plugin ist es moeglich, Telegram-Nachrichten für POCSAG-Alarmierungen zu senden.
|
||||||
|
Außerdem werden Locations versenden, wenn die Felder `lat` und `lon` im Paket definiert sind. (beispielsweise durch das Geocoding-Modul)
|
||||||
|
|
||||||
|
|
||||||
## Unterstütze Alarmtypen
|
## Unterstütze Alarmtypen
|
||||||
- Pocsag
|
- Pocsag
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
by Bastian Schroll
|
by Bastian Schroll
|
||||||
|
|
||||||
@file: geocoding.py
|
@file: geocoding.py
|
||||||
@date: 01.03.2019
|
@date: 22.02.2020
|
||||||
@author: Jan Speller
|
@author: Jan Speller
|
||||||
@description: Geocoding Module
|
@description: Geocoding Module
|
||||||
"""
|
"""
|
||||||
|
|
@ -38,7 +38,6 @@ class BoswatchModule(ModuleBase):
|
||||||
@param bwPacket: A BOSWatch packet instance"""
|
@param bwPacket: A BOSWatch packet instance"""
|
||||||
if bwPacket.get("mode") == "pocsag":
|
if bwPacket.get("mode") == "pocsag":
|
||||||
self.geocode(bwPacket)
|
self.geocode(bwPacket)
|
||||||
pass
|
|
||||||
|
|
||||||
return bwPacket
|
return bwPacket
|
||||||
|
|
||||||
|
|
@ -49,24 +48,24 @@ class BoswatchModule(ModuleBase):
|
||||||
try:
|
try:
|
||||||
address = re.search(self.config.get("regex"), bwPacket.get("message"))[1]
|
address = re.search(self.config.get("regex"), bwPacket.get("message"))[1]
|
||||||
provider = self.config.get("apiProvider")
|
provider = self.config.get("apiProvider")
|
||||||
|
|
||||||
|
logging.info("Found address: '" + address + "' in packet")
|
||||||
if "mapbox" == provider:
|
if "mapbox" == provider:
|
||||||
|
logging.info("Using Mapbox as provider")
|
||||||
g = geocoder.mapbox(address, key=self.config.get("apiToken"))
|
g = geocoder.mapbox(address, key=self.config.get("apiToken"))
|
||||||
print(address)
|
|
||||||
elif "google" == provider:
|
elif "google" == provider:
|
||||||
|
logging.info("Using Google as provider")
|
||||||
g = geocoder.google(address, key=self.config.get("apiToken"))
|
g = geocoder.google(address, key=self.config.get("apiToken"))
|
||||||
else:
|
else:
|
||||||
return bwPacket
|
return bwPacket
|
||||||
|
|
||||||
(lat, lng) = g.latlng
|
(lat, lon) = g.latlng
|
||||||
|
logging.info("Found following coordinates for address: [lat=" + str(lat) + ", lon=" + str(lon) + "]")
|
||||||
bwPacket.set("lat", lat)
|
bwPacket.set("lat", lat)
|
||||||
bwPacket.set("lng", lng)
|
bwPacket.set("lon", lon)
|
||||||
return bwPacket
|
return bwPacket
|
||||||
except (IndexError, TypeError, ValueError):
|
except (IndexError, TypeError, ValueError):
|
||||||
logging.warning("Address was not found in current Message, skipping geocoding")
|
logging.warning("Address was not found in current Message, skipping geocoding")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error("Unknown Error while executing geocoding module: " + str(type(e).__name__) + ": " + str(e))
|
logging.error("Unknown Error while executing geocoding module: " + str(type(e).__name__) + ": " + str(e))
|
||||||
return bwPacket
|
return bwPacket
|
||||||
|
|
||||||
def onUnload(self):
|
|
||||||
"""!Called by destruction of the plugin"""
|
|
||||||
pass
|
|
||||||
|
|
|
||||||
|
|
@ -36,24 +36,26 @@ class BoswatchPlugin(PluginBase):
|
||||||
def onLoad(self):
|
def onLoad(self):
|
||||||
"""!Called by import of the plugin"""
|
"""!Called by import of the plugin"""
|
||||||
self.bot = telegram.Bot(token=self.config.get("botToken", default=""))
|
self.bot = telegram.Bot(token=self.config.get("botToken", default=""))
|
||||||
pass
|
|
||||||
|
|
||||||
def pocsag(self, bwPacket):
|
def pocsag(self, bwPacket):
|
||||||
"""!Called on POCSAG alarm
|
"""!Called on POCSAG alarm
|
||||||
|
|
||||||
@param bwPacket: bwPacket instance"""
|
@param bwPacket: bwPacket instance"""
|
||||||
msg = bwPacket.get("ric") + " (" + bwPacket.get("subric") + ")\n" + bwPacket.get("message")
|
msg = bwPacket.get("ric") + " (" + bwPacket.get("subric") + ")\n" + bwPacket.get("message")
|
||||||
if bwPacket.get("lat") is not None and bwPacket.get("lng") is not None:
|
if bwPacket.get("lat") is not None and bwPacket.get("lon") is not None:
|
||||||
(lat, lng) = (bwPacket.get("lat"), bwPacket.get("lng"))
|
logging.info("Found coordinates in packet")
|
||||||
|
(lat, lon) = (bwPacket.get("lat"), bwPacket.get("lon"))
|
||||||
|
|
||||||
for chatId in self.config.get("chatIds", default=[]):
|
for chatId in self.config.get("chatIds", default=[]):
|
||||||
try:
|
try:
|
||||||
# Send Message via Telegram
|
# Send Message via Telegram
|
||||||
|
logging.info("Sending message to " + chatId)
|
||||||
self.bot.send_message(chat_id=chatId, text=msg)
|
self.bot.send_message(chat_id=chatId, text=msg)
|
||||||
|
|
||||||
# Send Location via Telegram if lat and lng are defined
|
# Send Location via Telegram if lat and lon are defined
|
||||||
if lat is not None and lng is not None:
|
if lat is not None and lon is not None:
|
||||||
self.bot.sendLocation(chat_id=chatId, latitude=lat, longitude=lng)
|
logging.info("Sending location to " + chatId)
|
||||||
|
self.bot.sendLocation(chat_id=chatId, latitude=lat, longitude=lon)
|
||||||
except Unauthorized:
|
except Unauthorized:
|
||||||
logging.error("Error while sending Telegram Message, please Check your api-key")
|
logging.error("Error while sending Telegram Message, please Check your api-key")
|
||||||
except (TimedOut, NetworkError):
|
except (TimedOut, NetworkError):
|
||||||
|
|
@ -62,4 +64,3 @@ class BoswatchPlugin(PluginBase):
|
||||||
logging.error("Error while sending Telegram Message")
|
logging.error("Error while sending Telegram Message")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error("Unknown Error while sending Telegram Message: " + str(type(e).__name__) + ": " + str(e))
|
logging.error("Unknown Error while sending Telegram Message: " + str(type(e).__name__) + ": " + str(e))
|
||||||
pass
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue