implement timezone as part of config instead of env
This commit is contained in:
parent
60e9584949
commit
fd97c1862a
3 changed files with 6 additions and 2 deletions
|
@ -17,5 +17,6 @@ response_tokens: tokens.dist.yml
|
||||||
# scheduled task list
|
# scheduled task list
|
||||||
schedule: sched.dist.yml
|
schedule: sched.dist.yml
|
||||||
|
|
||||||
|
timezone: Europe/Moscow
|
||||||
admins:
|
admins:
|
||||||
- 00000000
|
- 00000000
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import random
|
import random
|
||||||
|
|
||||||
import yaml
|
|
||||||
import aiocron
|
import aiocron
|
||||||
import telethon
|
import telethon
|
||||||
import pgbotlib.defaults
|
import pgbotlib.defaults
|
||||||
import pgbotlib.response
|
import pgbotlib.response
|
||||||
import pgbotlib.misc
|
import pgbotlib.misc
|
||||||
|
import pytz
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
|
||||||
class Cron:
|
class Cron:
|
||||||
|
@ -15,6 +16,7 @@ class Cron:
|
||||||
client: telethon.TelegramClient,
|
client: telethon.TelegramClient,
|
||||||
responder: pgbotlib.response.Responder) -> None:
|
responder: pgbotlib.response.Responder) -> None:
|
||||||
schedule_conf = config.get('schedule', pgbotlib.defaults.SCHEDULE)
|
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:
|
with open(schedule_conf, 'r', encoding='utf-8') as data:
|
||||||
self.sched = yaml.safe_load(data.read())
|
self.sched = yaml.safe_load(data.read())
|
||||||
self.responder = responder
|
self.responder = responder
|
||||||
|
@ -33,4 +35,4 @@ class Cron:
|
||||||
|
|
||||||
def plan(self) -> None:
|
def plan(self) -> None:
|
||||||
for job in self.sched:
|
for job in self.sched:
|
||||||
aiocron.crontab(job['cron'], func=self.__mkjob(job))
|
aiocron.crontab(job['cron'], tz=self.tz, func=self.__mkjob(job))
|
||||||
|
|
|
@ -2,3 +2,4 @@ CONFDIR = '/pgbot/conf'
|
||||||
CONFIG = CONFDIR + '/pgbot.yml'
|
CONFIG = CONFDIR + '/pgbot.yml'
|
||||||
TOKENS = CONFDIR + '/tokens.yml'
|
TOKENS = CONFDIR + '/tokens.yml'
|
||||||
SCHEDULE = CONFDIR + '/sched.yml'
|
SCHEDULE = CONFDIR + '/sched.yml'
|
||||||
|
TZ = 'UTC'
|
||||||
|
|
Loading…
Reference in a new issue