add event generation to atom_gen.py

This commit is contained in:
fram3d 2023-08-04 23:18:01 +02:00
parent 3990f37738
commit 78ca7464b6
Signed by: fram3d
GPG Key ID: 938920E709EEA32A
2 changed files with 44 additions and 14 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
venv/
poster.html
poster.pdf
atom_blog.xml
atom_events.xml

View File

@ -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())