Update wash_post.recipe

This commit is contained in:
unkn0w7n 2025-04-19 08:21:55 +05:30
parent 9e3a2c8be7
commit e987f88036

View File

@ -16,7 +16,14 @@ from calibre.web.feeds.news import BasicNewsRecipe
class TheWashingtonPost(BasicNewsRecipe): class TheWashingtonPost(BasicNewsRecipe):
title = 'The Washington Post' title = 'The Washington Post'
__author__ = 'Darko Miletic, unkn0wn' __author__ = 'Darko Miletic, unkn0wn'
description = 'Leading source for news, video and opinion on politics, business, world and national news, science, travel, entertainment and more. Our local coverage includes reporting on education, crime, weather, traffic, real estate, jobs and cars for DC, Maryland and Virginia. Offering award-winning opinion writing, entertainment information and restaurant reviews.' # noqa: E501 description = (
'Leading source for news, video and opinion on politics, business, '
'world and national news, science, travel, entertainment and more. '
'Our local coverage includes reporting on education, crime, weather, '
'traffic, real estate, jobs and cars for DC, Maryland and Virginia. '
'Offering award-winning opinion writing, entertainment information '
'and restaurant reviews.'
)
publisher = 'The Washington Post Company' publisher = 'The Washington Post Company'
category = 'news, politics, USA' category = 'news, politics, USA'
oldest_article = 1.2 oldest_article = 1.2
@ -27,7 +34,7 @@ class TheWashingtonPost(BasicNewsRecipe):
language = 'en_US' language = 'en_US'
remove_empty_feeds = True remove_empty_feeds = True
ignore_duplicate_articles = {'url'} ignore_duplicate_articles = {'url'}
masthead_url = 'https://www.washingtonpost.com/pb/resources/img/twp-masthead-415x57.svg' masthead_url = 'https://upload.wikimedia.org/wikipedia/commons/9/93/The_Logo_of_The_Washington_Post_Newspaper.svg'
publication_type = 'newspaper' publication_type = 'newspaper'
remove_attributes = ['style', 'width', 'height'] remove_attributes = ['style', 'width', 'height']
@ -35,7 +42,7 @@ class TheWashingtonPost(BasicNewsRecipe):
'days': { 'days': {
'short': 'Oldest article to download from this news source. In days ', 'short': 'Oldest article to download from this news source. In days ',
'long': 'For example, 0.5, gives you articles from the past 12 hours', 'long': 'For example, 0.5, gives you articles from the past 12 hours',
'default': str(oldest_article) 'default': str(oldest_article),
} }
} }
@ -51,28 +58,32 @@ class TheWashingtonPost(BasicNewsRecipe):
.time { font-size:small; color: #202020; } .time { font-size:small; color: #202020; }
''' '''
def get_browser(self): def get_browser(self, *args, **kwargs):
return BasicNewsRecipe.get_browser( kwargs['user_agent'] = (
self, verify_ssl_certificates=False, user_agent='Mozilla/5.0 (Windows NT 10.0; rv:128.0) Gecko/20100101 Firefox/128.0') 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'
)
br = BasicNewsRecipe.get_browser(self, *args, **kwargs)
br.addheaders += [
('Referer', 'https://www.google.com/'),
('X-Forwarded-For', '66.249.66.1'),
]
return br
# Official feeds: https://www.washingtonpost.com/discussions/2018/10/12/washington-post-rss-feeds/ # Official feeds: https://www.washingtonpost.com/discussions/2018/10/12/washington-post-rss-feeds/
feeds = [ feeds = [
(u'Politics', u'http://feeds.washingtonpost.com/rss/politics'), ('Politics', 'http://feeds.washingtonpost.com/rss/politics'),
(u'Opinions', u'http://feeds.washingtonpost.com/rss/opinions'), ('Opinions', 'http://feeds.washingtonpost.com/rss/opinions'),
(u'Local', u'http://feeds.washingtonpost.com/rss/local'), ('Local', 'http://feeds.washingtonpost.com/rss/local'),
(u'Sports', u'http://feeds.washingtonpost.com/rss/sports'), ('Sports', 'http://feeds.washingtonpost.com/rss/sports'),
(u'Technology', u'http://feeds.washingtonpost.com/rss/business/technology'), ('Technology', 'http://feeds.washingtonpost.com/rss/business/technology'),
(u'National', u'http://feeds.washingtonpost.com/rss/national'), ('National', 'http://feeds.washingtonpost.com/rss/national'),
(u'World', u'http://feeds.washingtonpost.com/rss/world'), ('World', 'http://feeds.washingtonpost.com/rss/world'),
(u'Business', u'http://feeds.washingtonpost.com/rss/business'), ('Business', 'http://feeds.washingtonpost.com/rss/business'),
(u'Lifestyle', u'http://feeds.washingtonpost.com/rss/lifestyle'), ('Lifestyle', 'http://feeds.washingtonpost.com/rss/lifestyle'),
(u'Entertainment', ('Entertainment', 'http://feeds.washingtonpost.com/rss/entertainment'),
u'http://feeds.washingtonpost.com/rss/entertainment'),
# Undocumented feeds. # Undocumented feeds.
(u'White House', ('White House', 'http://feeds.washingtonpost.com/rss/politics/whitehouse'),
u'http://feeds.washingtonpost.com/rss/politics/whitehouse'), ('Commanders', 'http://feeds.washingtonpost.com/rss/sports/redskins'),
(u'Commanders', u'http://feeds.washingtonpost.com/rss/sports/redskins'),
] ]
def preprocess_raw_html(self, raw, *a): def preprocess_raw_html(self, raw, *a):
@ -87,8 +98,14 @@ class TheWashingtonPost(BasicNewsRecipe):
author = '' author = ''
if 'credits' in data: if 'credits' in data:
author = ('<div><span class="auth">' + 'By ' + ', '.join(x['name'] for x in data['credits']['by']) + author = (
'</span> | <span class="time">' + data['publish_date'][:-14] + '</span></div>') '<div><span class="auth">'
+ 'By '
+ ', '.join(x['name'] for x in data['credits']['by'])
+ '</span> | <span class="time">'
+ data['publish_date'][:-14]
+ '</span></div>'
)
body = '' body = ''
for x in data['content_elements']: for x in data['content_elements']:
@ -100,11 +117,21 @@ class TheWashingtonPost(BasicNewsRecipe):
x['promo_image']['url'], x['description'].get('basic', '') x['promo_image']['url'], x['description'].get('basic', '')
) )
elif x['type'] == 'image': elif x['type'] == 'image':
body += '<p><div class="img"><img src="{}"><div>{}</div></div></p>'.format(x['url'], x['credits_caption_display']) body += (
'<p><div class="img"><img src="{}"><div>{}</div></div></p>'.format(
x['url'], x['credits_caption_display']
)
)
return '<html><body><div>' + title + subhead + author + body + '</div></body></html>' return (
'<html><body><div>' + title + subhead + author + body + '</div></body></html>'
)
def preprocess_html(self, soup): def preprocess_html(self, soup):
for img in soup.findAll('img', attrs={'src':True}): for img in soup.findAll('img', attrs={'src': True}):
img['src'] = 'https://www.washingtonpost.com/wp-apps/imrs.php?src=' + img['src'] + '&w=916' img['src'] = (
'https://www.washingtonpost.com/wp-apps/imrs.php?src='
+ img['src']
+ '&w=916'
)
return soup return soup