Reformat legacy project

This commit is contained in:
2022-09-05 07:20:30 +01:00
parent 6b082adeb2
commit 8b9ad05089
59 changed files with 538 additions and 198 deletions

View File

@@ -2,9 +2,8 @@ from copy import deepcopy
from datetime import datetime
from json import dumps
from siphashc import siphash
import main
from siphashc import siphash
from utils.logging.debug import debug
@@ -12,16 +11,24 @@ def dedup(numName, b):
c = deepcopy(b)
if "ts" in c.keys():
del c["ts"]
c["approxtime"] = str(datetime.utcnow().timestamp())[: main.config["Tweaks"]["DedupPrecision"]]
c["approxtime"] = str(datetime.utcnow().timestamp())[
: main.config["Tweaks"]["DedupPrecision"]
]
castHash = siphash(main.hashKey, dumps(c, sort_keys=True))
del c["approxtime"]
isDuplicate = any(castHash in main.lastEvents[x] for x in main.lastEvents.keys() if not x == numName)
isDuplicate = any(
castHash in main.lastEvents[x]
for x in main.lastEvents.keys()
if not x == numName
)
if isDuplicate:
debug("Duplicate: %s" % (c))
return True
if numName in main.lastEvents.keys():
main.lastEvents[numName].insert(0, castHash)
main.lastEvents[numName] = main.lastEvents[numName][0 : main.config["Tweaks"]["MaxHash"]] # noqa
main.lastEvents[numName] = main.lastEvents[numName][
0 : main.config["Tweaks"]["MaxHash"]
] # noqa
else:
main.lastEvents[numName] = [castHash]
return False