Debian Codegraph @

recipes/daily_mirror.recipe

raw
1 import re
2
3 from calibre import browser
4 from calibre.web.feeds.news import BasicNewsRecipe
5
6
7 class AdvancedUserRecipe1306061239(BasicNewsRecipe):
8 title = 'The Daily Mirror'
9 description = 'News as provided by The Daily Mirror -UK'
10
11 __author__ = 'Dave Asbury'
12 # last updated 1/5/14
13 language = 'en_GB'
14 # cover_url = 'http://yookeo.com/screens/m/i/mirror.co.uk.jpg'
15
16 masthead_url = 'http://www.nmauk.co.uk/nma/images/daily_mirror.gif'
17
18 compress_news_images = True
19 compress_news_images_max_size = 15
20 oldest_article = 1.5
21 max_articles_per_feed = 10
22 remove_empty_feeds = True
23 remove_javascript = True
24 no_stylesheets = True
25 ignore_duplicate_articles = {'title'}
26
27 keep_only_tags = [
28 dict(name='h1'),
29 dict(name='div', attrs={'class': 'lead-text'}),
30 dict(name='figure', attrs={'class': 'inline-image clearfix '}),
31 dict(name='div', attrs={'class': 'styleGroup clearfix'}),
32 dict(name='div', attrs={'class': 'widget relatedContents pictures widget-editable viziwyg-section-70 inpage-widget-2230659'}),
33 dict(name='div', attrs={'class': 'body '}),
34 ]
35
36 remove_tags = [
37 dict(attrs={'class': ['article sa-teaser type-opinion', 'image-gallery', 'gallery-caption']}),
38 dict(attrs={'class': 'comment'}),
39 dict(name='title'),
40 dict(name='ul'),
41 dict(name='ul', attrs={'class': 'clearfix breadcrumbs '}),
42 dict(name='ul', attrs={'id': 'login-201109171215'}),
43 dict(name='div', attrs={'class': ['inline-ad span-16 last', 'caption']}),
44 ]
45
46 preprocess_regexps = [
47 (re.compile(r'- mirror.co.uk', re.IGNORECASE | re.DOTALL), lambda match: ''),
48 (re.compile(r'<span class="image-credit">Getty</span>', re.IGNORECASE | re.DOTALL), lambda match: ''),
49 ]
50
51 feeds = [
52 ('UK News', 'http://www.mirror.co.uk/news/uk-news/rss.xml'),
53 ('world News', 'http://www.mirror.co.uk/news/world-news/rss.xml'),
54 ('Sports', 'http://www.mirror.co.uk/sport/rss.xml'),
55 ('3AM', 'http://www.mirror.co.uk/3am/rss.xml'),
56 ('Lifestyle', 'http://www.mirror.co.uk/lifestyle/rss.xml'),
57 # example of commented out feed not needed
58 # (u'Travel','http://www.mirror.co.uk/advice/travel/rss.xml'),
59 ]
60 extra_css = '''
61 h1{font-family:Arial,Helvetica,sans-serif; font-weight:bold;font-size:large;}
62 h2{font-family:Arial,Helvetica,sans-serif; font-weight:normal;font-size:small;}
63 p{font-family:Arial,Helvetica,sans-serif;font-size:small;}
64 body{font-family:Helvetica,Arial,sans-serif;font-size:small;}
65 '''
66
67 def get_cover_url(self):
68 soup = self.index_to_soup('http://www.politicshome.com/uk/latest_frontpage.html')
69 # look for the block containing the mirror button and url
70 cov = soup.find(attrs={'style': 'background-image: url(http://www.politicshome.com/images/sources/source_frontpage_button_92.gif);'})
71 cov2 = str(cov)
72 cov2 = 'http://www.politicshome.com' + cov2[9:-142]
73 # cov2 now contains url of the page containing pic
74 soup = self.index_to_soup(cov2)
75 cov = soup.find(attrs={'id': 'large'})
76 cov = str(cov)
77 cov2 = re.findall(r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', cov)
78 cov2 = str(cov2)
79 cov2 = cov2[2 : len(cov2) - 2]
80 # cov2 now is pic url, now go back to original function
81 br = browser()
82 br.set_handle_redirect(False)
83 try:
84 br.open_novisit(cov2)
85 cover_url = cov2
86 except Exception:
87 cover_url = 'http://profile.ak.fbcdn.net/hprofile-ak-snc4/373019_6149699161_1710984811_n.jpg'
88
89 return cover_url