diff --git a/docu/docs/modul/geocoding.md b/docu/docs/modul/geocoding.md index ca939ea..5876f08 100644 --- a/docu/docs/modul/geocoding.md +++ b/docu/docs/modul/geocoding.md @@ -45,7 +45,7 @@ geoRegex|Regex Capture-Group zum Herausfiltern der Adresse| --- ## Paket Modifikationen -- Im Paket werden die Felder `lat` und `lng` hinterlegt +- Im Paket werden die Felder `lat` und `lon` hinterlegt --- ## Zusätzliche Wildcards diff --git a/docu/docs/plugin/telegram.md b/docu/docs/plugin/telegram.md index d6afdfb..d72a84e 100644 --- a/docu/docs/plugin/telegram.md +++ b/docu/docs/plugin/telegram.md @@ -2,7 +2,9 @@ --- ## 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 - Pocsag diff --git a/module/geocoding.py b/module/geocoding.py index b2bbb5c..765bafc 100644 --- a/module/geocoding.py +++ b/module/geocoding.py @@ -10,7 +10,7 @@ by Bastian Schroll @file: geocoding.py -@date: 01.03.2019 +@date: 22.02.2020 @author: Jan Speller @description: Geocoding Module """ @@ -38,7 +38,6 @@ class BoswatchModule(ModuleBase): @param bwPacket: A BOSWatch packet instance""" if bwPacket.get("mode") == "pocsag": self.geocode(bwPacket) - pass return bwPacket @@ -49,24 +48,24 @@ class BoswatchModule(ModuleBase): try: address = re.search(self.config.get("regex"), bwPacket.get("message"))[1] provider = self.config.get("apiProvider") + + logging.info("Found address: '" + address + "' in packet") if "mapbox" == provider: + logging.info("Using Mapbox as provider") g = geocoder.mapbox(address, key=self.config.get("apiToken")) - print(address) elif "google" == provider: + logging.info("Using Google as provider") g = geocoder.google(address, key=self.config.get("apiToken")) else: 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("lng", lng) + bwPacket.set("lon", lon) return bwPacket except (IndexError, TypeError, ValueError): logging.warning("Address was not found in current Message, skipping geocoding") except Exception as e: logging.error("Unknown Error while executing geocoding module: " + str(type(e).__name__) + ": " + str(e)) return bwPacket - - def onUnload(self): - """!Called by destruction of the plugin""" - pass diff --git a/plugin/telegram.py b/plugin/telegram.py index 3050afc..b27ce6d 100644 --- a/plugin/telegram.py +++ b/plugin/telegram.py @@ -36,24 +36,26 @@ class BoswatchPlugin(PluginBase): def onLoad(self): """!Called by import of the plugin""" self.bot = telegram.Bot(token=self.config.get("botToken", default="")) - pass def pocsag(self, bwPacket): """!Called on POCSAG alarm @param bwPacket: bwPacket instance""" 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: - (lat, lng) = (bwPacket.get("lat"), bwPacket.get("lng")) + if bwPacket.get("lat") is not None and bwPacket.get("lon") is not None: + logging.info("Found coordinates in packet") + (lat, lon) = (bwPacket.get("lat"), bwPacket.get("lon")) for chatId in self.config.get("chatIds", default=[]): try: # Send Message via Telegram + logging.info("Sending message to " + chatId) self.bot.send_message(chat_id=chatId, text=msg) - # Send Location via Telegram if lat and lng are defined - if lat is not None and lng is not None: - self.bot.sendLocation(chat_id=chatId, latitude=lat, longitude=lng) + # Send Location via Telegram if lat and lon are defined + if lat is not None and lon is not None: + logging.info("Sending location to " + chatId) + self.bot.sendLocation(chat_id=chatId, latitude=lat, longitude=lon) except Unauthorized: logging.error("Error while sending Telegram Message, please Check your api-key") except (TimedOut, NetworkError): @@ -62,4 +64,3 @@ class BoswatchPlugin(PluginBase): logging.error("Error while sending Telegram Message") except Exception as e: logging.error("Unknown Error while sending Telegram Message: " + str(type(e).__name__) + ": " + str(e)) - pass