mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Update nypost.recipe
This commit is contained in:
parent
4c753a5904
commit
1840b7469a
@ -1,35 +1,35 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=utf-8
|
||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||
|
||||
from calibre.web.feeds.news import BasicNewsRecipe
|
||||
|
||||
|
||||
def classes(classes):
|
||||
q = frozenset(classes.split(' '))
|
||||
return dict(
|
||||
attrs={'class': lambda x: x and frozenset(x.split()).intersection(q)})
|
||||
from calibre.web.feeds.news import BasicNewsRecipe, classes
|
||||
|
||||
|
||||
class NewYorkPost(BasicNewsRecipe):
|
||||
title = 'New York Post'
|
||||
__author__ = 'Darko Miletic'
|
||||
__author__ = 'unkn0wn'
|
||||
description = 'Daily newspaper'
|
||||
publisher = 'NYP Holdings, Inc.'
|
||||
category = 'news, politics, USA'
|
||||
oldest_article = 2
|
||||
max_articles_per_feed = 20
|
||||
oldest_article = 1
|
||||
no_stylesheets = True
|
||||
encoding = 'utf8'
|
||||
encoding = 'utf-8'
|
||||
use_embedded_content = False
|
||||
language = 'en_US'
|
||||
extra_css = ' body{font-family: Arial,Helvetica,sans-serif } img{margin-bottom: 0.4em} '
|
||||
remove_attributes = ['style', 'height', 'width']
|
||||
masthead_url = 'https://static.storied.co/gQlwL7PA4X5XM6b8/projects/JYX3m27B8zP9BW4D/assets/images/81e851fd6c5d8fc747c41064d8aee316.png'
|
||||
extra_css = '.byline, .date, .article-header__top, .calibre-nuked-tag-figcaption { font-size: small; }'
|
||||
|
||||
def get_cover_url(self):
|
||||
soup = self.index_to_soup('https://www.frontpages.com/new-york-post/')
|
||||
return (
|
||||
'https://www.frontpages.com'
|
||||
+ soup.find('img', attrs={'id': 'giornale-img'})['src']
|
||||
)
|
||||
|
||||
recipe_specific_options = {
|
||||
'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',
|
||||
'default': str(oldest_article)
|
||||
'default': str(oldest_article),
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,55 +39,41 @@ class NewYorkPost(BasicNewsRecipe):
|
||||
if d and isinstance(d, str):
|
||||
self.oldest_article = float(d)
|
||||
|
||||
conversion_options = {
|
||||
'comment': description, 'tags': category, 'publisher': publisher, 'language': language
|
||||
}
|
||||
ignore_duplicate_articles = {'title', 'url'}
|
||||
|
||||
keep_only_tags = [
|
||||
dict(itemprop=['headline', 'articleBody']),
|
||||
dict(name='h1'),
|
||||
classes(
|
||||
'byline byline-date source article-info entry-content entry-content-read-more featured-image'
|
||||
' headline--single date meta meta--byline Date published'
|
||||
),
|
||||
classes('article-header single__content'),
|
||||
]
|
||||
|
||||
remove_tags = [
|
||||
dict(itemprop=['sharebar-trigger-desktop', ]),
|
||||
dict(attrs={'id': ['connatix-outstream-video']}),
|
||||
classes(
|
||||
'floating-share floating-share-wrap sharedaddy sd-sharing-enabled tag-list module-wrapper'
|
||||
' inline-module--author inline-module--columnist inline-module--primary-tag'
|
||||
' author-flyout modal__email-author button gowatchit-inline updated select-share__title'
|
||||
'article-header__social-icons wpcom-liveblog-container nyp-s2n-wrapper '
|
||||
'nyp-slideshow-modal-image__icon inline-module inline-module__inner'
|
||||
),
|
||||
dict(name=['link', 'meta']),
|
||||
dict(name=['svg', 'link', 'meta', 'aside']),
|
||||
]
|
||||
|
||||
# https://nypost.com/rssfeeds/
|
||||
feeds = [
|
||||
('All Stories','https://nypost.com/feed'),
|
||||
('News','https://nypost.com/news/feed'),
|
||||
('Metro', 'http://nypost.com/metro/feed/'),
|
||||
('Business', 'http://nypost.com/business/feed/'),
|
||||
('Opinion', 'http://nypost.com/opinion/feed/'),
|
||||
('Technology', 'http://nypost.com/tech/feed/'),
|
||||
('Media', 'http://nypost.com/media/feed/'),
|
||||
('Entertainment', 'http://nypost.com/entertainment/feed/'),
|
||||
('Living', 'http://nypost.com/living/feed/'),
|
||||
('Page 6', 'http://pagesix.com/feed/'),
|
||||
('US-News', 'https://nypost.com/us-news/feed/'),
|
||||
('Metro', 'https://nypost.com/metro/feed/'),
|
||||
('Politics', 'https://nypost.com/politics/feed/'),
|
||||
('World News', 'https://nypost.com/world-news/feed/'),
|
||||
('Sports', 'https://nypost.com/sports/feed/'),
|
||||
('Business', 'https://nypost.com/business/feed/'),
|
||||
('Opinion', 'https://nypost.com/opinion/feed/'),
|
||||
('Entertainment', 'https://nypost.com/entertainment/feed/'),
|
||||
('Fashion & Beauty', 'https://nypost.com/fashion-and-beauty/feed/'),
|
||||
('Lifestyle', 'https://nypost.com/lifestyle/feed/'),
|
||||
('Tech', 'https://nypost.com/tech/feed/'),
|
||||
('Media', 'https://nypost.com/media/feed/'),
|
||||
('Real Estate', 'https://nypost.com/real-estate/feed/'),
|
||||
('Page Six', 'https://pagesix.com/feed/'),
|
||||
('Others', 'https://nypost.com/feed/'),
|
||||
]
|
||||
|
||||
def print_version(self, url):
|
||||
return url.replace('nypost.com/p/', 'nypost.com/f/print/')
|
||||
|
||||
def preprocess_html(self, soup):
|
||||
for img in soup.findAll('img', attrs={'data-srcset': True}):
|
||||
img['src'] = img['data-srcset'].split()[0]
|
||||
for pic in soup.findAll('picture'):
|
||||
source = pic.find('source', srcset=True)
|
||||
if source is not None:
|
||||
img = pic.find('img')
|
||||
if img is not None:
|
||||
img['src'] = source['srcset'].split()[0]
|
||||
for source in pic.findAll('source'):
|
||||
source.extract()
|
||||
for img in soup.findAll('img', attrs={'src': True}):
|
||||
img['src'] = img['src'].split('?')[0] + '?w=600'
|
||||
return soup
|
||||
|
Loading…
x
Reference in New Issue
Block a user