| 1 |
#!/usr/bin/env python |
| 2 |
|
| 3 |
__license__ = 'GPL v3' |
| 4 |
|
| 5 |
'''DistroWatch Weekly''' |
| 6 |
|
| 7 |
import datetime |
| 8 |
|
| 9 |
from calibre.web.feeds.news import BasicNewsRecipe |
| 10 |
|
| 11 |
|
| 12 |
class DistroWatchWeekly(BasicNewsRecipe): |
| 13 |
title = 'DistroWatch Weekly' |
| 14 |
description = 'Weekly news about Linux distributions' |
| 15 |
category = 'Linux, Technology, News' |
| 16 |
oldest_article = 14 |
| 17 |
language = 'en' |
| 18 |
max_articles_per_feed = 50 |
| 19 |
no_stylesheets = True |
| 20 |
use_embedded_content = False |
| 21 |
timefmt = ' [%A, %d %B, %Y]' |
| 22 |
auto_cleanup = False |
| 23 |
|
| 24 |
keep_only_tags = [dict(attrs={'class': lambda x: x and ('News1' in x)})] |
| 25 |
|
| 26 |
def _get_mag_date(self): |
| 27 |
"""Return date of latest weekly issue.""" |
| 28 |
|
| 29 |
d = datetime.date(2022, 6, 20) |
| 30 |
t = datetime.date.today() |
| 31 |
ld = None |
| 32 |
while d <= t: |
| 33 |
ld = d |
| 34 |
d += datetime.timedelta(days=7) |
| 35 |
return ld |
| 36 |
|
| 37 |
def parse_index(self): |
| 38 |
|
| 39 |
# Get URL of latest mag page |
| 40 |
ld = self._get_mag_date() |
| 41 |
url = ld.strftime('https://distrowatch.com/weekly.php?issue=%Y%m%d') |
| 42 |
url = url.lower() |
| 43 |
title = ld.strftime('DistroWatch Weekly for %Y-%m-%d') |
| 44 |
|
| 45 |
# Get articles |
| 46 |
stories = [ |
| 47 |
{ |
| 48 |
'url': url, |
| 49 |
'title': title, |
| 50 |
}, |
| 51 |
] |
| 52 |
index = [ |
| 53 |
('Articles', stories), |
| 54 |
] |
| 55 |
|
| 56 |
return index |