コミットを比較

26 コミット

作成者 SHA1 メッセージ 日付
みてるぞ 99a5dca5a3 リプライが送信されないバグ修正(#17) (#18)
#17

Co-authored-by: miteruzo <miteruzo@naver.com>
Reviewed-on: #18
2025-12-03 22:48:57 +09:00
みてるぞ a6af306204 字数制限 2025-11-30 04:12:35 +09:00
みてるぞ 9f36cfea28 細部 2025-10-26 18:29:52 +09:00
みてるぞ a103093e9c Merge pull request '統合 AI への移行' (#16) from ai-migration into main
Reviewed-on: #16
2025-10-22 21:50:01 +09:00
みてるぞ 7ff729b256 #11 2025-10-21 22:27:37 +09:00
みてるぞ 3e8c2c5fe0 #11 2025-10-21 21:23:03 +09:00
みてるぞ 6eb191a7f4 #11 完了? 2025-10-19 17:03:51 +09:00
みてるぞ 82fabebe2f コミット忘れ 2025-10-19 15:56:55 +09:00
みてるぞ 47dc881537 #11 2025-08-17 05:37:36 +09:00
みてるぞ 658b15ac52 nicolib 2025-01-10 10:12:02 +00:00
みてるぞ 6d4e826439 None の場合について考慮 2025-01-03 17:40:10 +09:00
みてるぞ e6f90611fa リレーションのミス修正 2024-12-30 17:02:46 +09:00
みてるぞ 4f2056b347 botiboti 2024-12-29 20:31:48 +09:00
みてるぞ 64279b2eca キリ番祝ひ 2024-12-29 16:49:45 +09:00
みてるぞ 4bd15d0cc9 細部の修正 2024-12-11 00:22:28 +09:00
みてるぞ 26867f5269 #1 さすがに失礼すぎるコメント多めなのでポジティブな感想多めに修正 2024-11-14 23:18:31 +09:00
みてるぞ 0dd27b4ec7 #1 当日にて,より小さいキリ番は祝はなぃやぅに 2024-11-11 12:31:19 +09:00
みてるぞ fb920a1f2c #8 すでにいいねしてゐるポストは対象外に 2024-11-10 03:26:30 +09:00
みてるぞ 5041b91485 #8 いいねから自分を除外 2024-11-09 06:24:51 +09:00
みてるぞ 06b9d015d0 #8 型安全性不明 2024-11-09 06:02:57 +09:00
みてるぞ fad7ffe969 なかなか辛辣だったのでプロンプト修正 2024-11-08 01:48:13 +09:00
みてるぞ d6654c41ba #1 100 刻みはさすがに刻みすぎた 2024-11-07 12:38:30 +09:00
みてるぞ a4e0a5fcd8 #1 2024-11-07 03:15:52 +09:00
みてるぞ f3c8f5fa27 #1 ニジカがあまりにも塩対応だったので要求ã追加 2024-11-07 03:09:48 +09:00
みてるぞ f6ab471e04 #1 base_date が意味をなしてゐなかったのを修正 2024-11-07 03:03:14 +09:00
みてるぞ ad9f5256e5 #1 ほぼ完了 2024-11-07 02:54:22 +09:00
12個のファイルの変更283行の追加476行の削除
+2
ファイルの表示
@@ -1,3 +1,5 @@
/__pycache__ /__pycache__
/account.py /account.py
/connection.py /connection.py
/db
/eloquent.pyi
+6 -6
ファイルの表示
@@ -1,6 +1,6 @@
[submodule "nizika_nico"] [submodule "nizika_ai"]
path = nizika_nico path = nizika_ai
url = https://git.miteruzo.com/miteruzo/nizika_nico url = https://git.miteruzo.com/miteruzo/nizika_ai.git
[submodule "ai"] [submodule "nicolib"]
path = ai path = nicolib
url = https://git.miteruzo.com/miteruzo/nizika_broadcast url = https://git.miteruzo.com/miteruzo/nicolib.git
-1
サブモジュール ai299a3acdff から削除されました
-49
ファイルの表示
@@ -1,49 +0,0 @@
from datetime import datetime
from atproto import models
class Client:
app: AppNamespace
def get_current_time_iso (self) -> datetime: ...
def get_post_thread (
self,
uri: str,
parent_height: int | None = None
) -> Response: ...
def follow (self, did: str) -> None: ...
class AppNamespace:
bsky: AppBskyNamespace
class AppBskyNamespace:
notification: AppBskyNotificationNamespace
class AppBskyNotificationNamespace:
def list_notifications (self) -> Response: ...
def update_seen (self, seen: dict[str, datetime]) -> None: ...
class Response:
notifications: list[Notification]
thread: (ThreadViewPost
| models.AppBskyFeedDefs.NotFoundPost
| models.AppBskyFeedDefs.BlockedPost)
class Notification:
is_read: bool
reason: str
uri: str
author: ProfileView
class ProfileView:
did: str
ファイルの表示
-1
ファイルの表示
@@ -1 +0,0 @@
nizika_nico/db
-1
ファイルの表示
@@ -1 +0,0 @@
db/eloquent.pyi
+273 -259
ファイルの表示
@@ -1,291 +1,305 @@
""" from __future__ import annotations
Bluesky のニジカがいろいろする.
(近々機能ごとにファイル分けて systemd でイベント管理する予定)
"""
import io import asyncio
import random import os
import sys
import time import time
from datetime import date, datetime from datetime import datetime
from datetime import time as dt_time from io import BytesIO
from datetime import timedelta from typing import Any, TypedDict
from typing import cast
import atproto # type: ignore
import requests import requests
from atproto import Client, models from atproto import Client # type: ignore
from bs4 import BeautifulSoup from atproto_client.models import AppBskyEmbedExternal, AppBskyEmbedImages, ComAtprotoRepoStrongRef # type: ignore
from atproto_client.models.app.bsky.feed.get_timeline import Response # type: ignore
from atproto_client.models.app.bsky.feed.post import ReplyRef # type: ignore
from requests.exceptions import Timeout from requests.exceptions import Timeout
import account import account
import nico import nicolib
from ai.talk import Talk from nizika_ai.consts import Character, GPTModel, Platform, QueryType
from nizika_ai.models import Answer, AnsweredFlag, Query, User
TARGET_WORDS = ['deerjika', 'ニジカ', 'ぼっち', '虹夏', '郁代', 'バーカ',
'kfif', 'kita-flatten-ikuyo-flatten', 'ラマ田', 'ゴートう',
'ぼざクリ', 'オオミソカ', '伊地知', '喜多ちゃん',
'喜タイ', '洗澡鹿', 'シーザオ', '今日は本当に',
'ダイソーで', '変なチンチン', 'daisoで', 'だね~(笑)',
'おやつタイム', 'わさしが', 'わさび県', 'たぬマ', 'にくまる',
'ルイズマリー', '', 'ニジゴ', 'ゴニジ', 'ニジニジ',
'新年だよね', 'うんこじゃん', 'ほくほくのジャガイモ']
time.sleep (60)
client = Client (base_url = 'https://bsky.social')
client.login (account.USER_ID, account.PASSWORD)
async def main (
) -> None:
"""
メーン処理
"""
await asyncio.gather (like_posts (),
check_mentions (),
answer ())
async def like_posts (
) -> None:
while True:
try:
for post in fetch_target_posts ():
client.like (**post)
except Exception as e:
print (f"[like_posts] { type (e).__name__ }: { e }")
await asyncio.sleep (60)
async def check_mentions (
) -> None:
while True:
try:
for uri in check_notifications ():
records = fetch_thread_contents (uri, 20)
if records:
record = records[0]
image_url: str | None = None
if record['embed'] and hasattr (record['embed'], 'images'):
image_url = ('https://cdn.bsky.app/img/feed_fullsize/plain'
f"/{ record['did'] }"
f"/{ record['embed'].images[0].image.ref.link }")
user = _fetch_user (record['did'], record['name'])
_add_query (user, record['text'], image_url, {
'uri': record['strong_ref']['uri'],
'cid': record['strong_ref']['cid'] })
except Exception as e:
print (f"[check_mentions] { type (e).__name__ }: { e }")
await asyncio.sleep (60)
async def answer (
) -> None:
while True:
answered_flags = (
AnsweredFlag
.where ('platform', Platform.BLUESKY.value)
.where ('answered', False)
.get ())
for answered_flag in answered_flags:
td: dict[str, Any]
answer = answered_flag.answer
answered_flag.answered = True
answered_flag.save ()
match QueryType (answer.query_rel.query_type):
case QueryType.BLUESKY_COMMENT:
td = answer.query_rel.transfer_data or { }
uri: str | None = td.get ('uri')
cid: str | None = td.get ('cid')
if (not uri) or (not cid):
continue
strong_ref = ComAtprotoRepoStrongRef.Main (uri = uri, cid = cid)
reply_ref = ReplyRef (root = strong_ref, parent = strong_ref)
try:
client.post (answer.content[:250], reply_to = reply_ref)
except Exception as e:
print (f"[answer/reply] { type (e).__name__ }: { e }")
continue
case QueryType.KIRIBAN | QueryType.NICO_REPORT:
td = answer.query_rel.transfer_data or { }
video_code: str | None = td.get ('video_code')
if not video_code:
continue
uri = f"https://www.nicovideo.jp/watch/{ video_code }"
(title, description, thumbnail) = nicolib.fetch_embed_info (uri)
try:
resp = requests.get (thumbnail, timeout = 60)
resp.raise_for_status ()
upload = client.com.atproto.repo.upload_blob (BytesIO (resp.content))
thumb = upload.blob
except Timeout:
thumb = None
except Exception as e:
print (f"[answer/nico-thumb] { type (e).__name__ }: { e }")
thumb = None
external = AppBskyEmbedExternal.External (
title = title,
description = description,
thumb = thumb,
uri = uri)
embed_external = AppBskyEmbedExternal.Main (external = external)
try:
client.post (answer.content[:250], embed = embed_external)
except Exception as e:
print (f"[answer/nico-post] { type (e).__name__ }: { e }")
continue
case QueryType.SNACK_TIME:
try:
with open ('./assets/snack-time.jpg', 'rb') as f:
image = AppBskyEmbedImages.Image (
alt = (
'左に喜多ちゃん、右に人面鹿のニジカが'
'V字に並んでいる。'
'喜多ちゃんは右手でピースサインをして'
'片目をウインクしている。'
'ニジカは両手を広げ、'
'右手にスプーンを持って'
'ポーズを取っている。'
'背景には'
'赤と黄色の放射線状の模様が広がり、'
'下部に「おやつタイムだ!!!!」という'
'日本語のテキストが表示されている。'),
image = client.com.atproto.repo.upload_blob (f).blob)
client.post (answer.content[:250],
embed = AppBskyEmbedImages.Main (images = [image]))
except Exception:
pass
case QueryType.HOT_SPRING:
try:
with open ('./assets/hot-spring.jpg', 'rb') as f:
image = AppBskyEmbedImages.Image (
alt = ('左に喜多ちゃん、右にわさび県産滋賀県が'
'V字に並んでいる。'
'喜多ちゃんは右手でピースサインをして'
'片目をウインクしている。'
'わさび県産滋賀県はただ茫然と'
'立ち尽くしている。'
'背景には'
'血と空の色をした放射線状の模様が広がり、'
'下部に「温泉に入ろう!!!」という'
'日本語のテキストが表示されている。'),
image = client.com.atproto.repo.upload_blob (f).blob)
client.post (answer.content[:250],
embed = AppBskyEmbedImages.Main (images = [image]))
except Exception:
pass
await asyncio.sleep (10)
def check_notifications ( def check_notifications (
client: Client, ) -> list[str]:
) -> list: uris: list[str] = []
(uris, last_seen_at) = ([], client.get_current_time_iso ()) last_seen_at = client.get_current_time_iso ()
for notification in (client.app.bsky.notification.list_notifications () notifications = client.app.bsky.notification.list_notifications ()
.notifications): for notification in notifications.notifications:
if not notification.is_read: if not notification.is_read:
if notification.reason in ['mention', 'reply', 'quote']: match notification.reason:
uris += [notification.uri] case 'mention' | 'reply' | 'quote':
elif notification.reason == 'follow': uris.append (notification.uri)
client.follow (notification.author.did) case 'follow':
client.follow (notification.author.did)
client.app.bsky.notification.update_seen ({ 'seen_at': last_seen_at }) client.app.bsky.notification.update_seen ({ 'seen_at': last_seen_at })
return uris return uris
def get_thread_contents ( def fetch_thread_contents (
client: Client,
uri: str, uri: str,
parent_height: int, parent_height: int,
) -> list: ) -> list[Record]:
response = (client.get_post_thread (uri = uri, post_thread = client.get_post_thread (uri = uri, parent_height = parent_height)
parent_height = parent_height) if not post_thread:
.thread) return []
records = []
while response is not None: res = post_thread.thread
records += [{ 'strong_ref': models.create_strong_ref (response.post),
'did': response.post.author.did, records: list[Record] = []
'handle': response.post.author.handle, while res:
'name': response.post.author.display_name, if hasattr (res, 'post'):
'datetime': response.post.record.created_at, records.append ({ 'strong_ref': { 'uri': res.post.uri,
'text': response.post.record.text, 'cid': res.post.cid },
'embed': response.post.record.embed }] 'did': res.post.author.did,
response = response.parent 'handle': res.post.author.handle,
'name': (res.post.author.display_name
or res.post.author.handle),
'datetime': res.post.record.created_at,
'text': getattr (res.post.record, 'text', None) or '',
'embed': getattr (res.post.record, 'embed', None) })
res = res.parent
else:
break
return records return records
def main ( def fetch_target_posts (
) -> list[LikeParams]:
posts: list[LikeParams] = []
timeline: Response = client.get_timeline ()
for feed in timeline.feed:
me = getattr (client, 'me', None)
my_did = me.did if me else ''
if (feed.post.author.did != my_did
and (feed.post.viewer.like is None)
and any (target_word in (feed.post.record.text or '').casefold ()
for target_word in TARGET_WORDS)):
posts.append (LikeParams ({ 'uri': feed.post.uri, 'cid': feed.post.cid }))
return posts
def _add_query (
user: User,
content: str,
image_url: str | None = None,
transfer_data: dict[str, Any] | None = None,
) -> None: ) -> None:
time.sleep (60) query = Query ()
query.user_id = user.id
client = Client (base_url = 'https://bsky.social') query.target_character = Character.DEERJIKA.value
query.content = content
client.login (account.USER_ID, account.PASSWORD) query.image_url = image_url or None
query.query_type = QueryType.BLUESKY_COMMENT.value
got_kiriban_at: date = datetime.now ().date () - timedelta (days = datetime.now ().hour < 15) query.model = GPTModel.GPT3_TURBO.value
kiriban_list: list[tuple[int, nico.VideoInfo]] = nico.get_kiriban_list (got_kiriban_at) query.sent_at = datetime.now ()
kiriban_interval: timedelta = ((get_kiriban_dt_to_update () - datetime.now ()) query.answered = False
/ len (kiriban_list)) query.transfer_data = transfer_data
next_kiriban_at = datetime.now () query.save ()
# TODO: 履歴情報の追加
last_posted_at = datetime.now () - timedelta (hours = 6)
has_got_snack_time = False
has_taken_hot_spring = False
watched_videos = []
while True:
now = datetime.now ()
for uri in check_notifications (client):
records = get_thread_contents (client, uri, 20)
if len (records) > 0:
answer = Talk.main ((records[0]['text']
if (records[0]['embed'] is None
or not hasattr (records[0]['embed'],
'images'))
else [
{ 'type': 'text', 'text': records[0]['text'] },
{ 'type': 'image_url', 'image_url': {
'url': f"https://cdn.bsky.app/img/feed_fullsize/plain/{ records[0]['did'] }/{ records[0]['embed'].images[0].image.ref.link }" } }]),
records[0]['name'],
[*map (lambda record: {
'role': ('assistant'
if (record['handle']
== account.USER_ID)
else 'user'),
'content':
record['text']},
reversed (records[1:]))])
client.post (answer,
reply_to = models.AppBskyFeedPost.ReplyRef (
parent = records[0]['strong_ref'],
root = records[-1]['strong_ref']))
if kiriban_list and datetime.now () >= next_kiriban_at:
(views_count, video_info) = (
kiriban_list.pop (random.randint (0, len (kiriban_list) - 1)))
uri = f"https://www.nicovideo.jp/watch/{ video_info['contentId'] }"
(title, description, thumbnail) = get_embed_info (uri)
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 (
title = title,
description = description,
thumb = thumb,
uri = uri))
client.post (Talk.main (f"""
ニコニコの『{ video_info['title'] }』という動画が{ views_count }再生を突破しました。
つけられたタグは「{ '」、「'.join (video_info['tags']) }」です。
概要には次のように書かれています:
```html
{ video_info['description'] }
```
このことについて、ニジカちゃんからのお祝いメッセージを下さい。"""),
embed = embed_external)
next_kiriban_at += kiriban_interval
last_posted_at = now
latest_deerjika = nico.get_latest_deerjika ()
if latest_deerjika is not None:
for datum in [e for e in [latest_deerjika]
if e['contentId'] not in watched_videos]:
watched_videos += [datum['contentId']]
uri = f"https://www.nicovideo.jp/watch/{ datum['contentId'] }"
(title, description, thumbnail) = get_embed_info (uri)
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 (
title = title,
description = description,
thumb = thumb,
uri = uri))
client.post (Talk.main (f"""
ニコニコに『{ datum['title'] }』という動画がアップされました。
つけられたタグは「{ '」、「'.join (datum['tags']) }」です。
概要には次のように書かれています:
```html
{ datum['description'] }
```
このことについて、みんなに告知するとともに、ニジカちゃんの感想を教えてください。 """),
embed = embed_external)
last_posted_at = now
if now.hour == 14 and has_got_snack_time:
has_got_snack_time = False
if now.hour == 15:
if got_kiriban_at < datetime.now ().date ():
kiriban_list = nico.get_kiriban_list (datetime.now ().date ())
got_kiriban_at = datetime.now ().date ()
kiriban_interval = ((get_kiriban_dt_to_update () - datetime.now ())
/ len (kiriban_list))
next_kiriban_at = datetime.now ()
if not has_got_snack_time:
try:
with open ('./assets/snack-time.jpg', 'rb') as f:
image = models.AppBskyEmbedImages.Image (
alt = ('左に喜多ちゃん、右に人面鹿のニジカが'
'V字に並んでいる。'
'喜多ちゃんは右手でピースサインをして'
'片目をウインクしている。'
'ニジカは両手を広げ、'
'右手にスプーンを持って'
'ポーズを取っている。'
'背景には'
'赤と黄色の放射線状の模様が広がり、'
'下部に「おやつタイムだ!!!!」という'
'日本語のテキストが表示されている。'),
image = client.com.atproto.repo.upload_blob (f).blob)
client.post (Talk.main ('おやつタイムだ!!!!'),
embed = models.app.bsky.embed.images.Main (
images = [image]))
last_posted_at = now
except Exception:
pass
has_got_snack_time = True
if now.hour == 20 and has_taken_hot_spring:
has_taken_hot_spring = False
if now.hour == 21 and not has_taken_hot_spring:
try:
with open ('./assets/hot-spring.jpg', 'rb') as f:
image = models.AppBskyEmbedImages.Image (
alt = ('左に喜多ちゃん、右にわさび県産滋賀県が'
'V字に並んでいる。'
'喜多ちゃんは右手でピースサインをして'
'片目をウインクしている。'
'わさび県産滋賀県はただ茫然と'
'立ち尽くしている。'
'背景には'
'血と空の色をした放射線状の模様が広がり、'
'下部に「温泉に入ろう!!!」という'
'日本語のテキストが表示されている。'),
image = client.com.atproto.repo.upload_blob (f).blob)
client.post (Talk.main ('温泉に入ろう!!!'),
embed = models.app.bsky.embed.images.Main (
images = [image]))
last_posted_at = now
except Exception:
pass
has_taken_hot_spring = True
if now - last_posted_at >= timedelta (hours = 6):
client.post (Talk.main ('今どうしてる?'))
last_posted_at = now
time.sleep (60)
def get_embed_info ( def _fetch_user (
url: str did: str,
) -> tuple[str, str, str]: name: str,
title: str = '' ) -> User:
description: str = '' user = User.where ('platform', Platform.BLUESKY.value).where ('code', did).first ()
thumbnail: str = '' if user is None:
user = User ()
try: user.platform = Platform.BLUESKY.value
res = requests.get (url, timeout = 60) user.code = did
except Timeout: user.name = name
return ('', '', '') user.save ()
return user
if res.status_code != 200:
return ('', '', '')
soup = BeautifulSoup (res.text, 'html.parser')
tmp = soup.find ('title')
if tmp is not None:
title = tmp.text
tmp = soup.find ('meta', attrs = { 'name': 'description' })
if tmp is not None and hasattr (tmp, 'get'):
try:
description = cast (str, tmp.get ('content'))
except Exception:
pass
tmp = soup.find ('meta', attrs = { 'name': 'thumbnail' })
if tmp is not None and hasattr (tmp, 'get'):
try:
thumbnail = cast (str, tmp.get ('content'))
except Exception:
pass
return (title, description, thumbnail)
def get_kiriban_dt_to_update ( class LikeParams (TypedDict):
) -> datetime: uri: str
now = datetime.now () cid: str
today = now.date ()
dt = datetime.combine (today, dt_time (15, 0))
if dt <= now: class Record (TypedDict):
dt += timedelta (days = 1) strong_ref: StrongRef
return dt did: str
handle: str
name: str
datetime: str
text: str
embed: object
class StrongRef (TypedDict):
uri: str
cid: str
if __name__ == '__main__': if __name__ == '__main__':
main (*sys.argv[1:]) asyncio.run (main ())
-158
ファイルの表示
@@ -1,158 +0,0 @@
"""
ニコニコのニジカ動画取得モヂュール
"""
from __future__ import annotations
import os
from datetime import date, timedelta
from typing import TypedDict, cast
import requests
from bs4 import BeautifulSoup
from requests.exceptions import Timeout
from eloquent import DatabaseManager, Model
from db.models import Tag, Video, VideoHistory, VideoTag
CONFIG: dict[str, DbConfig] = { 'mysql': { 'driver': 'mysql',
'host': 'localhost',
'database': 'nizika_nico',
'user': os.environ['MYSQL_USER'],
'password': os.environ['MYSQL_PASS'],
'prefix': '' } }
DB = DatabaseManager (CONFIG)
Model.set_connection_resolver (DB)
KIRIBAN_VIEWS_COUNTS: set[int] = { *range (100, 1_000, 100),
*range (1_000, 10_000, 1_000),
*range (10_000, 1_000_001, 10_000),
194, 245, 510, 114_514, 1_940, 2_450, 5_100, 24_500,
51_000, 2_424 }
class VideoInfo (TypedDict):
contentId: str
title: str
tags: list[str]
description: str
def get_latest_deerjika (
) -> VideoInfo | None:
tag = '伊地知ニジカ OR ぼざろクリーチャーシリーズ'
url = f"https://www.nicovideo.jp/tag/{ tag }"
params = { 'sort': 'f',
'order': 'd' }
video_info = { }
bs = get_bs_from_url (url, params)
if bs is None:
return None
try:
video = (bs.find_all ('ul', class_ = 'videoListInner')[1]
.find ('li', class_ = 'item'))
video_info['contentId'] = video['data-video-id']
except Exception:
return None
return get_video_info (video_info['contentId'])
def get_bs_from_url (
url: str,
params: dict = { },
) -> BeautifulSoup | None:
"""
URL から BeautifulSoup インスタンス生成
Parameters
----------
url: str
捜査する URL
params: dict
パラメータ
Return
------
BeautifulSoup | None
BeautifulSoup オブゼクト(失敗したら None)
"""
try:
req = requests.get (url, params = params, timeout = 60)
except Timeout:
return None
if req.status_code != 200:
return None
req.encoding = req.apparent_encoding
return BeautifulSoup (req.text, 'html.parser')
def get_video_info (
video_code: str,
) -> VideoInfo | None:
video_info: dict[str, str | list[str]] = { 'contentId': video_code }
bs = get_bs_from_url (f"https://www.nicovideo.jp/watch/{ video_code }")
if bs is None:
return None
try:
title = bs.find ('title')
if title is None:
return None
video_info['title'] = '-'.join (title.text.split ('-')[:(-1)])[:(-1)]
tags: str = bs.find ('meta', attrs = { 'name': 'keywords' }).get ('content') # type: ignore
video_info['tags'] = tags.split (',')
video_info['description'] = bs.find ('meta', attrs = { 'name': 'description' }).get ('content') # type: ignore
except Exception:
return None
return cast (VideoInfo, video_info)
def get_kiriban_list (
base_date: date,
) -> list[tuple[int, VideoInfo]]:
kiriban_list: list[tuple[int, VideoInfo]] = []
latest_fetched_at = cast (date, VideoHistory.max ('fetched_at'))
previous_fetched_at = cast (date, (VideoHistory
.where ('fetched_at', '<', latest_fetched_at)
.max ('fetched_at')))
for kiriban_views_count in KIRIBAN_VIEWS_COUNTS:
targets = ({ vh.video.code for vh in (VideoHistory
.where ('fetched_at', latest_fetched_at)
.where ('views_count', '>=', kiriban_views_count)
.get ()) }
- { vh.video.code for vh in (VideoHistory
.where ('fetched_at', previous_fetched_at)
.where ('views_count', '>=', kiriban_views_count)
.get ()) })
for code in targets:
video_info = get_video_info (code)
if video_info is not None:
kiriban_list.append ((kiriban_views_count, video_info))
return kiriban_list
class DbConfig (TypedDict):
driver: str
host: str
database: str
user: str
password: str
prefix: str
サブモジュール
+1
サブモジュール nicolib85670982f0 で追加されました
サブモジュール
+1
サブモジュール nizika_ai1f75763038 で追加されました
サブモジュール nizika_nicob2f5f81ca8 から削除されました