From c21562a04a9ec252e4134aaab5de8f06c107630f Mon Sep 17 00:00:00 2001 From: Thomas Baruchel Date: Sat, 5 Nov 2022 12:13:14 +0100 Subject: [PATCH] Update --- rst2atom.py | 50 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/rst2atom.py b/rst2atom.py index 0a9346a..5ad4941 100644 --- a/rst2atom.py +++ b/rst2atom.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- filename="test.rst" +generator_uri = "http://git.sdf.org/rst2atom.py" +generator_name = "rst2atom" # https://docutils.sourceforge.io/docs/api/publisher.html @@ -27,6 +29,16 @@ def extract_docinfos(html): soup1.find_all("th", {"class": "docinfo-name"}) ] } +def extract_meta(html): + """ + Parse the publish_parts dictionary and return a dictionary containing + the metadata from the RsT document. + """ + soup1 = bs4.BeautifulSoup(html["meta"], 'html.parser') + return { m.attrs["name"]: m.attrs["content"] + for m in soup1.find_all("meta", {"name": True, + "content": True}) } + def find_date(d): """ @@ -76,20 +88,36 @@ def build_entry(d): """) -print(""" - - %s - %s - - - urn:uuid:60a76c80-d399-11d9-b91C-0003939e0af6 -""" % ( - html["title"], - datetime.datetime.now().isoformat() -)) docinfos = extract_docinfos(html) +meta = extract_meta(html) + +print(""" + + %s + %s + + %s + %s + + %s + %s + + + %s +""" % ( + meta["original-source"], + html["title"], + docinfos["Author:"], + docinfos["Contact:"], + meta["copyright"], + datetime.datetime.now().isoformat(), + meta["original-source"], + meta["syndication-source"], + generator_uri, generator_name +)) + soup2 = bs4.BeautifulSoup(html["body"], 'html.parser') divs = soup2.select("div")