| 1 |
#!/usr/bin/env python |
| 2 |
# vim:fileencoding=utf-8 |
| 3 |
|
| 4 |
from calibre.web.feeds.news import BasicNewsRecipe |
| 5 |
|
| 6 |
|
| 7 |
class LWNFree(BasicNewsRecipe): |
| 8 |
title = 'LWN Linux Weekly News (Free)' |
| 9 |
language = 'en' |
| 10 |
__author__ = 'yodha8' |
| 11 |
description = "LWN is published every Thursday. This recipe skips current week's articles (subscriber-only) and pulls free articles from previous week." |
| 12 |
oldest_article = 28 # So we can grab previous week articles. |
| 13 |
max_articles_per_feed = 100 |
| 14 |
extra_css = '.FeatureByline { font-size:small; }' |
| 15 |
|
| 16 |
keep_only_tags = [dict(name='div', attrs={'class': ['ArticleText', 'PageHeadline']})] |
| 17 |
remove_tags = [dict(name='blockquote', attrs={'class': 'ad'}), dict(name='form')] |
| 18 |
|
| 19 |
feeds = [ |
| 20 |
('LWN Articles', 'https://lwn.net/headlines/Features'), |
| 21 |
] |
| 22 |
|
| 23 |
def parse_feeds(self): |
| 24 |
"""Remove paid articles and articles older than a week.""" |
| 25 |
|
| 26 |
prev_feeds = super().parse_feeds() |
| 27 |
|
| 28 |
remove_articles = [] |
| 29 |
weekly_count = 0 |
| 30 |
|
| 31 |
for article in prev_feeds[0]: |
| 32 |
# Paid article |
| 33 |
if '[$]' in article.title: |
| 34 |
remove_articles.append(article) |
| 35 |
continue |
| 36 |
|
| 37 |
# Count how many free weekly edition we passed |
| 38 |
if 'Weekly Edition' in article.title: |
| 39 |
weekly_count += 1 |
| 40 |
remove_articles.append(article) |
| 41 |
|
| 42 |
# Remove all articles starting from 2nd free weekly edition |
| 43 |
if weekly_count > 1: |
| 44 |
remove_articles.append(article) |
| 45 |
|
| 46 |
# Remove everything but prev week's free articles |
| 47 |
for pa in remove_articles: |
| 48 |
prev_feeds[0].remove_article(pa) |
| 49 |
|
| 50 |
return prev_feeds |