|
|
@@ -4,9 +4,12 @@ Bluesky のニジカがいろいろする. |
|
|
|
""" |
|
|
|
|
|
|
|
import io |
|
|
|
import random |
|
|
|
import sys |
|
|
|
import time |
|
|
|
from datetime import datetime, timedelta |
|
|
|
from datetime import date, datetime |
|
|
|
from datetime import time as dt_time |
|
|
|
from datetime import timedelta |
|
|
|
from typing import cast |
|
|
|
|
|
|
|
import requests |
|
|
@@ -67,6 +70,12 @@ def main ( |
|
|
|
|
|
|
|
client.login (account.USER_ID, account.PASSWORD) |
|
|
|
|
|
|
|
kiriban_list: list[tuple[int, nico.VideoInfo]] = nico.get_kiriban_list () |
|
|
|
got_kiriban_at: date = datetime.now ().date () - timedelta (days = datetime.now ().hour < 15) |
|
|
|
kiriban_interval: timedelta = ((get_kiriban_dt_to_update () - datetime.now ()) |
|
|
|
/ len (kiriban_list)) |
|
|
|
next_kiriban_at = datetime.now () |
|
|
|
|
|
|
|
last_posted_at = datetime.now () - timedelta (hours = 6) |
|
|
|
has_got_snack_time = False |
|
|
|
has_taken_hot_spring = False |
|
|
@@ -99,6 +108,27 @@ def main ( |
|
|
|
parent = records[0]['strong_ref'], |
|
|
|
root = records[-1]['strong_ref'])) |
|
|
|
|
|
|
|
if kiriban_list and datetime.now () >= next_kiriban_at: |
|
|
|
(views_count, video_code) = ( |
|
|
|
kiriban_list.pop (random.randint (0, len (kiriban_list) - 1))) |
|
|
|
embed_external = models.AppBskyEmbedExternal.Main ( |
|
|
|
external = models.AppBskyEmbedExternal.External ( |
|
|
|
title = title, |
|
|
|
description = description, |
|
|
|
thumb = thumb, |
|
|
|
uri = uri)) |
|
|
|
client.post (Talk.main (f""" |
|
|
|
ニコニコの『{ datum['title'] }』という動画が{ views_count }再生を突破しました。 |
|
|
|
つけられたタグは「{ '」、「'.join (datum['tags']) }」です。 |
|
|
|
概要には次のように書かれています: |
|
|
|
```html |
|
|
|
{ datum['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] |
|
|
@@ -135,29 +165,37 @@ def main ( |
|
|
|
if now.hour == 14 and has_got_snack_time: |
|
|
|
has_got_snack_time = False |
|
|
|
|
|
|
|
if now.hour == 15 and 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 == 15: |
|
|
|
if got_kiriban_at < datetime.now ().date (): |
|
|
|
kiriban_list = nico.get_kiriban_list () |
|
|
|
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 |
|
|
@@ -192,7 +230,6 @@ def main ( |
|
|
|
time.sleep (60) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_embed_info ( |
|
|
|
url: str |
|
|
|
) -> tuple[str, str, str]: |
|
|
@@ -231,5 +268,15 @@ def get_embed_info ( |
|
|
|
return (title, description, thumbnail) |
|
|
|
|
|
|
|
|
|
|
|
def get_kiriban_dt_to_update ( |
|
|
|
) -> datetime: |
|
|
|
now = datetime.now () |
|
|
|
today = now.date () |
|
|
|
dt = datetime.combine (today, dt_time (15, 0)) |
|
|
|
if dt <= now: |
|
|
|
dt += timedelta (days = 1) |
|
|
|
return dt |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
main (*sys.argv[1:]) |