BOSWatch 3
Python Script to receive and decode German BOS Information with rtl_fm and multimon-NG
 
Loading...
Searching...
No Matches
module.geocoding.BoswatchModule Class Reference

Description of the Module. More...

Public Member Functions

def __init__ (self, config)
 Do not change anything here!
 
def doWork (self, bwPacket)
 start an run of the module.
 
def geocode (self, bwPacket)
 find address in message and get latitude and longitude
 
- Public Member Functions inherited from module.moduleBase.ModuleBase
def __init__ (self, moduleName, config)
 init preload some needed locals and then call onLoad() directly
 
def onLoad (self)
 Called by import of the module can be inherited.
 
def doWork (self, bwPacket)
 Called module run can be inherited.
 
def onUnload (self)
 Called on shutdown of boswatch can be inherited.
 

Additional Inherited Members

- Static Public Member Functions inherited from module.moduleBase.ModuleBase
def registerWildcard (newWildcard, bwPacketField)
 Register a new wildcard.
 
- Data Fields inherited from module.moduleBase.ModuleBase
 config
 
- Protected Member Functions inherited from module.moduleBase.ModuleBase
def _cleanup (self)
 Cleanup routine calls onUnload() directly.
 
def _run (self, bwPacket)
 start an run of the module.
 
def _getStatistics (self)
 Returns statistical information's from last module run.
 
- Protected Attributes inherited from module.moduleBase.ModuleBase
 _moduleName
 
 _cumTime
 
 _moduleTime
 
 _runCount
 
 _moduleErrorCount
 
- Static Protected Attributes inherited from module.moduleBase.ModuleBase
list _modulesActive = []
 

Detailed Description

Description of the Module.

Constructor & Destructor Documentation

◆ __init__()

def module.geocoding.BoswatchModule.__init__ (   self,
  config 
)

Do not change anything here!

Reimplemented from module.moduleBase.ModuleBase.

31 def __init__(self, config):
32 r"""!Do not change anything here!"""
33 super().__init__(__name__, config) # you can access the config class on 'self.config'
34

Member Function Documentation

◆ doWork()

def module.geocoding.BoswatchModule.doWork (   self,
  bwPacket 
)

start an run of the module.

    @param bwPacket: A BOSWatch packet instance

Reimplemented from module.moduleBase.ModuleBase.

35 def doWork(self, bwPacket):
36 r"""!start an run of the module.
37
38 @param bwPacket: A BOSWatch packet instance"""
39 if bwPacket.get("mode") == "pocsag":
40 self.geocode(bwPacket)
41
42 return bwPacket
43

◆ geocode()

def module.geocoding.BoswatchModule.geocode (   self,
  bwPacket 
)

find address in message and get latitude and longitude

    @param bwPacket: A BOSWatch packet instance
44 def geocode(self, bwPacket):
45 r"""!find address in message and get latitude and longitude
46
47 @param bwPacket: A BOSWatch packet instance"""
48 try:
49 addressArray = re.search(self.config.get("regex"), bwPacket.get("message"))
50 provider = self.config.get("apiProvider")
51
52 if addressArray[1] is None:
53 logging.info("No address found, skipping geocoding")
54 return bwPacket
55
56 address = addressArray[1]
57 bwPacket.set("address", address)
58 self.registerWildcard("{ADDRESS}", "address")
59 logging.info("Found address: '" + address + "' in packet")
60
61 if "mapbox" == provider:
62 logging.info("Using Mapbox as provider")
63 g = geocoder.mapbox(address, key=self.config.get("apiToken"))
64 elif "google" == provider:
65 logging.info("Using Google as provider")
66 g = geocoder.google(address, key=self.config.get("apiToken"))
67 else:
68 return bwPacket
69
70 (lat, lon) = g.latlng
71 logging.info("Found following coordinates for address: [lat=" + str(lat) + ", lon=" + str(lon) + "]")
72 bwPacket.set("lat", lat)
73 bwPacket.set("lon", lon)
74 self.registerWildcard("{LAT}", "lat")
75 self.registerWildcard("{LON}", "lon")
76
77 return bwPacket
78 except Exception as e:
79 logging.exception("Unknown Error while executing geocoding module: " + str(type(e).__name__) + ": " + str(e))
80 return bwPacket