From 73516a15fe5a0142256ef46e279f9dd9b407e900 Mon Sep 17 00:00:00 2001 From: Zhiming Wang Date: Wed, 13 May 2015 13:03:59 -0700 Subject: sitemap.xml: correct datetime format coreutils date --iso-8601=s generates output like 2015-05-13T13:04:24-0700 while the correct format (at least the format Python datetime.datetime.isoformat() prints, and the format Google expects) is 2015-05-13T13:04:24-07:00 Account for this problem. I didn't read the RFC, so not sure. --- pyblog | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'pyblog') diff --git a/pyblog b/pyblog index fe3b1f16..e563660f 100755 --- a/pyblog +++ b/pyblog @@ -267,7 +267,7 @@ def make_sitemap_url_element(link, updated=None, changefreq=None, priority=None) link : str or xml.etree.ElementTree.Element If using an xml.etree.ElementTree.Element element, then it shall be an atom:link element, e.g., . - updated : str or xml.etree.ElementTree.Element, optional + updated : datetime or xml.etree.ElementTree.Element, optional If using an xml.etree.ElementTree.Element element, then it shall be an atom:updated element, e.g., 2015-05-05T22:38:42-07:00. @@ -282,7 +282,8 @@ def make_sitemap_url_element(link, updated=None, changefreq=None, priority=None) urlelem.append(loc) if updated is not None: lastmod = ET.Element("lastmod") - lastmod.text = updated.text if isinstance(updated, ET.Element) else updated + lastmod.text = (updated.text if isinstance(updated, ET.Element) + else updated.isoformat()) urlelem.append(lastmod) if changefreq is not None: changefreq_elem = ET.Element("changefreq") @@ -313,7 +314,7 @@ def generate_sitemap(feed): if soup.article.footer is not None: updated_tag = soup.article.footer.find(attrs={"class": "updated"}) if updated_tag is not None: - updated = updated_tag.text + updated = dateutil.parser.parse(updated_tag.text) sitemap.append(make_sitemap_url_element(link, updated, "monthly", 0.9)) # blog entries @@ -323,6 +324,7 @@ def generate_sitemap(feed): with open(sitemappath, "w", encoding="utf-8") as sitemapfile: sitemapfile.write('\n%s\n' % ET.tostring(sitemap).decode('utf-8')) + sys.stderr.write("wrote sitemap.xml\n") def generate_index_and_feed(): -- cgit v1.2.1