diff --git a/discorss.py b/discorss.py index 99b4398..9d001ce 100755 --- a/discorss.py +++ b/discorss.py @@ -66,7 +66,10 @@ class Discorss: desc = desc + str(addons) return desc - def setupPaths(self): + def setup(self): + os.environ["TZ"] = "America/Toronto" + time.tzset() + self.now = time.mktime(time.localtime()) # Check for log and config files/paths, create empty directories if needed # TODO: make this cleaner if not Path(self.log_dir).exists(): @@ -107,22 +110,19 @@ class Discorss: logging.basicConfig( filename=str(self.log_dir + self.log_file_path), encoding="utf-8", - level=logging.DEBUG, + level=logging.ERROR, datefmt="%m/%d/%Y %H:%M:%S", format="%(asctime)s: %(levelname)s: %(message)s", ) return def process(self): - os.environ["TZ"] = "America/Toronto" - time.tzset() - now = time.mktime(time.localtime()) - self.setupPaths() # Handle the config and log paths + self.setup() # Handle the config and log paths try: last_check = self.app_config["lastupdate"] except KeyError: last_check = ( - now - 21600 + self.now - 21600 ) # first run, no lastupdate, check up to 6 hours ago for i, hook in enumerate(self.app_config["feeds"]): # Feed loop start self.logger.debug("Parsing feed %s...", hook["name"]) @@ -172,10 +172,10 @@ class Discorss: ) # Generate the webhook self.logger.info( - "Publishing webhook for %s. Last check was %d, now is %d", + "Publishing webhook for %s. Last check was %d, self.now is %d", hook["name"], last_check, - now, + self.now, ) webhook = { "embeds": [ @@ -197,7 +197,7 @@ class Discorss: "value": self.get_description(latest_post), } ], - # "timestamp": str(now), + # "timestamp": str(self.now), } ], "attachments": [], @@ -223,7 +223,7 @@ class Discorss: # Dump updated config back to json file self.logger.debug("Dumping config back to %s", str(self.config_file_path)) - self.app_config["lastupdate"] = now + self.app_config["lastupdate"] = self.now with open(self.config_file_path, "w") as config_file: json.dump(self.app_config, config_file, indent=4)