This commit is contained in:
Loic Guegan 2020-10-09 14:35:08 +02:00
parent 404db42aea
commit d848b9ce3c

View file

@ -24,23 +24,23 @@ def notify_done(key):
data=dict() data=dict()
with open(CACHE_FILE, 'rb') as f: with open(CACHE_FILE, 'rb') as f:
data=pickle.load(f) data=pickle.load(f)
if datetime.timestamp(datetime.now()) - data["ts"] >= CACHE_EXPIRE*60: if datetime.timestamp(datetime.now()) - data[key] >= CACHE_EXPIRE*60:
remove(CACHE_FILE) remove(CACHE_FILE)
return(False) return(False)
else: else:
return(key in data["keys"]) return(key in data)
# Save notify key in cache # Save notify key in cache
def add_key(key): def add_key(key):
if not(path.exists(CACHE_FILE)): if not(path.exists(CACHE_FILE)):
with open(CACHE_FILE, 'wb') as f: with open(CACHE_FILE, 'wb') as f:
pickle.dump({"ts":datetime.timestamp(datetime.now()),"keys":key},f) pickle.dump({key:datetime.timestamp(datetime.now())},f)
else: else:
data=list() data=list()
with open(CACHE_FILE, 'rb') as f: with open(CACHE_FILE, 'rb') as f:
data=pickle.load(f) data=pickle.load(f)
if not(key in data["keys"]): if not(key in data["keys"]):
data["keys"].append(key) data[key]=datetime.timestamp(datetime.now())
with open(CACHE_FILE, 'wb') as f: with open(CACHE_FILE, 'wb') as f:
pickle.dump(data,f) pickle.dump(data,f)