add pytz to the mix, so that we can display time for specific time zones (totally optional dependency)

This commit is contained in:
Von Random 2017-11-30 01:20:35 +03:00
parent e84936b3f8
commit f5c49008ec
2 changed files with 12 additions and 5 deletions

View file

@ -1,4 +1,4 @@
import time
import datetime
import plugins
@ -6,6 +6,13 @@ class PluginThread(plugins.PluginThreadCommon):
def __init__(self, section, config):
super(PluginThread, self).__init__(section, config)
self.date_format = config.get(section, 'format', fallback='%c')
tz = config.get(section, 'TZ', fallback=None)
if tz:
import pytz
self.tz = pytz.timezone(tz)
else:
self.tz = None
def main(self):
self.status['full_text'] = time.strftime(self.date_format)
now = datetime.datetime.now(tz=self.tz)
self.status['full_text'] = now.strftime(self.date_format)

View file

@ -7,9 +7,9 @@ import configparser
import importlib
import json
import os
import plugins
import sys
import time
import plugins
DEFAULT_CONFIG = os.path.join(os.environ['HOME'], '.config/vdstatus/conf.ini')
@ -36,8 +36,8 @@ class PluginRunner:
self.format_output = self.format_term
for section in self.config.sections():
plugin_name = self.config.get(section, 'plugin')
module = importlib.import_module('.' + plugin_name, 'plugins')
thread_object = module.PluginThread(section, self.config)
mod = importlib.import_module('.' + plugin_name, 'plugins')
thread_object = mod.PluginThread(section, self.config)
self.plugins_loaded.append(thread_object)
def start(self):