From 324bb4b81b32ac8aa585de6e93b63e9dbe2ca09b Mon Sep 17 00:00:00 2001 From: yodha8 <104330897+yodha8@users.noreply.github.com> Date: Mon, 20 Jun 2022 12:00:35 -0700 Subject: [PATCH] Create recipe for DistroWatch Weekly --- recipes/distrowatch_weekly.recipe | 59 +++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 recipes/distrowatch_weekly.recipe diff --git a/recipes/distrowatch_weekly.recipe b/recipes/distrowatch_weekly.recipe new file mode 100644 index 0000000000..de16f73e4f --- /dev/null +++ b/recipes/distrowatch_weekly.recipe @@ -0,0 +1,59 @@ +#!/usr/bin/env python + +__license__ = "GPL v3" + +"""DistroWatch Weekly""" + +from calibre.web.feeds.news import BasicNewsRecipe +import datetime + +class DistroWatchWeekly(BasicNewsRecipe): + title = "DistroWatch Weekly" + description = "Weekly news about Linux distributions" + category = "Linux, Technology, News" + oldest_article = 14 + language = "en" + max_articles_per_feed = 50 + no_stylesheets = True + use_embedded_content = False + timefmt = " [%A, %d %B, %Y]" + auto_cleanup = False + + keep_only_tags = [ + dict( + attrs={ + "class": + lambda x: x and ("News1" in x) + } + ) + ] + + def _get_mag_date(self): + """Return date of latest weekly issue.""" + + d = datetime.date(2022, 6, 20) + t = datetime.date.today() + ld = None + while d <= t: + ld = d + d += datetime.timedelta(days=7) + return ld + + def parse_index(self): + + # Get URL of latest mag page + ld = self._get_mag_date() + url = ld.strftime("https://distrowatch.com/weekly.php?issue=%Y%m%d") + url = url.lower() + title = ld.strftime("DistroWatch Weekly for %Y-%m-%d") + + # Get articles + stories = [{ + "url": url, + "title": title, + },] + index = [ + ("Articles", stories), + ] + + return index