From 30df62d1d5db83061408f6b42943d6bc30a7197b Mon Sep 17 00:00:00 2001 From: manetta Date: Sun, 7 Mar 2021 11:36:03 +0100 Subject: [PATCH] adding RSS support to logbot --- LogBot/feed.rss | 18 ++++++++++++++++++ LogBot/logbot.py | 29 +++++++++++++++++++++++------ 2 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 LogBot/feed.rss diff --git a/LogBot/feed.rss b/LogBot/feed.rss new file mode 100644 index 0000000..9356b0d --- /dev/null +++ b/LogBot/feed.rss @@ -0,0 +1,18 @@ + + + + {{ title }} + {{ log_path }} + Collective log writing using XMPP chat groups and LogBot. + {{ date }} + {% for post in db["messages"] %} + + + {{ log_path }}#{{ x }} + {{ post }} + LogBot + {{ post.date }} + + {% endfor %} + + \ No newline at end of file diff --git a/LogBot/logbot.py b/LogBot/logbot.py index 86708d5..7a1bb80 100644 --- a/LogBot/logbot.py +++ b/LogBot/logbot.py @@ -3,11 +3,10 @@ import re import shutil import urllib.request from urllib.parse import urlparse - +from datetime import datetime import jinja2 from xbotlib import Bot - class Logbot(Bot): help = """Oh dear, logbot is here! @@ -106,10 +105,25 @@ class Logbot(Bot): with open(log_path, "w") as out: html = template.render( title=self.db[message.room]["title"], - db=self.db[message.room]["messages"], + db=self.db[message.room]["messages"] ) out.write(html) - self.log.info(f"writing to: {log_path}") + self.log.info(f"writing to: { log_path }") + + def _generate_feed(self, message): + template = jinja2.Template(open("feed.rss").read()) + room_name = self._parse_room_name(message.room) + feed_path = os.path.join(self.output, room_name, "feed.rss") + date = datetime.now() + with open(feed_path, "w") as out: + feed = template.render( + log_path=os.path.join(self.output, room_name, "index.html"), + title=self.db[message.room]["title"], + db=self.db[message.room], + date=date.strftime("%A, %d. %B %Y %I:%M%p") + ) + out.write(feed) + self.log.info(f"writing to: { feed_path }") def _add_to_db(self, message, media_post=None): """Save new entry to database.""" @@ -122,8 +136,8 @@ class Logbot(Bot): if media_post: self.db[message.room]["messages"][new_key] = media_post else: - replaced = message.content.replace("@add", "") - self.db[message.room]["messages"][new_key] = replaced + post = message.content.replace("@add ", "") + self.db[message.room]["messages"][new_key] = post self.db._dumps() def _parse_room_name(self, room): @@ -218,6 +232,9 @@ class Logbot(Bot): # Regenerate the log webpage self._write_log(message) + # Regenerate the RSS feed + self._generate_feed(message) + # Reply to the groupchat self.reply(reply, room=message.room)