feat: init rss polling module

This commit is contained in:
EstrellaXD
2023-06-05 21:53:51 +08:00
parent dbc73ea665
commit ae01637f01
3 changed files with 39 additions and 0 deletions

View File

@@ -3,3 +3,4 @@ from .config import Config
from .torrent import EpisodeFile, SubtitleFile
from .user import UserLogin
from .torrent import TorrentBase
from .rss import RSSTorrents

10
src/module/models/rss.py Normal file
View File

@@ -0,0 +1,10 @@
from pydantic import BaseModel, Field
class RSSTorrents(BaseModel):
name: str = Field(..., alias="item_path")
url: str = Field(..., alias="url")
analyze: bool = Field(..., alias="analyze")
enabled: bool = Field(..., alias="enabled")
torrents: list[str] = Field(..., alias="torrents")

28
src/module/rss/poller.py Normal file
View File

@@ -0,0 +1,28 @@
import re
from module.database import RSSDatabase
from module.network import RequestContent, TorrentInfo
from module.models import BangumiData, RSSTorrents
from module.conf import settings
class RSSPoller(RSSDatabase):
@staticmethod
def polling(rss_link, req: RequestContent) -> list[TorrentInfo]:
return req.get_torrents(rss_link)
@staticmethod
def filter_torrent(data: BangumiData, torrent: TorrentInfo) -> bool:
if data.title_raw in torrent.name:
_filter = "|".join(data.filter)
if not re.search(_filter, torrent.name):
return True
else:
return False
def foo(self):
rss_datas: list[RSSTorrents] = self.get_rss_data()
with RequestContent() as req:
for rss_data in rss_datas:
torrents = self.polling(rss_data.url, req)