fix timezone errors
This commit is contained in:
		
							parent
							
								
									d5e25f8da3
								
							
						
					
					
						commit
						624d286d8a
					
				
					 1 changed files with 7 additions and 1 deletions
				
			
		| 
						 | 
					@ -1,5 +1,6 @@
 | 
				
			||||||
import asyncio
 | 
					import asyncio
 | 
				
			||||||
import random
 | 
					import random
 | 
				
			||||||
 | 
					import sys
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import aiocron
 | 
					import aiocron
 | 
				
			||||||
import telethon
 | 
					import telethon
 | 
				
			||||||
| 
						 | 
					@ -16,7 +17,12 @@ 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)
 | 
					        local_tz = config.get('timezone', pgbotlib.defaults.TZ)
 | 
				
			||||||
 | 
					        try:
 | 
				
			||||||
 | 
					            self.tz = pytz.timezone(local_tz)
 | 
				
			||||||
 | 
					        except pytz.exceptions.UnknownTimeZoneError as e:
 | 
				
			||||||
 | 
					            sys.stderr.write(e)
 | 
				
			||||||
 | 
					            self.tz = pytz.utc
 | 
				
			||||||
        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
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue