You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
894 B
Python
28 lines
894 B
Python
2 years ago
|
from copy import deepcopy
|
||
2 years ago
|
from datetime import datetime
|
||
2 years ago
|
from json import dumps
|
||
2 years ago
|
|
||
2 years ago
|
from siphashc import siphash
|
||
2 years ago
|
|
||
5 years ago
|
import main
|
||
|
from utils.logging.debug import debug
|
||
|
|
||
2 years ago
|
|
||
4 years ago
|
def dedup(numName, b):
|
||
|
c = deepcopy(b)
|
||
2 years ago
|
if "ts" in c.keys():
|
||
|
del c["ts"]
|
||
2 years ago
|
c["approxtime"] = str(datetime.utcnow().timestamp())[: main.config["Tweaks"]["DedupPrecision"]]
|
||
2 years ago
|
castHash = siphash(main.hashKey, dumps(c, sort_keys=True))
|
||
5 years ago
|
del c["approxtime"]
|
||
2 years ago
|
isDuplicate = any(castHash in main.lastEvents[x] for x in main.lastEvents.keys() if not x == numName)
|
||
5 years ago
|
if isDuplicate:
|
||
|
debug("Duplicate: %s" % (c))
|
||
|
return True
|
||
|
if numName in main.lastEvents.keys():
|
||
|
main.lastEvents[numName].insert(0, castHash)
|
||
2 years ago
|
main.lastEvents[numName] = main.lastEvents[numName][0 : main.config["Tweaks"]["MaxHash"]] # noqa
|
||
5 years ago
|
else:
|
||
|
main.lastEvents[numName] = [castHash]
|
||
|
return False
|