mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-04-14 02:20:53 +08:00
fix: tg notification
This commit is contained in:
@@ -55,6 +55,9 @@ class RequestContent(RequestURL):
|
||||
def post_data(self, _url, data: dict) -> dict:
|
||||
return self.post_url(_url, data)
|
||||
|
||||
def post_form(self, _url, data: dict, files: dict) -> dict:
|
||||
return self.post_form(_url, data, files)
|
||||
|
||||
def get_html(self, _url):
|
||||
return self.get_url(_url).text
|
||||
|
||||
|
||||
@@ -72,10 +72,10 @@ class RequestURL:
|
||||
logger.debug(f"[Network] Cannot connect to {url}.")
|
||||
return False
|
||||
|
||||
def post_form(self, url: str, data: dict):
|
||||
def post_form(self, url: str, data: dict, files):
|
||||
try:
|
||||
req = self.session.post(
|
||||
url=url, headers=self.header, data=data, timeout=5
|
||||
url=url, headers=self.header, data=data, files=files, timeout=5
|
||||
)
|
||||
req.raise_for_status()
|
||||
return req
|
||||
|
||||
@@ -2,6 +2,7 @@ import logging
|
||||
|
||||
from module.models import Notification
|
||||
from module.network import RequestContent
|
||||
from module.utils import load_image
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -24,9 +25,14 @@ class TelegramNotification(RequestContent):
|
||||
data = {
|
||||
"chat_id": self.chat_id,
|
||||
"caption": text,
|
||||
"photo": notify.poster_path,
|
||||
"disable_notification": True,
|
||||
}
|
||||
resp = self.post_data(self.notification_url, data)
|
||||
photo = load_image(notify.poster_path)
|
||||
if photo:
|
||||
resp = self.post_form(
|
||||
self.notification_url, data, files={"photo": photo}
|
||||
)
|
||||
else:
|
||||
resp = self.post_data(self.notification_url, data)
|
||||
logger.debug(f"Telegram notification: {resp.status_code}")
|
||||
return resp.status_code == 200
|
||||
|
||||
@@ -10,5 +10,5 @@ def save_image(img, suffix):
|
||||
|
||||
|
||||
def load_image(img_path):
|
||||
with open(f"data/images/{img_path}", "rb") as f:
|
||||
with open(f"data/{img_path}", "rb") as f:
|
||||
return f.read()
|
||||
|
||||
Reference in New Issue
Block a user