| 1 |
__license__ = 'GPL v3' |
| 2 |
__copyright__ = '2014, Darko Miletic <darko.miletic at gmail.com>' |
| 3 |
''' |
| 4 |
www.wired.com |
| 5 |
''' |
| 6 |
|
| 7 |
from calibre import browser |
| 8 |
from calibre.web.feeds.news import BasicNewsRecipe |
| 9 |
|
| 10 |
|
| 11 |
def classes(classes): |
| 12 |
q = frozenset(classes.split(' ')) |
| 13 |
return dict(attrs={'class': lambda x: x and frozenset(x.split()).intersection(q)}) |
| 14 |
|
| 15 |
|
| 16 |
class WiredDailyNews(BasicNewsRecipe): |
| 17 |
title = 'Wired Magazine, Monthly Edition' |
| 18 |
__author__ = 'Darko Miletic, update by Howard Cornett, Zach Lapidus, Michael Marotta' |
| 19 |
description = ( |
| 20 |
'Wired is a full-color monthly American magazine, ' |
| 21 |
'published in both print and online editions, that ' |
| 22 |
'reports on how emerging technologies affect culture, ' |
| 23 |
'the economy and politics. ' |
| 24 |
'Monthly edition, best run at the start of every month.' |
| 25 |
) |
| 26 |
publisher = 'Conde Nast' |
| 27 |
category = 'news, IT, computers, technology' |
| 28 |
oldest_article = 45 |
| 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 |
extra_css = ''' |
| 37 |
.entry-header{ |
| 38 |
text-transform: uppercase; |
| 39 |
vertical-align: baseline; |
| 40 |
display: inline; |
| 41 |
} |
| 42 |
ul li{display: inline} |
| 43 |
''' |
| 44 |
|
| 45 |
keep_only_tags = [ |
| 46 |
classes('content-header lead-asset article__body'), |
| 47 |
] |
| 48 |
remove_tags = [ |
| 49 |
classes( |
| 50 |
'related-cne-video-component tags-component callout--related-list iframe-embed podcast_storyboard' |
| 51 |
' inset-left-component ad consumer-marketing-component social-icons' |
| 52 |
), |
| 53 |
dict(name=['meta', 'link']), |
| 54 |
dict(id=['sharing', 'social', 'article-tags', 'sidebar']), |
| 55 |
] |
| 56 |
remove_attributes = ['srcset'] |
| 57 |
|
| 58 |
def parse_wired_index_page(self, currenturl, seen): |
| 59 |
self.log('Parsing index page', currenturl) |
| 60 |
soup = self.index_to_soup(currenturl) |
| 61 |
baseurl = 'https://www.wired.com' |
| 62 |
for a in soup.find('div', {'class': 'multi-packages'}).findAll('a', href=True): |
| 63 |
url = a['href'] |
| 64 |
if url.startswith('/story') and url.endswith('/'): |
| 65 |
title = self.tag_to_string(a.parent.find('h3')) |
| 66 |
dateloc = a.parent.find('time') |
| 67 |
date = self.tag_to_string(dateloc) |
| 68 |
if title.lower() != 'read more' and title and url not in seen: |
| 69 |
seen.add(url) |
| 70 |
self.log('Found article:', title) |
| 71 |
yield { |
| 72 |
'title': title, |
| 73 |
'date': date, |
| 74 |
'url': baseurl + url, |
| 75 |
} |
| 76 |
|
| 77 |
def parse_index(self): |
| 78 |
baseurl = 'https://www.wired.com/magazine/?page={}/' |
| 79 |
pagenum = 1 |
| 80 |
articles = [] |
| 81 |
seen = set() |
| 82 |
for pagenum in range(1, 4): |
| 83 |
articles.extend(self.parse_wired_index_page(baseurl.format(pagenum), seen)) |
| 84 |
|
| 85 |
return [('Magazine Articles', articles)] |
| 86 |
|
| 87 |
# Wired changes the content it delivers based on cookies, so the |
| 88 |
# following ensures that we send no cookies |
| 89 |
def get_browser(self, *args, **kwargs): |
| 90 |
return self |
| 91 |
|
| 92 |
def clone_browser(self, *args, **kwargs): |
| 93 |
return self.get_browser() |
| 94 |
|
| 95 |
def open_novisit(self, *args, **kwargs): |
| 96 |
br = browser() |
| 97 |
return br.open_novisit(*args, **kwargs) |
| 98 |
|
| 99 |
open = open_novisit |