| 1 |
#!/usr/bin/env python |
| 2 |
# vim:fileencoding=utf-8 |
| 3 |
from calibre.web.feeds.news import BasicNewsRecipe, classes |
| 4 |
|
| 5 |
|
| 6 |
class NewYorkPost(BasicNewsRecipe): |
| 7 |
title = 'New York Post' |
| 8 |
__author__ = 'unkn0wn' |
| 9 |
description = 'Daily newspaper' |
| 10 |
publisher = 'NYP Holdings, Inc.' |
| 11 |
category = 'news, politics, USA' |
| 12 |
oldest_article = 1 |
| 13 |
no_stylesheets = True |
| 14 |
encoding = 'utf-8' |
| 15 |
use_embedded_content = False |
| 16 |
language = 'en_US' |
| 17 |
remove_attributes = ['style', 'height', 'width'] |
| 18 |
masthead_url = 'https://static.storied.co/gQlwL7PA4X5XM6b8/projects/JYX3m27B8zP9BW4D/assets/images/81e851fd6c5d8fc747c41064d8aee316.png' |
| 19 |
extra_css = '.byline, .date, .article-header__top, .calibre-nuked-tag-figcaption { font-size: small; }' |
| 20 |
|
| 21 |
def get_cover_url(self): |
| 22 |
soup = self.index_to_soup('https://www.frontpages.com/us-newspapers/') |
| 23 |
for img in soup.findAll('img', src=True): |
| 24 |
if 'new-york-post' in img['src']: |
| 25 |
return 'https://www.frontpages.com' + img['src'] |
| 26 |
|
| 27 |
recipe_specific_options = { |
| 28 |
'days': { |
| 29 |
'short': 'Oldest article to download from this news source. In days ', |
| 30 |
'long': 'For example, 0.5, gives you articles from the past 12 hours', |
| 31 |
'default': str(oldest_article), |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
def __init__(self, *args, **kwargs): |
| 36 |
BasicNewsRecipe.__init__(self, *args, **kwargs) |
| 37 |
d = self.recipe_specific_options.get('days') |
| 38 |
if d and isinstance(d, str): |
| 39 |
self.oldest_article = float(d) |
| 40 |
|
| 41 |
ignore_duplicate_articles = {'title', 'url'} |
| 42 |
|
| 43 |
keep_only_tags = [ |
| 44 |
classes('article-header single__content'), |
| 45 |
] |
| 46 |
|
| 47 |
remove_tags = [ |
| 48 |
dict(attrs={'id': ['connatix-outstream-video']}), |
| 49 |
classes('article-header__social-icons wpcom-liveblog-container nyp-s2n-wrapper nyp-slideshow-modal-image__icon inline-module inline-module__inner'), |
| 50 |
dict(name=['svg', 'link', 'meta', 'aside']), |
| 51 |
] |
| 52 |
|
| 53 |
# https://nypost.com/rssfeeds/ |
| 54 |
feeds = [ |
| 55 |
('US-News', 'https://nypost.com/us-news/feed/'), |
| 56 |
('Metro', 'https://nypost.com/metro/feed/'), |
| 57 |
('Politics', 'https://nypost.com/politics/feed/'), |
| 58 |
('World News', 'https://nypost.com/world-news/feed/'), |
| 59 |
('Sports', 'https://nypost.com/sports/feed/'), |
| 60 |
('Business', 'https://nypost.com/business/feed/'), |
| 61 |
('Opinion', 'https://nypost.com/opinion/feed/'), |
| 62 |
('Entertainment', 'https://nypost.com/entertainment/feed/'), |
| 63 |
('Fashion & Beauty', 'https://nypost.com/fashion-and-beauty/feed/'), |
| 64 |
('Lifestyle', 'https://nypost.com/lifestyle/feed/'), |
| 65 |
('Tech', 'https://nypost.com/tech/feed/'), |
| 66 |
('Media', 'https://nypost.com/media/feed/'), |
| 67 |
('Real Estate', 'https://nypost.com/real-estate/feed/'), |
| 68 |
('Page Six', 'https://pagesix.com/feed/'), |
| 69 |
('Others', 'https://nypost.com/feed/'), |
| 70 |
] |
| 71 |
|
| 72 |
def preprocess_html(self, soup): |
| 73 |
for img in soup.findAll('img', attrs={'src': True}): |
| 74 |
img['src'] = img['src'].split('?')[0] + '?w=600' |
| 75 |
return soup |