From 372e8251bdf4bd5187c140df89f0c2116ef5aa62 Mon Sep 17 00:00:00 2001 From: amtoaer Date: Wed, 22 Nov 2023 22:11:56 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8A=A0=E5=85=A5=E5=87=AD=E6=8D=AE?= =?UTF-8?q?=E5=88=B7=E6=96=B0=E9=80=BB=E8=BE=91=EF=BC=8C=E6=AF=8F=E6=97=A5?= =?UTF-8?q?=E8=87=B3=E5=A4=9A=E6=A3=80=E6=9F=A5=E4=B8=80=E6=AC=A1=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- processor.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/processor.py b/processor.py index c9fdda6..6477eb8 100644 --- a/processor.py +++ b/processor.py @@ -8,6 +8,9 @@ from asyncio import create_subprocess_exec from asyncio.subprocess import DEVNULL from loguru import logger import asyncio +import datetime + +anchor = datetime.datetime.today() async def download_content(url: str, path: Path): @@ -21,8 +24,18 @@ async def download_content(url: str, path: Path): async def process(): + global anchor + if ( + datetime.datetime.now() - anchor + ).days >= 1 and await credential.check_refresh(): + try: + credential.refresh() + anchor += datetime.timedelta(days=1) + logger.info("Credential refreshed.") + except Exception: + logger.exception("Failed to refresh credential.") + return favorite_ids, tasks = [], [] - for favorite_id in settings.favorite_ids: if favorite_id not in settings.path_mapper: logger.warning(f"Favorite {favorite_id} not in path mapper, ignored.")