e
This commit is contained in:
parent
9caa2f50d1
commit
00000d9342
6 changed files with 10 additions and 12 deletions
|
|
@ -1,5 +1,4 @@
|
|||
import json
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
from .config import Time
|
||||
|
|
@ -12,14 +11,10 @@ class Cache:
|
|||
self.exp = exp
|
||||
self.now_ts = Time.now().timestamp()
|
||||
|
||||
@staticmethod
|
||||
def clean(dt: datetime) -> float:
|
||||
return dt.replace(second=0, microsecond=0).timestamp()
|
||||
|
||||
def is_fresh(self, entry: dict) -> bool:
|
||||
ts: float | int = entry.get("timestamp", 31496400)
|
||||
|
||||
dt_ts = self.clean(Time.from_ts(ts))
|
||||
dt_ts = Time.clean(Time.from_ts(ts)).timestamp()
|
||||
|
||||
return self.now_ts - dt_ts < self.exp
|
||||
|
||||
|
|
@ -34,7 +29,7 @@ class Cache:
|
|||
|
||||
ts: float | int = data.get("timestamp", 31496400)
|
||||
|
||||
dt_ts = self.clean(Time.from_ts(ts))
|
||||
dt_ts = Time.clean(Time.from_ts(ts)).timestamp()
|
||||
|
||||
return data if self.is_fresh({"timestamp": dt_ts}) else {}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue