From 94f71d6f8fc7301dfd470ccf2fee27e078321a78 Mon Sep 17 00:00:00 2001 From: mjfernez Date: Sun, 13 Mar 2022 15:21:11 -0400 Subject: Pull changes from mjfer.net This commit adds the changes from the mjfer.net which enable using git as the file last update tracker --- rss_generator.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'rss_generator.py') diff --git a/rss_generator.py b/rss_generator.py index bde4645..05a8b39 100644 --- a/rss_generator.py +++ b/rss_generator.py @@ -1,5 +1,6 @@ import os -from time import strftime, strptime +from datetime import datetime +from dateutil import parser from siteconfig import siteconfig from view_functions import is_hidden_path, file_last_modified @@ -12,6 +13,7 @@ class RSS_Item: Item data is generated from a given file path """ + PARAGRAPHS = siteconfig.rss_channel_config['DESCRIPTION_LENGTH'] class NotAFile(Exception): @@ -19,6 +21,7 @@ class RSS_Item: Throws an exception if an RSS_Item is made out of a directory or invalid file """ + def __init__(self, path: str): self.path = path self.message = f"{path} not a file" @@ -32,8 +35,8 @@ class RSS_Item: self.TITLE = path.rsplit('.', 1)[0].split('/')[-1] self.FILE_TYPE = path.rsplit('.', 1)[1] self.DESCRIPTION = self.parse_file() - self.LAST_UPDATE = self.last_updated() self.URI = self.get_uri() + self.LAST_UPDATE = self.last_updated() self.LINK = siteconfig.rss_channel_config['LINK'] + self.URI def __str__(self): @@ -42,7 +45,10 @@ class RSS_Item: ) def short_timestamp(self): - return strftime("%Y-%m-%d %H:%M", strptime(self.LAST_UPDATE)) + if self.LAST_UPDATE is None: + return "" + dt_update = parser.parse(self.LAST_UPDATE) + return datetime.strftime(dt_update, "%Y-%m-%d %H:%M") def parse_file(self): """ @@ -76,11 +82,11 @@ class RSS_Item: return ''.join(description) def last_updated(self): - return file_last_modified(self.FULL_PATH) + return file_last_modified(self.URI) def get_uri(self): - # return everything after "./templates/" - return '/'.join(self.FULL_PATH.split('/')[2:]) + # return everything after "./templates/site" + return '/'.join(self.FULL_PATH.split('/')[3:]) def get_rss_channel(): -- cgit v1.2.3