|
@@ -1,8 +1,13 @@ |
|
|
|
|
|
""" |
|
|
|
|
|
Bluesky のニジカがいろいろする. |
|
|
|
|
|
(近々機能ごとにファイル分けて systemd でイベント管理する予定) |
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
import io |
|
|
import io |
|
|
import json |
|
|
|
|
|
import time |
|
|
import time |
|
|
import sys |
|
|
import sys |
|
|
from datetime import datetime, timedelta |
|
|
from datetime import datetime, timedelta |
|
|
|
|
|
from typing import cast |
|
|
|
|
|
|
|
|
import requests |
|
|
import requests |
|
|
from atproto import Client, models |
|
|
from atproto import Client, models |
|
@@ -22,7 +27,7 @@ def check_notifications ( |
|
|
for notification in (client.app.bsky.notification.list_notifications () |
|
|
for notification in (client.app.bsky.notification.list_notifications () |
|
|
.notifications): |
|
|
.notifications): |
|
|
if not notification.is_read: |
|
|
if not notification.is_read: |
|
|
if notification.reason in ['mention', 'reply']: |
|
|
|
|
|
|
|
|
if notification.reason in ['mention', 'reply', 'quote']: |
|
|
uris += [notification.uri] |
|
|
uris += [notification.uri] |
|
|
elif notification.reason == 'follow': |
|
|
elif notification.reason == 'follow': |
|
|
client.follow (notification.author.did) |
|
|
client.follow (notification.author.did) |
|
@@ -62,6 +67,7 @@ def main ( |
|
|
|
|
|
|
|
|
last_posted_at = datetime.now () - timedelta (hours = 6) |
|
|
last_posted_at = datetime.now () - timedelta (hours = 6) |
|
|
has_got_snack_time = False |
|
|
has_got_snack_time = False |
|
|
|
|
|
has_taken_hot_spring = False |
|
|
watched_videos = [] |
|
|
watched_videos = [] |
|
|
while True: |
|
|
while True: |
|
|
now = datetime.now () |
|
|
now = datetime.now () |
|
@@ -111,7 +117,7 @@ def main ( |
|
|
external = models.AppBskyEmbedExternal.External ( |
|
|
external = models.AppBskyEmbedExternal.External ( |
|
|
title = title, |
|
|
title = title, |
|
|
description = description, |
|
|
description = description, |
|
|
thumb = upload.blob, |
|
|
|
|
|
|
|
|
thumb = thumb, |
|
|
uri = uri)) |
|
|
uri = uri)) |
|
|
client.post (Talk.main (f""" |
|
|
client.post (Talk.main (f""" |
|
|
ニコニコに『{ datum['title'] }』という動画がアップされました。 |
|
|
ニコニコに『{ datum['title'] }』という動画がアップされました。 |
|
@@ -122,6 +128,7 @@ def main ( |
|
|
``` |
|
|
``` |
|
|
このことについて、みんなに告知するとともに、ニジカちゃんの感想を教えてください。 """), |
|
|
このことについて、みんなに告知するとともに、ニジカちゃんの感想を教えてください。 """), |
|
|
embed = embed_external) |
|
|
embed = embed_external) |
|
|
|
|
|
last_posted_at = now |
|
|
|
|
|
|
|
|
if now.hour == 14 and has_got_snack_time: |
|
|
if now.hour == 14 and has_got_snack_time: |
|
|
has_got_snack_time = False |
|
|
has_got_snack_time = False |
|
@@ -142,16 +149,40 @@ def main ( |
|
|
'下部に「おやつタイムだ!!!!」という' |
|
|
'下部に「おやつタイムだ!!!!」という' |
|
|
'日本語のテキストが表示されている。'), |
|
|
'日本語のテキストが表示されている。'), |
|
|
image = client.com.atproto.repo.upload_blob (f).blob) |
|
|
image = client.com.atproto.repo.upload_blob (f).blob) |
|
|
|
|
|
|
|
|
client.post (Talk.main ('おやつタイムだ!!!!'), |
|
|
client.post (Talk.main ('おやつタイムだ!!!!'), |
|
|
embed = models.app.bsky.embed.images.Main ( |
|
|
embed = models.app.bsky.embed.images.Main ( |
|
|
images = [image])) |
|
|
images = [image])) |
|
|
last_posted_at = now |
|
|
last_posted_at = now |
|
|
except Exception: |
|
|
except Exception: |
|
|
pass |
|
|
pass |
|
|
|
|
|
|
|
|
has_got_snack_time = True |
|
|
has_got_snack_time = True |
|
|
|
|
|
|
|
|
|
|
|
if now.hour == 20 and has_got_snack_time: |
|
|
|
|
|
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): |
|
|
if now - last_posted_at >= timedelta (hours = 6): |
|
|
client.post (Talk.main ('今どうしてる?')) |
|
|
client.post (Talk.main ('今どうしてる?')) |
|
|
last_posted_at = now |
|
|
last_posted_at = now |
|
@@ -161,7 +192,7 @@ def main ( |
|
|
|
|
|
|
|
|
def get_embed_info ( |
|
|
def get_embed_info ( |
|
|
url: str |
|
|
url: str |
|
|
) -> (str, str, str): |
|
|
|
|
|
|
|
|
) -> tuple[str, str, str]: |
|
|
title: str = '' |
|
|
title: str = '' |
|
|
description: str = '' |
|
|
description: str = '' |
|
|
thumbnail: str = '' |
|
|
thumbnail: str = '' |
|
@@ -181,12 +212,18 @@ def get_embed_info ( |
|
|
title = tmp.text |
|
|
title = tmp.text |
|
|
|
|
|
|
|
|
tmp = soup.find ('meta', attrs = { 'name': 'description' }) |
|
|
tmp = soup.find ('meta', attrs = { 'name': 'description' }) |
|
|
if tmp is not None: |
|
|
|
|
|
description = tmp.get ('content') |
|
|
|
|
|
|
|
|
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' }) |
|
|
tmp = soup.find ('meta', attrs = { 'name': 'thumbnail' }) |
|
|
if tmp is not None: |
|
|
|
|
|
thumbnail = tmp.get ('content') |
|
|
|
|
|
|
|
|
if tmp is not None and hasattr (tmp, 'get'): |
|
|
|
|
|
try: |
|
|
|
|
|
thumbnail = cast (str, tmp.get ('content')) |
|
|
|
|
|
except Exception: |
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
return (title, description, thumbnail) |
|
|
return (title, description, thumbnail) |
|
|
|
|
|
|
|
|