Use feedgen instead of feedformatter

master
Ryan Rix 2019-03-18 19:23:07 -07:00
parent cbe2805f36
commit 653d05f8c8
2 changed files with 30 additions and 22 deletions

View File

@ -22,7 +22,7 @@ import shutil
import urllib2
import hashlib
import markdown, feedformatter
import markdown, feedgen.feed as feed
script_root_dir = path.dirname( path.abspath(__file__) )
@ -93,10 +93,22 @@ def setup_afd_feed(result_dir, afd_entries):
# shutil.rmtree(result_dir)
# os.makedirs(result_dir)
afd_feed_items = []
afd_feed = feed.FeedGenerator()
afd_feed.title("NWS Seattle Area Forecast Discussion")
afd_feed.link(href="https://afd.fontkeming.fail/SEW/current.md", rel="self")
afd_feed.id('https://afd.fontkeming.fail')
afd_feed.author(name="Ryan Rix", email="ry@n.rix.si")
afd_feed.description("NWS Seattle Area Forecast Discussion")
current = None
current_md = None
for afd_entry in sorted(afd_entries, reverse = True, key=lambda e: e["timestamp"] ):
eid = afd_entry["timestamp"].strftime("%y-%m-%d-%H%m")
if not current:
afd_feed.updated(afd_feed["timestamp"])
current = eid
entry_md = format_afd(afd_entry)
logging.debug("Rendered entry md:\n%s", entry_md)
@ -105,31 +117,27 @@ def setup_afd_feed(result_dir, afd_entries):
with open(entry_md_file, "w") as md_out:
md_out.write(entry_md)
item = {}
item = afd_feed.add_entry()
md = markdown.markdown( entry_md )
item["title"] = pformat_time(afd_entry["timestamp"])
item["link"] = eid + ".md"
item["description"] = markdown.markdown( entry_md )
item["markdown"] = entry_md
item["pubDate"] = afd_entry["timestamp"].timetuple()
item["guid"] = eid
afd_feed_items.append(item)
if not current_md:
current_md = md
logging.info("Writing current: %s", afd_feed_items[0]["guid"])
item.title(pformat_time(afd_entry["timestamp"]))
item.link(href=(eid + ".md"))
item.description(md)
item.pubDate(afd_entry["timestamp"])
item.updated(afd_entry["timestamp"])
item.guid(eid)
item.id(eid)
logging.info("Writing current: %s", current)
with open( path.join(result_dir, "current.md"), "w") as md_out:
md_out.write( afd_feed_items[0]["markdown"] )
afd_feed = feedformatter.Feed()
afd_feed.feed["title"] = "NWS Seattle Area Forecast Discussion"
afd_feed.feed["link"] = "current.md"
afd_feed.feed["author"] = "ry@n.rix.si"
afd_feed.feed["description"] = "NWS Seattle Area Forecast Discussion"
afd_feed.entries.extend(afd_feed_items)
md_out.write(current_md)
logging.info("Rendering feed file: %s", path.join(result_dir, "AFDSEW.xml"))
afd_feed.format_atom_file( path.join(result_dir, "AFDSEW.xml"))
afd_feed.atom_file( path.join(result_dir, "AFDSEW.xml"))
return result_dir

View File

@ -1,4 +1,4 @@
markdown
feedformatter
feedgen
click
arrow