| 1 |
#!/usr/bin/env python |
| 2 |
# vim:fileencoding=utf-8 |
| 3 |
__license__ = 'GPL v3' |
| 4 |
__copyright__ = '2014, Darko Miletic <darko.miletic at gmail.com>' |
| 5 |
''' |
| 6 |
www.wired.com |
| 7 |
''' |
| 8 |
|
| 9 |
from calibre import browser |
| 10 |
from calibre.web.feeds.news import BasicNewsRecipe |
| 11 |
|
| 12 |
|
| 13 |
def classes(classes): |
| 14 |
q = frozenset(classes.split(' ')) |
| 15 |
return dict(attrs={'class': lambda x: x and frozenset(x.split()).intersection(q)}) |
| 16 |
|
| 17 |
|
| 18 |
class WiredDailyNews(BasicNewsRecipe): |
| 19 |
title = 'Wired Daily Edition' |
| 20 |
__author__ = 'Darko Miletic, PatStapleton(update 2020-05-24)' |
| 21 |
description = ( |
| 22 |
'Wired is a full-color monthly American magazine, published in both print' |
| 23 |
' and online editions, that reports on how emerging technologies affect culture,' |
| 24 |
' the economy and politics.' |
| 25 |
) |
| 26 |
publisher = 'Conde Nast' |
| 27 |
category = 'news, IT, computers, technology' |
| 28 |
oldest_article = 2 |
| 29 |
max_articles_per_feed = 200 |
| 30 |
no_stylesheets = True |
| 31 |
encoding = 'utf-8' |
| 32 |
use_embedded_content = False |
| 33 |
language = 'en' |
| 34 |
ignore_duplicate_articles = {'url'} |
| 35 |
remove_empty_feeds = True |
| 36 |
publication_type = 'newsportal' |
| 37 |
extra_css = ''' |
| 38 |
.entry-header{ |
| 39 |
text-transform: uppercase; |
| 40 |
vertical-align: baseline; |
| 41 |
display: inline; |
| 42 |
} |
| 43 |
ul li{display: inline} |
| 44 |
''' |
| 45 |
|
| 46 |
recipe_specific_options = { |
| 47 |
'days': { |
| 48 |
'short': 'Oldest article to download from this news source. In days ', |
| 49 |
'long': 'For example, 0.5, gives you articles from the past 12 hours', |
| 50 |
'default': str(oldest_article), |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
def __init__(self, *args, **kwargs): |
| 55 |
BasicNewsRecipe.__init__(self, *args, **kwargs) |
| 56 |
d = self.recipe_specific_options.get('days') |
| 57 |
if d and isinstance(d, str): |
| 58 |
self.oldest_article = float(d) |
| 59 |
|
| 60 |
keep_only_tags = [ |
| 61 |
classes('content-header lead-asset article__body'), |
| 62 |
] |
| 63 |
remove_tags = [ |
| 64 |
classes( |
| 65 |
'related-cne-video-component tags-component callout--related-list iframe-embed podcast_storyboard' |
| 66 |
' inset-left-component ad consumer-marketing-component social-icons' |
| 67 |
), |
| 68 |
dict(name=['meta', 'link', 'aside']), |
| 69 |
dict(id=['sharing', 'social', 'article-tags', 'sidebar']), |
| 70 |
] |
| 71 |
remove_attributes = ['srcset'] |
| 72 |
handle_gzip = True |
| 73 |
|
| 74 |
feeds = [ |
| 75 |
('Top Stories', 'https://www.wired.com/feed/rss'), |
| 76 |
('Business', 'https://www.wired.com/feed/category/business/latest/rss'), |
| 77 |
('Culture', 'https://www.wired.com/feed/category/culture/latest/rss'), |
| 78 |
('Gear', 'https://www.wired.com/feed/category/gear/latest/rss'), |
| 79 |
('Ideas', 'https://www.wired.com/feed/category/ideas/latest/rss'), |
| 80 |
('Science', 'https://www.wired.com/feed/category/science/latest/rss'), |
| 81 |
('Security', 'https://www.wired.com/feed/category/security/latest/rss'), |
| 82 |
('Transportation', 'https://www.wired.com/feed/category/transportation/latest/rss'), |
| 83 |
('Backchannel', 'https://www.wired.com/feed/category/backchannel/latest/rss'), |
| 84 |
('WIRED Guides', 'https://www.wired.com/feed/tag/wired-guide/latest/rss'), |
| 85 |
# (u'Photo', u'https://www.wired.com/feed/category/photo/latest/rss'), |
| 86 |
] |
| 87 |
|
| 88 |
def get_article_url(self, article): |
| 89 |
return article.get('link', None) |
| 90 |
|
| 91 |
# Wired changes the content it delivers based on cookies, so the |
| 92 |
# following ensures that we send no cookies |
| 93 |
def get_browser(self, *args, **kwargs): |
| 94 |
return self |
| 95 |
|
| 96 |
def clone_browser(self, *args, **kwargs): |
| 97 |
return self.get_browser() |
| 98 |
|
| 99 |
def open_novisit(self, *args, **kwargs): |
| 100 |
br = browser() |
| 101 |
return br.open_novisit(*args, **kwargs) |
| 102 |
|
| 103 |
open = open_novisit |