mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-04-09 21:49:57 +08:00
Fix check error, close #266
This commit is contained in:
@@ -4,7 +4,7 @@ from fastapi.security import OAuth2PasswordRequestForm
|
||||
from module.database.user import AuthDB
|
||||
from module.security.jwt import decode_token, oauth2_scheme
|
||||
|
||||
from .api import router
|
||||
from .log import router
|
||||
|
||||
|
||||
async def get_current_user(token: str = Depends(oauth2_scheme)):
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import sqlite3
|
||||
|
||||
from .api import router
|
||||
from .log import router
|
||||
|
||||
from module.models import BangumiData
|
||||
from module.database import BangumiDatabase
|
||||
|
||||
@@ -1,15 +1,10 @@
|
||||
import logging
|
||||
import os
|
||||
from fastapi import Response
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi.responses import Response
|
||||
from .program import router
|
||||
|
||||
from module.conf import LOG_PATH
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
router = FastAPI()
|
||||
|
||||
|
||||
@router.get("/api/v1/log", tags=["log"])
|
||||
async def get_log():
|
||||
@@ -1,11 +1,12 @@
|
||||
import os
|
||||
import signal
|
||||
import logging
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
from contextlib import asynccontextmanager
|
||||
from fastapi.exceptions import HTTPException
|
||||
|
||||
from .download import router
|
||||
|
||||
from fastapi import FastAPI
|
||||
|
||||
from module.core import Program, check_status, check_rss, check_downloader
|
||||
|
||||
@@ -13,9 +14,15 @@ logger = logging.getLogger(__name__)
|
||||
program = Program()
|
||||
|
||||
|
||||
@router.on_event("startup")
|
||||
async def on_startup():
|
||||
asyncio.create_task(program.startup())
|
||||
@asynccontextmanager
|
||||
async def lifespan(router: FastAPI):
|
||||
logger.info("Starting program...")
|
||||
program.startup()
|
||||
yield
|
||||
program.stop()
|
||||
|
||||
|
||||
router = FastAPI(lifespan=lifespan)
|
||||
|
||||
|
||||
@router.on_event("shutdown")
|
||||
|
||||
@@ -4,7 +4,7 @@ import logging
|
||||
from fastapi.responses import Response
|
||||
from fastapi.exceptions import HTTPException
|
||||
|
||||
from .program import router
|
||||
from .download import router
|
||||
|
||||
from module.conf import settings
|
||||
from module.network import RequestContent
|
||||
|
||||
@@ -36,11 +36,13 @@ class Checker:
|
||||
def check_torrents() -> bool:
|
||||
with RequestContent() as req:
|
||||
try:
|
||||
torrents = req.get_torrents(settings.rss_link)
|
||||
torrents = req.get_torrents(settings.rss_link, retry=2)
|
||||
if torrents:
|
||||
return True
|
||||
except AttributeError:
|
||||
pass
|
||||
link = f"https://mikanani.me/RSS/MyBangumi?token={settings.rss_parser.token}"
|
||||
if req.get_torrents(link):
|
||||
return True
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -19,7 +19,7 @@ class Program(RenameThread, RSSThread):
|
||||
logger.info("GitHub: https://github.com/EstrellaXD/Auto_Bangumi/")
|
||||
logger.info("Starting AutoBangumi...")
|
||||
|
||||
async def startup(self):
|
||||
def startup(self):
|
||||
self.__start_info()
|
||||
self.start()
|
||||
|
||||
|
||||
@@ -35,9 +35,10 @@ class RequestContent(RequestURL):
|
||||
def get_torrents(
|
||||
self,
|
||||
_url: str,
|
||||
_filter: str = "|".join(settings.rss_parser.filter)
|
||||
_filter: str = "|".join(settings.rss_parser.filter),
|
||||
retry: int = 3
|
||||
) -> [TorrentInfo]:
|
||||
soup = self.get_xml(_url)
|
||||
soup = self.get_xml(_url, retry)
|
||||
torrent_titles = []
|
||||
torrent_urls = []
|
||||
torrent_homepage = []
|
||||
@@ -64,8 +65,8 @@ class RequestContent(RequestURL):
|
||||
return poster_path, official_title
|
||||
return "", ""
|
||||
|
||||
def get_xml(self, _url) -> xml.etree.ElementTree.Element:
|
||||
return xml.etree.ElementTree.fromstring(self.get_url(_url).text)
|
||||
def get_xml(self, _url, retry: int = 3) -> xml.etree.ElementTree.Element:
|
||||
return xml.etree.ElementTree.fromstring(self.get_url(_url, retry).text)
|
||||
|
||||
# API JSON
|
||||
def get_json(self, _url) -> dict:
|
||||
|
||||
@@ -14,9 +14,9 @@ class RequestURL:
|
||||
def __init__(self):
|
||||
self.header = {"user-agent": "Mozilla/5.0", "Accept": "application/xml"}
|
||||
|
||||
def get_url(self, url):
|
||||
def get_url(self, url, retry=3):
|
||||
try_time = 0
|
||||
while try_time < 3:
|
||||
while try_time < retry:
|
||||
try:
|
||||
req = self.session.get(url=url, headers=self.header, timeout=5)
|
||||
req.raise_for_status()
|
||||
@@ -33,9 +33,9 @@ class RequestURL:
|
||||
logger.debug(e)
|
||||
break
|
||||
|
||||
def post_url(self, url: str, data: dict):
|
||||
def post_url(self, url: str, data: dict, retry=3):
|
||||
try_time = 0
|
||||
while try_time < 3:
|
||||
while try_time < retry:
|
||||
try:
|
||||
req = self.session.post(url=url, headers=self.header, data=data, timeout=5)
|
||||
req.raise_for_status()
|
||||
|
||||
Reference in New Issue
Block a user