[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
This commit is contained in:
Christian Berendt 2015-10-16 07:28:10 +02:00
parent 512d64fd78
commit 6b5b7d530a
1 changed files with 5 additions and 2 deletions

View File

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