~ubuntu-branches/debian/wheezy/calibre/wheezy

« back to all changes in this revision

Viewing changes to recipes/techcrunch.recipe

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-10-04 10:29:28 UTC
  • mfrom: (29.3.5 sid)
  • Revision ID: james.westby@ubuntu.com-20111004102928-lbwg8cyjscq1tiz7
Tags: 0.8.21+dfsg-1
* New upstream release. (Closes: #642517)
* debian/control: Revert accidental X-Ubuntu-Original-Maintainer change.
  (Closes: #644029)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
__license__   = 'GPL v3'
 
2
__copyright__ = '2011, Darko Miletic <darko.miletic at gmail.com>'
 
3
'''
 
4
techcrunch.com
 
5
'''
 
6
 
 
7
from calibre.web.feeds.news import BasicNewsRecipe
 
8
 
 
9
class TechCrunch(BasicNewsRecipe):
 
10
    title                 = 'TechCrunch'
 
11
    __author__            = 'Darko Miletic'
 
12
    description           = 'IT News'
 
13
    publisher             = 'AOL Inc.'
 
14
    category              = 'news, IT'
 
15
    oldest_article        = 2
 
16
    max_articles_per_feed = 200
 
17
    no_stylesheets        = True
 
18
    encoding              = 'utf8'
 
19
    use_embedded_content  = False
 
20
    language              = 'en'
 
21
    remove_empty_feeds    = True
 
22
    publication_type      = 'newsportal'
 
23
    masthead_url          = 'http://s2.wp.com/wp-content/themes/vip/tctechcrunch2/images/site-logo.png'
 
24
    extra_css             = """
 
25
                               body{font-family: Helvetica,Arial,sans-serif }
 
26
                               img{margin-bottom: 0.4em; display:block}
 
27
                            """
 
28
 
 
29
    conversion_options = {
 
30
                          'comment'   : description
 
31
                        , 'tags'      : category
 
32
                        , 'publisher' : publisher
 
33
                        , 'language'  : language
 
34
                        }
 
35
 
 
36
    remove_tags = [dict(name=['meta','link'])]
 
37
    remove_attributes=['lang']
 
38
    keep_only_tags=[
 
39
                      dict(name='h1', attrs={'class':'headline'})
 
40
                     ,dict(attrs={'class':['author','post-time','body-copy']})
 
41
                   ]
 
42
 
 
43
    feeds = [(u'News', u'http://feeds.feedburner.com/TechCrunch/')]
 
44
 
 
45
    def preprocess_html(self, soup):
 
46
        for item in soup.findAll(style=True):
 
47
            del item['style']
 
48
        for item in soup.findAll('a'):
 
49
            limg = item.find('img')
 
50
            if item.string is not None:
 
51
               str = item.string
 
52
               item.replaceWith(str)
 
53
            else:
 
54
               if limg:
 
55
                  item.name = 'div'
 
56
                  item.attrs = []
 
57
               else:
 
58
                   str = self.tag_to_string(item)
 
59
                   item.replaceWith(str)
 
60
        for item in soup.findAll('img'):
 
61
            if not item.has_key('alt'):
 
62
               item['alt'] = 'image'            
 
63
        return soup