| 1 |
#!/usr/bin/env python |
| 2 |
|
| 3 |
from calibre.web.feeds.news import BasicNewsRecipe, classes |
| 4 |
|
| 5 |
|
| 6 |
class StrangeHorizons(BasicNewsRecipe): |
| 7 |
title = 'Strange Horizons' |
| 8 |
description = ( |
| 9 |
'Strange Horizons is a weekly magazine of and about speculative fiction. ' |
| 10 |
'We publish fiction, poetry, reviews, essays, interviews, roundtable ' |
| 11 |
'discussions, and art.' |
| 12 |
) |
| 13 |
__author__ = 'unkn0wn' |
| 14 |
no_stylesheets = True |
| 15 |
use_embedded_content = False |
| 16 |
encoding = 'utf-8' |
| 17 |
language = 'en' |
| 18 |
remove_attributes = ['style', 'height', 'width'] |
| 19 |
masthead_url = 'http://strangehorizons.com/wordpress/wp-content/themes/strangehorizons/images/sh-logo.jpg' |
| 20 |
ignore_duplicate_articles = {'url'} |
| 21 |
resolve_internal_links = True |
| 22 |
oldest_article = 7 |
| 23 |
|
| 24 |
extra_css = ''' |
| 25 |
.author-biographies, .content-warning-container-ltr, .category {font-size:small; font-style:italic; font-color:#404040;} |
| 26 |
.byline {font-size:small; font-color:#202020;} |
| 27 |
img {display:block; margin:0 auto;} |
| 28 |
''' |
| 29 |
|
| 30 |
recipe_specific_options = { |
| 31 |
'days': { |
| 32 |
'short': 'Oldest article to download from this news source. In days ', |
| 33 |
'long': 'For example, 0.5, gives you articles from the past 12 hours', |
| 34 |
'default': str(oldest_article), |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
def __init__(self, *args, **kwargs): |
| 39 |
BasicNewsRecipe.__init__(self, *args, **kwargs) |
| 40 |
d = self.recipe_specific_options.get('days') |
| 41 |
if d and isinstance(d, str): |
| 42 |
self.oldest_article = float(d) |
| 43 |
|
| 44 |
keep_only_tags = remove_tags_after = [dict(name='div', attrs={'class': 'post'})] |
| 45 |
|
| 46 |
remove_tags = [dict(name='button'), classes('font-size sharedaddy comments-form-row')] |
| 47 |
|
| 48 |
def preprocess_html(self, soup): |
| 49 |
h1 = soup.find(attrs={'class': 'title'}) |
| 50 |
if h1 and h1.find('a'): |
| 51 |
h1.a.name = 'h1' |
| 52 |
return soup |
| 53 |
|
| 54 |
feeds = [('Articles', 'http://strangehorizons.com/wordpress/feed/')] |