Update lwn_free.recipe

Skips paid articles and cleanly pulls only past week's free articles.
This commit is contained in:
yodha8 2022-06-20 01:23:03 -07:00 committed by GitHub
parent c89442e6a5
commit c0a0765b11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,11 +8,41 @@ class LWNFree(BasicNewsRecipe):
title = "LWN Linux Weekly News (Free)"
language = 'en'
__author__ = 'yodha8'
description = "LWN is published every Thursday. Recipe skips current week's articles (subscriber-only) and pulls free articles from previous week."
oldest_article = 14 # So we can grab previous week articles.
description = "LWN is published every Thursday. This recipe skips current week's articles (subscriber-only) and pulls free articles from previous week."
oldest_article = 28 # So we can grab previous week articles.
max_articles_per_feed = 100
auto_cleanup = True
feeds = [
('LWN Articles', 'https://lwn.net/headlines/Features'),
]
def parse_feeds(self):
"""Remove paid articles and articles older than a week."""
prev_feeds = super().parse_feeds()
remove_articles = []
weekly_count = 0
for article in prev_feeds[0]:
# Paid article
if "[$]" in article.title:
remove_articles.append(article)
continue
# Count how many free weekly edition we passed
if "Weekly Edition" in article.title:
weekly_count += 1
# Remove all articles starting from 2nd free weekly edition
if weekly_count > 1:
remove_articles.append(article)
# Remove everything but prev week's free articles
for pa in remove_articles:
prev_feeds[0].remove_article(pa)
print(prev_feeds)
return prev_feeds