Debian Codegraph @

recipes/fastcompany.recipe

raw
1 #!/usr/bin/env python
2
3 __license__ = 'GPL v3'
4 __copyright__ = '2008-2009, Darko Miletic <darko.miletic at gmail.com>'
5 '''
6 www.fastcompany.com
7 '''
8
9 from calibre.ebooks.BeautifulSoup import Tag
10 from calibre.web.feeds.news import BasicNewsRecipe
11
12
13 def new_tag(soup, name, attrs=()):
14 impl = getattr(soup, 'new_tag', None)
15 if impl is not None:
16 return impl(name, attrs=dict(attrs))
17 return Tag(soup, name, attrs=attrs or None)
18
19
20 class FastCompany(BasicNewsRecipe):
21 title = 'Fast Company'
22 __author__ = 'Darko Miletic'
23 description = 'Where ideas and people meet'
24 publisher = 'fastcompany.com'
25 category = 'news, technology, gadgets, games'
26 oldest_article = 15
27 max_articles_per_feed = 100
28 no_stylesheets = True
29 use_embedded_content = True
30 simultaneous_downloads = 1
31 encoding = 'utf-8'
32 lang = 'en'
33 language = 'en'
34
35 html2lrf_options = ['--comment', description, '--category', category, '--publisher', publisher]
36
37 html2epub_options = 'publisher="' + publisher + '"\ncomments="' + description + '"\ntags="' + category + '"'
38
39 remove_tags = [dict(name=['embed', 'object']), dict(name='div', attrs={'class': 'feedflare'})]
40
41 feeds = [('All News', 'http://feeds.feedburner.com/fastcompany/headlines')]
42
43 def get_article_url(self, article):
44 return article.get('guid', None)
45
46 def preprocess_html(self, soup):
47 soup.html['xml:lang'] = self.lang
48 soup.html['lang'] = self.lang
49 mlang = new_tag(soup, 'meta', [('http-equiv', 'Content-Language'), ('content', self.lang)])
50 mcharset = new_tag(soup, 'meta', [('http-equiv', 'Content-Type'), ('content', 'text/html; charset=UTF-8')])
51 soup.head.insert(0, mlang)
52 soup.head.insert(1, mcharset)
53 for item in soup.findAll('a'):
54 sp = item['href'].find('http://feedads.g.doubleclick.net/')
55 if sp != -1:
56 item.extract()
57 return self.adeify_images(soup)