From 78ca7464b662cfe336eee0bd4364615a006d1e9a Mon Sep 17 00:00:00 2001 From: fram3d Date: Fri, 4 Aug 2023 23:18:01 +0200 Subject: [PATCH] add event generation to atom_gen.py --- .gitignore | 2 ++ atom_gen.py | 56 +++++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 55bbdde..6cf32f8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ venv/ poster.html poster.pdf +atom_blog.xml +atom_events.xml diff --git a/atom_gen.py b/atom_gen.py index 2bbe3d7..a9bf126 100755 --- a/atom_gen.py +++ b/atom_gen.py @@ -5,6 +5,7 @@ # also expects that *.md files are in blog/ directory from feedgen.feed import FeedGenerator +import datetime import subprocess import os @@ -25,21 +26,48 @@ def blogposts_list_gen(): output_list.append([author, title, time, content_html, full_path]) return output_list -def feedgen(blogs): - fg = FeedGenerator() - fg.id('http://dmz.rs/') - fg.title('Decentrala Blog') - fg.author( {'name':'Decentrala','email':'dmz@dmz.rs'} ) - fg.link( href='https://dmz.rs/atom.xml', rel='self' ) +def events_list_gen(): + output_list = [] + events_file = open("dogadjaji.csv", "r") + for line in events_file.readlines(): + date, time, location, title = line.split(", ") + author = "Decentrala" + content_html = f"Event is taking place at {location} on {date} at {time}. For more information see the forum at https://forum.dmz.rs" + + output_list.append([author, title, content_html]) + events_file.close() + return output_list + +def feedgen(blogs, events): + fg_blog = FeedGenerator() + fg_blog.id('http://dmz.rs/') + fg_blog.title('Decentrala Blog') + fg_blog.author( {'name':'Decentrala','email':'dmz@dmz.rs'} ) + fg_blog.link( href='https://dmz.rs/atom_blog.xml', rel='self' ) + + fg_events = FeedGenerator() + fg_events.id('http://dmz.rs/') + fg_events.title('Decentrala Blog') + fg_events.author( {'name':'Decentrala','email':'dmz@dmz.rs'} ) + fg_events.link( href='https://dmz.rs/atom_events.xml', rel='self' ) for post in blogs: - fe = fg.add_entry() - fe.id("https://dmz.rs/" + post[4][:-3] + ".html") - fe.author({'name': post[0]}) - fe.title(post[1]) - fe.updated(post[2]) - fe.content(content=post[3], type='html') + fe_blogs = fg_blog.add_entry() + fe_blogs.id("https://dmz.rs/" + post[4][:-3] + ".html") + fe_blogs.author({'name': post[0]}) + fe_blogs.title(post[1]) + fe_blogs.updated(post[2]) + fe_blogs.content(content=post[3], type='html') - fg.atom_file('atom.xml') + for event in events: + fe_events = fg_events.add_entry() + fe_events.id("https://dmz.rs/pages/events.html") + fe_events.author({'name': event[0]}) + fe_events.title(event[1]) + fe_events.updated(datetime.datetime.now(datetime.timezone.utc)) + fe_events.content(content=event[2], type='html') -feedgen(blogposts_list_gen()) + fg_blog.atom_file('atom_blog.xml') + fg_events.atom_file('atom_events.xml') + +feedgen(blogposts_list_gen(), events_list_gen())