Browse Source

[sitemap] if last-modified not set in header use current date

This solves the following issue when last-modified is not set in the
response header:

---snip---
KeyError: 'Last-Modified'
---snap---

Change-Id: I372f9638f6b5006ff250b9dbe0e75cc1556d18c2
tags/0.32.0
Christian Berendt 4 years ago
parent
commit
6b5b7d530a
1 changed files with 5 additions and 2 deletions
  1. 5
    2
      sitemap/generator/spiders/sitemap.py

+ 5
- 2
sitemap/generator/spiders/sitemap.py View File

@@ -72,7 +72,10 @@ class SitemapSpider(spiders.CrawlSpider):
72 72
             if path.startswith("/%s" % entry):
73 73
                 item['changefreq'] = 'weekly'
74 74
 
75
-        lastmod = time.strptime(response.headers['Last-Modified'],
76
-                                "%a, %d %b %Y %H:%M:%S %Z")
75
+        if 'Last-Modified' in response.headers:
76
+            timestamp = response.headers['Last-Modified']
77
+        else:
78
+            timestamp = response.headers['Date']
79
+        lastmod = time.strptime(timestamp, "%a, %d %b %Y %H:%M:%S %Z")
77 80
         item['lastmod'] = time.strftime("%Y-%m-%dT%H:%M:%S%z", lastmod)
78 81
         return item

Loading…
Cancel
Save