Skip to content

Commit ce83326

Browse files
committed
Increase podcast check frequency and add time info
1 parent e42b42e commit ce83326

File tree

3 files changed

+40
-414
lines changed

3 files changed

+40
-414
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ dependencies = [
1515
"pygit2==1.*",
1616
"python-dotenv==1.*",
1717
"sqlalchemy[asyncio]==2.0.*",
18+
"tzdata",
1819
"wavelink==3.*",
1920
]
2021

src/my_discord_bot/cogs/subscription.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33
import os
44
import typing as ty
5+
import zoneinfo
56

67
import discord
78
import googleapiclient.discovery
@@ -32,7 +33,7 @@ def __init__(
3233
)
3334
self.check_subscription.start()
3435

35-
@tasks.loop(hours=1)
36+
@tasks.loop(minutes=15)
3637
async def check_subscription(self) -> None:
3738
"""Check for upcoming live of subscriptions.
3839
@@ -42,14 +43,16 @@ async def check_subscription(self) -> None:
4243
logger.debug("GOOGLE_API_KEY not set, skipping subscription check.")
4344
return
4445

45-
logger.info("Checking for new live streams...")
46+
logger.debug("Checking for new live streams...")
4647

4748
ISO_FORMAT = r"%Y-%m-%dT%H:%M:%SZ"
4849
MESSAGE_TEMPLATE = """{role_tag}
4950
# {title}
51+
## Scheduled Start Time
52+
{scheduled_start_time}
53+
## Description
5054
{description}
51-
52-
**Link:**
55+
## Link
5356
https://www.youtube.com/watch?v={video_id}"""
5457

5558
async with self.sessionmaker() as session:
@@ -138,7 +141,7 @@ async def check_subscription(self) -> None:
138141
# Not a scheduled stream or stream has already started
139142
continue
140143

141-
logger.debug(
144+
logger.info(
142145
f"Sending notification of video title: `{video['snippet']['title']}` to {bot_channel.id}"
143146
)
144147
await bot_channel.send(
@@ -147,6 +150,19 @@ async def check_subscription(self) -> None:
147150
if subscription.announcement_target
148151
else "@everyone",
149152
title=video["snippet"]["title"],
153+
# HKT+8
154+
scheduled_start_time=(
155+
dt.datetime.fromisoformat(
156+
video["liveStreamingDetails"][
157+
"scheduledStartTime"
158+
].replace("Z", "+00:00")
159+
).replace(
160+
tzinfo=zoneinfo.ZoneInfo(
161+
key="Asia/Hong_Kong"
162+
)
163+
)
164+
+ dt.timedelta(hours=8)
165+
).strftime(r"%B %d (%A), %I:%M %p %Z"),
150166
description=video["snippet"]["description"],
151167
video_id=video["id"],
152168
)

0 commit comments

Comments
 (0)