Browse Source

ニコニコ取得範囲の変更とリクエストのタイムアウト設定

kiriban
みてるぞ 2 months ago
parent
commit
b7433ade9f
1 changed files with 14 additions and 5 deletions
  1. +14
    -5
      main.py

+ 14
- 5
main.py View File

@@ -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:


Loading…
Cancel
Save