chore: rename function, move some init code

Also switching logging back to ERROR from DEBUG. The solution
to the lockups for now is to just use systemd timer timeouts.
This commit is contained in:
A.M. Rowsell 2025-04-22 02:11:01 -04:00
commit e4539b5733
Signed by: amr
GPG key ID: 0B6E2D8375CF79A9

View file

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