Debian Codegraph @

recipes/uncrate.recipe

raw
1 #!/usr/bin/env python
2
3 __license__ = 'GPL v3'
4 __copyright__ = '2009, Darko Miletic <darko.miletic at gmail.com>'
5 '''
6 www.uncrate.com
7 '''
8
9 from calibre.ebooks.BeautifulSoup import Tag
10 from calibre.web.feeds.recipes 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 Uncrate(BasicNewsRecipe):
21 title = 'Uncrate'
22 __author__ = 'Darko Miletic'
23 description = 'Uncrate is a web magazine for guys who love stuff. Our team digs up the best gadgets, clothes, cars, DVDs and more. New items are posted daily. Enjoy responsively.' # noqa: E501
24 oldest_article = 7
25 max_articles_per_feed = 100
26 no_stylesheets = True
27 use_embedded_content = False
28 encoding = 'utf-8'
29 publisher = 'Zombie corp.'
30 category = 'news, gadgets, clothes, cars, DVDs'
31 lang = 'en'
32 language = 'en'
33
34 html2lrf_options = ['--comment', description, '--category', category, '--publisher', publisher]
35
36 html2epub_options = 'publisher="' + publisher + '"\ncomments="' + description + '"\ntags="' + category + '"'
37
38 keep_only_tags = [dict(name='div', attrs={'class': 'lefttext'})]
39 remove_tags_after = dict(name='div', attrs={'class': 'serif'})
40 remove_tags = [dict(name=['object', 'link', 'script', 'iframe', 'form'])]
41
42 extra_css = '''
43 .serif{font-family:Georgia,Rockwell,'Times New Roman',Times,serif; font-weight:normal; font-size: x-small; }
44 h1{ font-family:Verdana,Arial,Helvetica,sans-serif;font-size:x-large; font-weight:bold;}
45 .byline{ font-family:Verdana,Arial,Helvetica,sans-serif;font-size: x-small; color:#FF4000;}
46 .posted{ font-family:Verdana,Arial,Helvetica,sans-serif;font-size: x-small;}
47 .answer{ font-family:Verdana,Arial,Helvetica,sans-serif;font-size: x-small;}
48 a{color:#FF4000;}
49 '''
50
51 feeds = [('Articles', 'http://feeds.feedburner.com/uncrate')]
52
53 def preprocess_html(self, soup):
54 mlang = new_tag(soup, 'meta', [('http-equiv', 'Content-Language'), ('content', self.lang)])
55 mcharset = new_tag(soup, 'meta', [('http-equiv', 'Content-Type'), ('content', 'text/html; charset=utf-8')])
56 soup.head.insert(0, mlang)
57 soup.head.insert(1, mcharset)
58 for item in soup.findAll(style=True):
59 del item['style']
60 return self.adeify_images(soup)