| 1 |
import re |
| 2 |
|
| 3 |
from calibre.web.feeds.news import BasicNewsRecipe |
| 4 |
|
| 5 |
|
| 6 |
class deredactie(BasicNewsRecipe): |
| 7 |
title = 'Deredactie.be' |
| 8 |
oldest_article = 7 |
| 9 |
max_articles_per_feed = 100 |
| 10 |
no_stylesheets = True |
| 11 |
cover_url = 'http://www.deredactie.be/polopoly_fs/1.510827!image/2710428628.gif' |
| 12 |
language = 'de' |
| 13 |
keep_only_tags = [] |
| 14 |
__author__ = 'malfi' |
| 15 |
keep_only_tags.append(dict(name='div', attrs={'id': 'articlehead'})) |
| 16 |
keep_only_tags.append(dict(name='div', attrs={'id': 'articlebody'})) |
| 17 |
remove_tags = [] |
| 18 |
remove_tags.append(dict(name='div', attrs={'id': 'story'})) |
| 19 |
remove_tags.append(dict(name='div', attrs={'id': 'useractions'})) |
| 20 |
remove_tags.append(dict(name='hr')) |
| 21 |
|
| 22 |
extra_css = ''' |
| 23 |
h1{font-family:Arial,Helvetica,sans-serif; font-weight:bold;font-size:large;} |
| 24 |
h2{font-family:Arial,Helvetica,sans-serif; font-weight:normal;font-size:small;} |
| 25 |
p{font-family:Arial,Helvetica,sans-serif;font-size:small;} |
| 26 |
body{font-family:Helvetica,Arial,sans-serif;font-size:small;} |
| 27 |
''' |
| 28 |
|
| 29 |
def parse_index(self): |
| 30 |
categories = [] |
| 31 |
catnames = {} |
| 32 |
soup = self.index_to_soup('http://www.deredactie.be/cm/vrtnieuws.deutsch') |
| 33 |
for elem in soup.findAll('li', attrs={'id': re.compile(r'^navItem[2-9]')}): |
| 34 |
a = elem.find('a', href=True) |
| 35 |
m = re.search(r'(?<=/)[^/]*$', a['href']) |
| 36 |
cat = str(m.group(0)) |
| 37 |
categories.append(cat) |
| 38 |
catnames[cat] = a['title'] |
| 39 |
self.log('found cat %s\n' % catnames[cat]) |
| 40 |
|
| 41 |
feeds = [] |
| 42 |
|
| 43 |
for cat in categories: |
| 44 |
articles = [] |
| 45 |
soup = self.index_to_soup('http://www.deredactie.be/cm/vrtnieuws.deutsch/' + cat) |
| 46 |
for a in soup.findAll('a', attrs={'href': re.compile(r'deutsch.*/[0-9][0-9][0-9][0-9][0-9][0-9]_')}): |
| 47 |
skip_this_article = False |
| 48 |
url = a['href'].strip() |
| 49 |
if url.startswith('/'): |
| 50 |
url = 'http://www.deredactie.be' + url |
| 51 |
myarticle = {'title': self.tag_to_string(a), 'url': url, 'description': '', 'date': ''} |
| 52 |
for article in articles: |
| 53 |
if article['url'] == url: |
| 54 |
skip_this_article = True |
| 55 |
self.log('SKIPPING DUP %s' % url) |
| 56 |
break |
| 57 |
if skip_this_article: |
| 58 |
continue |
| 59 |
articles.append(myarticle) |
| 60 |
self.log('Adding URL %s\n' % url) |
| 61 |
if articles: |
| 62 |
feeds.append((catnames[cat], articles)) |
| 63 |
return feeds |