From fd97c1862a2ae0bdc7f9bef336ec90a7bd67b888 Mon Sep 17 00:00:00 2001 From: Von Random Date: Tue, 5 Nov 2024 03:30:09 +0200 Subject: [PATCH] implement timezone as part of config instead of env --- configs/pgbot.dist.yml | 1 + pgbotlib/cron.py | 6 ++++-- pgbotlib/defaults.py | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/configs/pgbot.dist.yml b/configs/pgbot.dist.yml index 618a70c..449cf30 100644 --- a/configs/pgbot.dist.yml +++ b/configs/pgbot.dist.yml @@ -17,5 +17,6 @@ response_tokens: tokens.dist.yml # scheduled task list schedule: sched.dist.yml +timezone: Europe/Moscow admins: - 00000000 diff --git a/pgbotlib/cron.py b/pgbotlib/cron.py index 45482ba..b4c06b6 100644 --- a/pgbotlib/cron.py +++ b/pgbotlib/cron.py @@ -1,12 +1,13 @@ import asyncio import random -import yaml import aiocron import telethon import pgbotlib.defaults import pgbotlib.response import pgbotlib.misc +import pytz +import yaml class Cron: @@ -15,6 +16,7 @@ class Cron: client: telethon.TelegramClient, responder: pgbotlib.response.Responder) -> None: schedule_conf = config.get('schedule', pgbotlib.defaults.SCHEDULE) + self.tz = config.get('timezone', pgbotlib.defaults.TZ) with open(schedule_conf, 'r', encoding='utf-8') as data: self.sched = yaml.safe_load(data.read()) self.responder = responder @@ -33,4 +35,4 @@ class Cron: def plan(self) -> None: for job in self.sched: - aiocron.crontab(job['cron'], func=self.__mkjob(job)) + aiocron.crontab(job['cron'], tz=self.tz, func=self.__mkjob(job)) diff --git a/pgbotlib/defaults.py b/pgbotlib/defaults.py index 1d8f343..47cb4bc 100644 --- a/pgbotlib/defaults.py +++ b/pgbotlib/defaults.py @@ -2,3 +2,4 @@ CONFDIR = '/pgbot/conf' CONFIG = CONFDIR + '/pgbot.yml' TOKENS = CONFDIR + '/tokens.yml' SCHEDULE = CONFDIR + '/sched.yml' +TZ = 'UTC'