Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a parser for nu.nl (dutch news site) #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions parsers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
cnn.CNNParser
politico.PoliticoParser
bbc.BBCParser
nunl.NuNLParser
""".split()

parser_dict = {}
Expand Down
37 changes: 37 additions & 0 deletions parsers/nunl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from baseparser import BaseParser
from BeautifulSoup import BeautifulSoup, Tag


class NuNLParser(BaseParser):
SUFFIX = ''
domains = ['www.nu.nl']

feeder_base = 'http://www.nu.nl/'
feeder_pat = '^http://www.nu.nl/\w+/\d+/'

def _parse(self, html):
soup = BeautifulSoup(html, convertEntities=BeautifulSoup.HTML_ENTITIES,
fromEncoding='utf-8')

header = soup.find('div', 'header')

self.meta = soup.findAll('meta')
self.title = header.find('h1').getText()

self.byline = ''

# Date of the last revision
self.date = header.find('div', 'dateplace-data').contents[2].lstrip()

content = soup.find('div', 'content')

self.body = ''

for i in content.childGenerator():
if not isinstance(i, Tag):
continue
if not i.name == 'h2' and not i.name == 'p':
continue

self.body += i.getText() + '\n\n'

1 change: 1 addition & 0 deletions website/frontend/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def strip_prefix(string, prefix):
'edition.cnn.com': 'CNN',
'www.bbc.co.uk': 'BBC',
'www.politico.com': 'Politico',
'www.nu.nl': 'Nu.nl',
}

ancient = datetime(1901, 1, 1)
Expand Down
2 changes: 1 addition & 1 deletion website/frontend/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def get_articles(source=None, distance=0):
return articles


SOURCES = 'nytimes.com cnn.com politico.com bbc.co.uk'.split() + ['']
SOURCES = 'nytimes.com cnn.com politico.com bbc.co.uk nu.nl'.split() + ['']

@cache_page(60 * 30) #30 minute cache
def browse(request, source=''):
Expand Down