From fde7eb18c21626739936ab5072d8e537bc3a16de Mon Sep 17 00:00:00 2001 From: Matt Singleton Date: Sat, 14 Oct 2017 18:44:06 -0400 Subject: NPR News closes #2 --- unbiased/sources/npr.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 unbiased/sources/npr.py diff --git a/unbiased/sources/npr.py b/unbiased/sources/npr.py new file mode 100644 index 0000000..e52459f --- /dev/null +++ b/unbiased/sources/npr.py @@ -0,0 +1,29 @@ +from unbiased.sources.base import NewsSource + +class NPR(NewsSource): + + name = 'NPR News' + shortname = 'npr' + url = 'http://www.npr.org/sections/news/' + + bad_titles = ['The Two-Way'] + bad_authors = ['Domenico Montanaro'] + + @classmethod + def _fetch_urls(cls): + soup = cls._fetch_content(cls.url) + + featured = soup.find('div', class_='featured-3-up')\ + .find_all('article', recursive=False) + + h1s = featured[:1] + h1s = tuple(x.find('h2', class_='title').a['href'] for x in h1s) + h2s = featured[1:] + h2s = tuple(x.find('h2', class_='title').a['href'] for x in h2s) + + # get tertiary headlines + h3s = soup.find('div', id='overflow')\ + .find_all('article', recursive=False) + h3s = tuple(x.find('h2', class_='title').a['href'] for x in h3s[:5]) + + return h1s, h2s, h3s -- cgit v1.2.3