From 9f4ff4acf08e33194509018726b7ddbeaf651656 Mon Sep 17 00:00:00 2001 From: Jason Schwarzenberger Date: Wed, 4 Nov 2020 11:22:15 +1300 Subject: [PATCH] remove unnecessary sitemap.xml request. --- apiserver/feeds/news.py | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/apiserver/feeds/news.py b/apiserver/feeds/news.py index 9c1917f..3a61b72 100644 --- a/apiserver/feeds/news.py +++ b/apiserver/feeds/news.py @@ -109,36 +109,20 @@ class Sitemap: return [x.find('loc').text for x in articles] or [] def story(self, ref): - markup = xml(lambda x: self.sitemap_url) - if not markup: return [] - soup = BeautifulSoup(markup, features='lxml') - articles = soup.find('urlset').findAll('url') - articles = list(filter(None, [a if a.find('lastmod') is not None else None for a in articles])) - articles = list(filter(None, [a if a.find('loc').text == ref else None for a in articles])) - - if len(articles) == 0: + markup = xml(lambda x: ref) + if not markup: return False - r = articles[0] - if not r: - return False - - html = xml(lambda x: ref) - - if not html: - return False - - data = extruct.extract(html) - s = {} s['author_link'] = '' - s['score'] = '' + s['score'] = 0 s['comments'] = [] s['num_comments'] = 0 s['link'] = ref s['url'] = ref - s['date'] = unix(r.find('lastmod').text) + s['date'] = 0 + data = extruct.extract(markup) s = parse_extruct(s, data) return s @@ -162,17 +146,16 @@ class Category: if not markup: return False - data = extruct.extract(markup) - s = {} s['author_link'] = '' - s['score'] = '' + s['score'] = 0 s['comments'] = [] s['num_comments'] = 0 s['link'] = ref s['url'] = ref s['date'] = 0 + data = extruct.extract(markup) s = parse_extruct(s, data) return s