From c0a0765b1197643465ac142487d90eb8e0c792d0 Mon Sep 17 00:00:00 2001 From: yodha8 <104330897+yodha8@users.noreply.github.com> Date: Mon, 20 Jun 2022 01:23:03 -0700 Subject: [PATCH] Update lwn_free.recipe Skips paid articles and cleanly pulls only past week's free articles. --- recipes/lwn_free.recipe | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/recipes/lwn_free.recipe b/recipes/lwn_free.recipe index 6bed962ec6..5f77bd2083 100644 --- a/recipes/lwn_free.recipe +++ b/recipes/lwn_free.recipe @@ -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