Debian Codegraph @

recipes/birmingham_evening_mail.recipe

raw
1 import re
2
3 from calibre import browser
4 from calibre.web.feeds.news import BasicNewsRecipe
5
6
7 class AdvancedUserRecipe1306097511(BasicNewsRecipe):
8 title = 'Birmingham Evening Mail'
9 description = 'News for Birmingham UK'
10 # timefmt = ''
11 __author__ = 'Dave Asbury'
12 # 1/5/14
13 masthead_url = 'http://images.icnetwork.co.uk/upl/icbirmingham/apr2004/6/5/0007417F-982A-107F-969980BFB6FA0000.jpg'
14 oldest_article = 2
15 max_articles_per_feed = 10
16 # linearize_tables = True
17 remove_empty_feeds = True
18 remove_javascript = True
19 no_stylesheets = True
20 remove_attributes = ['style']
21 # auto_cleanup = True
22 language = 'en_GB'
23 compress_news_images = True
24 compress_news_images_max_size = 30
25 ignore_duplicate_articles = {'title', 'url'}
26
27 remove_tags = [
28 dict(attrs={'class': 'gallery-data'}),
29 dict(attrs={'class': 'ir btn-fullscreen'}),
30 dict(attrs={'class': 'tools clearfix'}),
31 dict(attrs={'class': 'shareButtons'}),
32 ]
33 keep_only_tags = [
34 dict(name='h1'),
35 dict(attrs={'class': 'lead-text'}),
36 # dict(attrs={'class' : 'styleGroup article-header'}),
37 # dict(attrs={'class' : 'body '}),
38 dict(attrs={'class': 'tmCol article'}),
39 ]
40
41 feeds = [
42 ('Local News', 'http://www.birminghammail.co.uk/news/local-news/rss.xml'),
43 ('UK News', 'http://www.birminghammail.co.uk/news/uk-news/rss.xml'),
44 ('Sport', 'http://www.birminghammail.co.uk/sport/rss.xml'),
45 ('Whats On', 'http://www.birminghammail.co.uk/whats-on/rss.xml'),
46 ('Lifestyle', 'http://www.birminghammail.co.uk/lifestyle/rss.xml'),
47 ]
48 extra_css = '''
49 h1{font-weight:bold;}
50 h2{font-weight:normal;font-size:75%;}
51 figure {font-size:50%;}
52 #body{font-size:14px;}
53 #.photo-caption {display: block;margin-left: auto;margin-right: auto;width:100%;font-size:40%;}
54 #.publish-info {font-size:50%;}
55 img {display: block;margin-left: auto;margin-right: auto;width:100%;font-size:50%;}
56 '''
57
58 def get_cover_url(self):
59 soup = self.index_to_soup('http://www.birminghammail.co.uk')
60 cov = soup.find(attrs={'src': re.compile(r'http://images.icnetwork.co.uk/upl/birm')})
61 cov = str(cov)
62 cov2 = re.findall(r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', cov)
63
64 cov = str(cov2)
65 cov = cov[2 : len(cov) - 2]
66
67 cover_url = cov
68 br = browser()
69 br.set_handle_redirect(False)
70 try:
71 br.open_novisit(cov)
72 cover_url = cov
73 except Exception:
74 cover_url = 'http://s.birminghammail.co.uk/skins/birminghammail/gfx/follow-media.jpg'
75
76 return cover_url