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
|
#!/usr/bin/env python
|
||||||
# vim:fileencoding=utf-8
|
# vim:fileencoding=utf-8
|
||||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
from calibre.web.feeds.news import BasicNewsRecipe, classes
|
||||||
|
|
||||||
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)})
|
|
||||||
|
|
||||||
|
|
||||||
class NewYorkPost(BasicNewsRecipe):
|
class NewYorkPost(BasicNewsRecipe):
|
||||||
title = 'New York Post'
|
title = 'New York Post'
|
||||||
__author__ = 'Darko Miletic'
|
__author__ = 'unkn0wn'
|
||||||
description = 'Daily newspaper'
|
description = 'Daily newspaper'
|
||||||
publisher = 'NYP Holdings, Inc.'
|
publisher = 'NYP Holdings, Inc.'
|
||||||
category = 'news, politics, USA'
|
category = 'news, politics, USA'
|
||||||
oldest_article = 2
|
oldest_article = 1
|
||||||
max_articles_per_feed = 20
|
|
||||||
no_stylesheets = True
|
no_stylesheets = True
|
||||||
encoding = 'utf8'
|
encoding = 'utf-8'
|
||||||
use_embedded_content = False
|
use_embedded_content = False
|
||||||
language = 'en_US'
|
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 = {
|
recipe_specific_options = {
|
||||||
'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),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,55 +39,41 @@ class NewYorkPost(BasicNewsRecipe):
|
|||||||
if d and isinstance(d, str):
|
if d and isinstance(d, str):
|
||||||
self.oldest_article = float(d)
|
self.oldest_article = float(d)
|
||||||
|
|
||||||
conversion_options = {
|
|
||||||
'comment': description, 'tags': category, 'publisher': publisher, 'language': language
|
|
||||||
}
|
|
||||||
ignore_duplicate_articles = {'title', 'url'}
|
ignore_duplicate_articles = {'title', 'url'}
|
||||||
|
|
||||||
keep_only_tags = [
|
keep_only_tags = [
|
||||||
dict(itemprop=['headline', 'articleBody']),
|
classes('article-header single__content'),
|
||||||
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'
|
|
||||||
),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
remove_tags = [
|
remove_tags = [
|
||||||
dict(itemprop=['sharebar-trigger-desktop', ]),
|
dict(attrs={'id': ['connatix-outstream-video']}),
|
||||||
classes(
|
classes(
|
||||||
'floating-share floating-share-wrap sharedaddy sd-sharing-enabled tag-list module-wrapper'
|
'article-header__social-icons wpcom-liveblog-container nyp-s2n-wrapper '
|
||||||
' inline-module--author inline-module--columnist inline-module--primary-tag'
|
'nyp-slideshow-modal-image__icon inline-module inline-module__inner'
|
||||||
' author-flyout modal__email-author button gowatchit-inline updated select-share__title'
|
|
||||||
),
|
),
|
||||||
dict(name=['link', 'meta']),
|
dict(name=['svg', 'link', 'meta', 'aside']),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# https://nypost.com/rssfeeds/
|
||||||
feeds = [
|
feeds = [
|
||||||
('All Stories','https://nypost.com/feed'),
|
('US-News', 'https://nypost.com/us-news/feed/'),
|
||||||
('News','https://nypost.com/news/feed'),
|
('Metro', 'https://nypost.com/metro/feed/'),
|
||||||
('Metro', 'http://nypost.com/metro/feed/'),
|
('Politics', 'https://nypost.com/politics/feed/'),
|
||||||
('Business', 'http://nypost.com/business/feed/'),
|
('World News', 'https://nypost.com/world-news/feed/'),
|
||||||
('Opinion', 'http://nypost.com/opinion/feed/'),
|
('Sports', 'https://nypost.com/sports/feed/'),
|
||||||
('Technology', 'http://nypost.com/tech/feed/'),
|
('Business', 'https://nypost.com/business/feed/'),
|
||||||
('Media', 'http://nypost.com/media/feed/'),
|
('Opinion', 'https://nypost.com/opinion/feed/'),
|
||||||
('Entertainment', 'http://nypost.com/entertainment/feed/'),
|
('Entertainment', 'https://nypost.com/entertainment/feed/'),
|
||||||
('Living', 'http://nypost.com/living/feed/'),
|
('Fashion & Beauty', 'https://nypost.com/fashion-and-beauty/feed/'),
|
||||||
('Page 6', 'http://pagesix.com/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):
|
def preprocess_html(self, soup):
|
||||||
for img in soup.findAll('img', attrs={'data-srcset': True}):
|
for img in soup.findAll('img', attrs={'src': True}):
|
||||||
img['src'] = img['data-srcset'].split()[0]
|
img['src'] = img['src'].split('?')[0] + '?w=600'
|
||||||
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()
|
|
||||||
return soup
|
return soup
|
||||||
|
Loading…
x
Reference in New Issue
Block a user