gemini.git

going-flying.com gemini git repository

summary

tree

log

refs

f3f0fde4f542d87ad22cf0ad904ff7cceb59c32d - Matthew Ernisse - 1666910472

also fix the atom feed. this seems to work

view tree

view raw

diff --git a/files/thoughts-to-gemini.py b/files/thoughts-to-gemini.py
index 50a510f..9cff7ff 100755
--- a/files/thoughts-to-gemini.py
+++ b/files/thoughts-to-gemini.py
@@ -40,12 +40,12 @@ from bs4 import BeautifulSoup
 from feedgen.feed import FeedGenerator
 
 entry_template = '''╒═════╣▒ {{ entry.date }} ▒╟──────────┘
-{% if entry.in_reply_to %}
-│ In-Reply-To: entry.in_reply_to
+{% if entry.in_reply_to_date %}
+│ In-Reply-To: {{ entry.in_reply_to_date }}
 {% endif %}
 {{ entry.message }}
 
-{% if 'attachment' in entry.keys() %}
+{% if entry.attachment %}
     Attachments:
 {% for attachment in entry.attachment %}
 => {{ attachment.name|urlencode }}	{{ attachment.type }}
@@ -207,6 +207,18 @@ class Thoughts(object):
 
 		self.thoughts.sort(key=lambda k: k['id'], reverse=True)
 
+		# Save the date of the In-Reply-To thought on the
+		# in_reply_to property insted of the ID since we
+		# would much rather print the datestr out.
+		for thought in self.thoughts:
+			if thought.get('in-reply-to'):
+				tId = thought['in-reply-to']
+				parent = [
+					t['date'] for t in self.thoughts
+						if t['id'] == tId
+				][0]
+				thought['in_reply_to_date'] = parent
+
 		with open(t_json, 'w', encoding='utf-8') as fd:
 			json.dump(
 				self.thoughts,
@@ -262,7 +274,15 @@ class Thoughts(object):
 			pubdate = pubdate.replace(tzinfo=pytz.utc)
 
 			e = feed.add_entry()
-			e.content(content=str(entry['message']), type='text')
+
+			message = ''
+			if entry.get('in-reply-to'):
+				message += 'In-Reply-To: '
+				message += entry['in_reply_to_date'] + '\n'
+
+			message += str(entry['message'])
+
+			e.content(content=message, type='text')
 			e.id(str(entry['id']))
 			e.title('A brief thought from mernisse')
 			e.link(
@@ -381,15 +401,6 @@ class ThoughtApi(object):
 		thoughts = resp.json()
 		thoughts.sort(key=lambda k: k['id'])
 
-		# Save the date of the In-Reply-To thought on the
-		# in_reply_to property insted of the ID since we
-		# would much rather print the datestr out.
-		for thought in thoughts:
-			if thought.get('in_reply_to'):
-				tId = thought['in_reply_to']
-				parent = [t['date'] for t in thoughts if t['id'] == tId][0]
-				thought['in_reply_to'] = parent
-
 		return thoughts
 
 	def _getRange(self):