Reformatted with black -l 120 -t py35 .

This commit is contained in:
D0han
2019-07-21 19:40:28 +02:00
parent 79062ff3d6
commit e15dc1ce11
17 changed files with 681 additions and 462 deletions

View File

@ -8,8 +8,10 @@ from owrx.map import Map, LatLngLocation
logger = logging.getLogger(__name__)
class DmrCache(object):
sharedInstance = None
@staticmethod
def getSharedInstance():
if DmrCache.sharedInstance is None:
@ -18,21 +20,20 @@ class DmrCache(object):
def __init__(self):
self.cache = {}
self.cacheTimeout = timedelta(seconds = 86400)
self.cacheTimeout = timedelta(seconds=86400)
def isValid(self, key):
if not key in self.cache: return False
if not key in self.cache:
return False
entry = self.cache[key]
return entry["timestamp"] + self.cacheTimeout > datetime.now()
def put(self, key, value):
self.cache[key] = {
"timestamp": datetime.now(),
"data": value
}
self.cache[key] = {"timestamp": datetime.now(), "data": value}
def get(self, key):
if not self.isValid(key): return None
if not self.isValid(key):
return None
return self.cache[key]["data"]
@ -52,8 +53,10 @@ class DmrMetaEnricher(object):
del self.threads[id]
def enrich(self, meta):
if not PropertyManager.getSharedInstance()["digital_voice_dmr_id_lookup"]: return None
if not "source" in meta: return None
if not PropertyManager.getSharedInstance()["digital_voice_dmr_id_lookup"]:
return None
if not "source" in meta:
return None
id = meta["source"]
cache = DmrCache.getSharedInstance()
if not cache.isValid(id):
@ -77,10 +80,7 @@ class YsfMetaEnricher(object):
class MetaParser(object):
enrichers = {
"DMR": DmrMetaEnricher(),
"YSF": YsfMetaEnricher()
}
enrichers = {"DMR": DmrMetaEnricher(), "YSF": YsfMetaEnricher()}
def __init__(self, handler):
self.handler = handler
@ -93,6 +93,6 @@ class MetaParser(object):
protocol = meta["protocol"]
if protocol in MetaParser.enrichers:
additional_data = MetaParser.enrichers[protocol].enrich(meta)
if additional_data is not None: meta["additional"] = additional_data
if additional_data is not None:
meta["additional"] = additional_data
self.handler.write_metadata(meta)