diff options
author | mjfernez <mjf@mjfer.net> | 2022-03-10 18:34:22 -0500 |
---|---|---|
committer | mjfernez <mjf@mjfer.net> | 2022-03-10 18:34:22 -0500 |
commit | c0be486968fe3d375d1f408eae7f954e1f5f82fc (patch) | |
tree | d5fac6cc4a8d129275bde64498b0e6662d4d47fe /rss_generator.py | |
parent | f335ff5265a96fdc0b9e0e9d8e4384f866de4e19 (diff) | |
download | ezcms-c0be486968fe3d375d1f408eae7f954e1f5f82fc.tar.gz |
Fixes RSS issues. Changes time tracking to git
This commit primarily changes the code base to base the file last
modified time on the output of "git log". This adds dateutil and git
itself as a dependency, but those are pretty common...
This also fixes some minor issues including:
- missing / between mjfer.net and the URI
- README up to date with latest changes
- linting
Diffstat (limited to 'rss_generator.py')
-rw-r--r-- | rss_generator.py | 18 |
1 files changed, 12 insertions, 6 deletions
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(): |