gemini.git

going-flying.com gemini git repository

summary

tree

log

refs

dfa046340f05abdc68b84d43840b69938c39b587 - Matthew Ernisse - 1598544561

generate an atom feed of thoughts

view tree

view raw

diff --git a/files/thoughts-to-gemini.py b/files/thoughts-to-gemini.py
index 7efe220..dd78f3b 100755
--- a/files/thoughts-to-gemini.py
+++ b/files/thoughts-to-gemini.py
@@ -37,6 +37,7 @@ import sys
 import time
 
 from bs4 import BeautifulSoup
+from feedgen.feed import FeedGenerator
 
 entry_template = '''╒═════╣▒ {{ entry.date }} ▒╟──────────┘
 > {{ entry.message }}
@@ -77,6 +78,9 @@ index_template = '''```
 🚀 © MMXX matt@going-flying.com 
 '''
 
+URLBASE = 'gemini://going-flying.com/thoughts/'
+WEBBASE = 'https://www.going-flying.com/thoughts/'
+
 class DeHTMLizer(object):
 	'''Converter for the lightweight Thoughts HTML into gemini's
 	markup language.
@@ -163,7 +167,6 @@ class Thoughts(object):
 	attachurl = 'https://thoughtsassets.blob.core.windows.net/thumbnails'
 	def __init__(self, thoughtdir):
 		self.api = ThoughtApi()
-		self.entries = []
 		self.thoughtdir = thoughtdir
 		self.thoughts = []
 		self._years = {}
@@ -218,6 +221,44 @@ class Thoughts(object):
 				'thoughts': self
 			}))
 
+		# Generate the atom feed.
+		feed = FeedGenerator()
+		feed.id(URLBASE)
+		feed.title('Thoughts from mernisse')
+		feed.author({
+			'name': 'mernisse',
+			'email': 'matt@going-flying.com'
+		})
+		feed.link(
+			href=URLBASE,
+			rel='alternate'
+		)
+		feed.link(
+			href=URLBASE + 'atom.xml',
+			rel='self'
+		)
+
+		for entry in self.thoughts:
+			e = feed.add_entry()
+			e.content(
+				content=entry['message'],
+				type='text'
+			)
+			e.published(
+				datetime.datetime.utcfromtimestamp(
+					entry['id']
+				)
+			)
+			e.title('A brief thought from mernisse')
+			e.link(
+				href=f'{ WEBBASE }{ entry['id'] }.html',
+				rel='alternate',
+				type='text/html'
+			)
+
+		outFile = os.path.join(thoughtdir, 'atom.xml')
+		feed.atom_file(outFile)
+
 	def _downloadAttachments(self, localdir, thought):
 		if 'attachment' not in thought:
 			return