From b7433ade9fbe8c13867b37476142f0f872396881 Mon Sep 17 00:00:00 2001 From: miteruzo Date: Mon, 9 Sep 2024 12:28:55 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=8B=E3=82=B3=E3=83=8B=E3=82=B3=E5=8F=96?= =?UTF-8?q?=E5=BE=97=E7=AF=84=E5=9B=B2=E3=81=AE=E5=A4=89=E6=9B=B4=E3=81=A8?= =?UTF-8?q?=E3=83=AA=E3=82=AF=E3=82=A8=E3=82=B9=E3=83=88=E3=81=AE=E3=82=BF?= =?UTF-8?q?=E3=82=A4=E3=83=A0=E3=82=A2=E3=82=A6=E3=83=88=E8=A8=AD=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index d6f8a94..39acb36 100644 --- a/main.py +++ b/main.py @@ -6,6 +6,7 @@ import sys from atproto import Client, models from bs4 import BeautifulSoup +from requests.exceptions import Timeout import requests from ai.talk import Talk @@ -95,8 +96,13 @@ def main ( uri = f"https://www.nicovideo.jp/watch/{ datum['contentId'] }" (title, description, thumbnail) = get_embed_info (uri) - upload = client.com.atproto.repo.upload_blob ( - io.BytesIO (requests.get (thumbnail).content)) + try: + upload = client.com.atproto.repo.upload_blob ( + io.BytesIO (requests.get (thumbnail, + timeout = 60).content)) + thumb = upload.blob + except Timeout: + thumb = None embed_external = models.AppBskyEmbedExternal.Main ( external = models.AppBskyEmbedExternal.External ( @@ -155,7 +161,7 @@ def get_nico_deerjika (): '/contents/search') now = datetime.now () - base = now - timedelta (hours = 1) + base = now - timedelta (hours = 4) params = { 'q': '伊地知ニジカ', 'targets': 'tags', @@ -173,7 +179,10 @@ def get_nico_deerjika (): % (now.year, now.month, now.day)), 'include_lower': True }] }) } - res = requests.get (URL, params = params).json () + try: + res = requests.get (URL, params = params, timeout = 60).json () + except Timeout: + return [] data = [] for datum in res['data']: @@ -192,7 +201,7 @@ def get_embed_info ( try: res = requests.get (url, timeout = 60) - except Exception: + except Timeout: return ('', '', '') if res.status_code != 200: