| @@ -6,6 +6,7 @@ import sys | |||||
| from atproto import Client, models | from atproto import Client, models | ||||
| from bs4 import BeautifulSoup | from bs4 import BeautifulSoup | ||||
| from requests.exceptions import Timeout | |||||
| import requests | import requests | ||||
| from ai.talk import Talk | from ai.talk import Talk | ||||
| @@ -95,8 +96,13 @@ def main ( | |||||
| uri = f"https://www.nicovideo.jp/watch/{ datum['contentId'] }" | uri = f"https://www.nicovideo.jp/watch/{ datum['contentId'] }" | ||||
| (title, description, thumbnail) = get_embed_info (uri) | (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 ( | embed_external = models.AppBskyEmbedExternal.Main ( | ||||
| external = models.AppBskyEmbedExternal.External ( | external = models.AppBskyEmbedExternal.External ( | ||||
| @@ -155,7 +161,7 @@ def get_nico_deerjika (): | |||||
| '/contents/search') | '/contents/search') | ||||
| now = datetime.now () | now = datetime.now () | ||||
| base = now - timedelta (hours = 1) | |||||
| base = now - timedelta (hours = 4) | |||||
| params = { 'q': '伊地知ニジカ', | params = { 'q': '伊地知ニジカ', | ||||
| 'targets': 'tags', | 'targets': 'tags', | ||||
| @@ -173,7 +179,10 @@ def get_nico_deerjika (): | |||||
| % (now.year, now.month, now.day)), | % (now.year, now.month, now.day)), | ||||
| 'include_lower': True }] }) } | 'include_lower': True }] }) } | ||||
| res = requests.get (URL, params = params).json () | |||||
| try: | |||||
| res = requests.get (URL, params = params, timeout = 60).json () | |||||
| except Timeout: | |||||
| return [] | |||||
| data = [] | data = [] | ||||
| for datum in res['data']: | for datum in res['data']: | ||||
| @@ -192,7 +201,7 @@ def get_embed_info ( | |||||
| try: | try: | ||||
| res = requests.get (url, timeout = 60) | res = requests.get (url, timeout = 60) | ||||
| except Exception: | |||||
| except Timeout: | |||||
| return ('', '', '') | return ('', '', '') | ||||
| if res.status_code != 200: | if res.status_code != 200: | ||||