From 14a3bb8fc272c0a6f168db4cd97c920e9350823d Mon Sep 17 00:00:00 2001 From: thsrite Date: Mon, 11 Mar 2024 15:56:19 +0800 Subject: [PATCH] =?UTF-8?q?add=20db=E8=AE=A2=E9=98=85=E3=80=81=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E5=8E=86=E5=8F=B2=E6=A0=B9=E6=8D=AE=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E5=92=8C=E6=97=B6=E9=97=B4=E6=9F=A5=E8=AF=A2=E5=88=97=E8=A1=A8?= =?UTF-8?q?=EF=BC=88=E6=8F=92=E4=BB=B6=E6=96=B9=E6=B3=95=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/db/downloadhistory_oper.py | 8 ++++++++ app/db/models/downloadhistory.py | 12 ++++++++++++ app/db/models/subscribe.py | 12 ++++++++++++ app/db/subscribe_oper.py | 6 ++++++ 4 files changed, 38 insertions(+) diff --git a/app/db/downloadhistory_oper.py b/app/db/downloadhistory_oper.py index 23020625..8770b28e 100644 --- a/app/db/downloadhistory_oper.py +++ b/app/db/downloadhistory_oper.py @@ -131,3 +131,11 @@ class DownloadHistoryOper(DbOper): type=type, tmdbid=tmdbid, seasons=seasons) + + def list_by_type(self, mtype: str, days: int = 7) -> List[DownloadHistory]: + """ + 获取指定类型的下载历史 + """ + return DownloadHistory.list_by_type(db=self._db, + mtype=mtype, + days=days) diff --git a/app/db/models/downloadhistory.py b/app/db/models/downloadhistory.py index 1e796877..1fd5c167 100644 --- a/app/db/models/downloadhistory.py +++ b/app/db/models/downloadhistory.py @@ -1,3 +1,5 @@ +import time + from sqlalchemy import Column, Integer, String, Sequence from sqlalchemy.orm import Session @@ -140,6 +142,16 @@ class DownloadHistory(Base): DownloadHistory.tmdbid == tmdbid).order_by( DownloadHistory.id.desc()).all() + @staticmethod + @db_query + def list_by_type(db: Session, mtype: str, days: int): + result = db.query(DownloadHistory) \ + .filter(DownloadHistory.type == mtype, + DownloadHistory.date >= time.strftime("%Y-%m-%d %H:%M:%S", + time.localtime(time.time() - 86400 * int(days))) + ).all() + return list(result) + class DownloadFiles(Base): """ diff --git a/app/db/models/subscribe.py b/app/db/models/subscribe.py index 53d7a0b3..080a13b5 100644 --- a/app/db/models/subscribe.py +++ b/app/db/models/subscribe.py @@ -1,3 +1,5 @@ +import time + from sqlalchemy import Column, Integer, String, Sequence from sqlalchemy.orm import Session @@ -126,3 +128,13 @@ class Subscribe(Base): if subscribe: subscribe.delete(db, subscribe.id) return True + + @staticmethod + @db_query + def list_by_type(db: Session, mtype: str, days: int): + result = db.query(Subscribe) \ + .filter(Subscribe.type == mtype, + Subscribe.date >= time.strftime("%Y-%m-%d %H:%M:%S", + time.localtime(time.time() - 86400 * int(days))) + ).all() + return list(result) diff --git a/app/db/subscribe_oper.py b/app/db/subscribe_oper.py index 7b4b8ef7..c10d43a5 100644 --- a/app/db/subscribe_oper.py +++ b/app/db/subscribe_oper.py @@ -83,3 +83,9 @@ class SubscribeOper(DbOper): subscribe = self.get(sid) subscribe.update(self._db, payload) return subscribe + + def list_by_type(self, mtype: str, days: int = 7) -> Subscribe: + """ + 获取指定类型的订阅 + """ + return Subscribe.list_by_type(self._db, mtype=mtype, days=days)