Debian Codegraph @

recipes/open_magazine.recipe

raw
1 #!/usr/bin/env python
2
3 from calibre.web.feeds.news import BasicNewsRecipe, classes
4
5
6 class OpenMagazine(BasicNewsRecipe):
7 title = 'Open Magazine'
8 description = 'The weekly current affairs and features magazine.'
9 language = 'en_IN'
10 __author__ = 'unkn0wn'
11 oldest_article = 7 # days
12 max_articles_per_feed = 50
13 encoding = 'utf-8'
14 use_embedded_content = False
15 no_stylesheets = True
16 remove_attributes = ['style', 'height', 'width']
17 masthead_url = 'https://openthemagazine.com/wp-content/themes/open/images/logo.png'
18 ignore_duplicate_articles = {'url'}
19 extra_css = '[id^="caption-attachment"] {font-size: small;font-style: italic;}'
20 'blockquote{color:#404040;}'
21 '.about-author{font-size:small;}'
22
23 recipe_specific_options = {
24 'days': {
25 'short': 'Oldest article to download from this news source. In days ',
26 'long': 'For example, 0.5, gives you articles from the past 12 hours',
27 'default': str(oldest_article),
28 }
29 }
30
31 def __init__(self, *args, **kwargs):
32 BasicNewsRecipe.__init__(self, *args, **kwargs)
33 d = self.recipe_specific_options.get('days')
34 if d and isinstance(d, str):
35 self.oldest_article = float(d)
36
37 def get_cover_url(self):
38 d = self.recipe_specific_options.get('days')
39 if not (d and isinstance(d, str)):
40 soup = self.index_to_soup('https://openthemagazine.com/')
41 tag = soup.find(attrs={'class': 'magazine-item mr-1'})
42 if tag:
43 self.cover_url = tag.find('img')['src']
44 return getattr(self, 'cover_url', None)
45
46 keep_only_tags = [
47 classes('post-data post-thumb post-meta post-excerp'),
48 ]
49
50 remove_tags = [
51 classes('top-social menu-social post-author blurb-social button-links'),
52 ]
53
54 remove_tags_after = [
55 classes('post-meta post-excerp'),
56 ]
57
58 feeds = [
59 ('Cover Story', 'https://openthemagazine.com/cover-story/feed/'),
60 ('Columns', 'https://openthemagazine.com/columns/feed'),
61 ('Essays', 'https://openthemagazine.com/essays/feed'),
62 ('Features', 'https://openthemagazine.com/features/feed'),
63 ('Books', 'https://openthemagazine.com/lounge/books/feed'),
64 ('Art & Culture', 'https://openthemagazine.com/art-culture/feed'),
65 ('Cinema', 'https://openthemagazine.com/cinema/feed'),
66 ]