reader-extras.py: Add datetime example
authorJack Miller <jack@codezen.org>
Wed, 20 Jan 2016 18:08:45 +0000 (12:08 -0600)
committerJack Miller <jack@codezen.org>
Wed, 20 Jan 2016 18:08:45 +0000 (12:08 -0600)
Adds published and updated times, if provided by the item data.

plugins/reader-extras.py

index 8ec5bb5..64b57a3 100644 (file)
@@ -4,10 +4,24 @@
 
 # Designed to put extra interesting content in the reader output.
 
-enabled_extras = ['slashdot', 'authors']
+enabled_extras = ['datetime', 'slashdot', 'authors']
 
 hacks = {}
 
+datetime_attrs = [ 'published_parsed', 'updated_parsed' ]
+
+def datetime_extras(body, extra_content, attrs):
+    import time
+
+    if attrs['published_parsed']:
+        body = "Published: " + time.asctime(tuple(attrs['published_parsed'])) + "<br />" + body
+    elif attrs['updated_parsed']:
+        body = "Updated: " + time.asctime(tuple(attrs['updated_parsed'])) + "<br />" + body
+
+    return (body, extra_content)
+
+hacks['datetime'] = ('.*', datetime_attrs, datetime_extras)
+
 # Slashdot (example)
 
 slashdot_attrs = [ 'slash_department' ]