From ec3dac53e78d25965d2c38c93b79cae5d54ca4c0 Mon Sep 17 00:00:00 2001 From: blank X Date: Thu, 19 Aug 2021 01:38:57 +0700 Subject: [PATCH] Show time when live event starts --- example-config.yaml | 1 + ytnotifier.py | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/example-config.yaml b/example-config.yaml index 851ae78..66d078e 100644 --- a/example-config.yaml +++ b/example-config.yaml @@ -9,6 +9,7 @@ storage: config: notify_chat: 558772678 wait_seconds: 1800 + time_offset: +07:00 channels: - UCL_qhgtOy0dy1Agp8vkySQg - UCHsx4Hqa-1ORjQTh9TYDhww diff --git a/ytnotifier.py b/ytnotifier.py index 979f59e..46f2302 100644 --- a/ytnotifier.py +++ b/ytnotifier.py @@ -7,6 +7,7 @@ import asyncio import logging import yaml import feedparser +from datetime import datetime, timedelta from telethon import TelegramClient from youtube_dl import YoutubeDL from youtube_dl.extractor import youtube @@ -28,6 +29,12 @@ if config.get('storage'): storage_message_id = config['storage'].get('storage_message_id') notify_chat = config['config']['notify_chat'] wait_seconds = config['config']['wait_seconds'] +time_offset = config['config'].get('time_offset', '00:00') +time_offset_neg = time_offset.startswith('-') +if time_ottset_neg or time_offset.startswith('+'): + time_offset = time_offset[1:] +hours, minutes = time_offset.split(':') +time_offset_td = timedelta(hours=int(hours), minutes=int(minutes)) channels = config['config']['channels'] invidious_instances = config['config'].get('invidious_instances', []) @@ -91,6 +98,12 @@ async def _handle_video(video_id, video_title): notify_text = 'Live event started' human_end_schedule_time = match.group(3) if end_schedule_time := int(end_schedule_time): + human_end_schedule_time += ' (' + if time_offset_neg: + human_end_schedule_time += str(datetime.fromtimestamp(end_schedule_time) - time_offset_td) + else: + human_end_schedule_time += str(datetime.fromtimestamp(end_schedule_time) + time_offset_td) + human_end_schedule_time += f' {"-" if time_offset_neg else "+"}{time_offset})' tmp_wait_time = end_schedule_time - time.time() if tmp_wait_time > wait_time: wait_time = tmp_wait_time