e
This commit is contained in:
parent
c8e49d9fbb
commit
00000d9077
7 changed files with 25 additions and 113 deletions
|
|
@ -68,20 +68,23 @@ def get_logger(name: str | None = None) -> logging.Logger:
|
|||
return logger
|
||||
|
||||
|
||||
def load_ts_cache(
|
||||
def load_cache(
|
||||
file: Path,
|
||||
cache_exp: int | float,
|
||||
exp: int | float = None,
|
||||
hour: int = None,
|
||||
) -> dict[str, dict[str, str | float]]:
|
||||
try:
|
||||
data: dict[str, dict[str, str | float]] = json.loads(
|
||||
file.read_text(encoding="utf-8")
|
||||
)
|
||||
data = json.loads(file.read_text(encoding="utf-8"))
|
||||
|
||||
return {
|
||||
k: v
|
||||
for k, v in data.items()
|
||||
if now.timestamp() - v.get("timestamp", 0) < cache_exp
|
||||
}
|
||||
if exp:
|
||||
return {
|
||||
k: v
|
||||
for k, v in data.items()
|
||||
if now.timestamp() - v.get("timestamp", 0) < exp
|
||||
}
|
||||
|
||||
elif hour:
|
||||
return {} if now.hour <= hour else data
|
||||
except (FileNotFoundError, json.JSONDecodeError):
|
||||
return {}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue