home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_4135 < prev    next >
Encoding:
Text File  |  2009-10-14  |  2.5 KB  |  72 lines

  1. #!/usr/bin/env  python
  2.  
  3. __license__   = 'GPL v3'
  4. __copyright__ = '2009, Darko Miletic <darko.miletic at gmail.com>'
  5. '''
  6. en.wikinews.org
  7. '''
  8.  
  9. from calibre.web.feeds.news import BasicNewsRecipe
  10.  
  11. class WikiNews(BasicNewsRecipe):
  12.     title                 = 'Wikinews'
  13.     __author__            = 'Darko Miletic'
  14.     description           = 'News from wikipedia'
  15.     category              = 'news, world'
  16.     oldest_article        = 7
  17.     max_articles_per_feed = 100
  18.     publisher             = 'Wiki'
  19.     no_stylesheets        = True
  20.     use_embedded_content  = False
  21.     encoding              = 'utf-8'
  22.     remove_javascript     = True
  23.     language = 'en'
  24.  
  25.     
  26.     html2lrf_options = [
  27.                           '--comment', description
  28.                         , '--category', category
  29.                         , '--publisher', publisher
  30.                         ]
  31.     
  32.     html2epub_options = 'publisher="' + publisher + '"\ncomments="' + description + '"\ntags="' + category + '"' 
  33.  
  34.     keep_only_tags = [ 
  35.                         dict(name='h1', attrs={'id':'firstHeading'}) 
  36.                        ,dict(name='div', attrs={'id':'bodyContent'}) 
  37.                      ]
  38.     
  39.     remove_tags = [
  40.                     dict(name='link')
  41.                    ,dict(name='div',attrs={'id':['printfooter','catlinks','footer']})
  42.                    ,dict(name='div',attrs={'class':['thumb left','thumb right']})
  43.                   ]
  44.  
  45.     remove_tags_after = dict(name='h2')
  46.                   
  47.     feeds = [(u'News', u'http://feeds.feedburner.com/WikinewsLatestNews')]
  48.  
  49.     def get_article_url(self, article):
  50.         artl  = article.get('link',  None)
  51.         rest, sep, article_id  = artl.rpartition('/')
  52.         return 'http://en.wikinews.org/wiki/' + article_id
  53.             
  54.     def print_version(self, url):
  55.         rest, sep, article_id  = url.rpartition('/')
  56.         return 'http://en.wikinews.org/w/index.php?title=' + article_id + '&printable=yes'
  57.  
  58.     def preprocess_html(self, soup):
  59.         mtag = '<meta http-equiv="Content-Language" content="en"/><meta http-equiv="Content-Type" content="text/html; charset=utf-8">'
  60.         soup.head.insert(0,mtag)
  61.         btag = soup.find('div',attrs={'id':'bodyContent'})
  62.         for item in btag.findAll('div'):
  63.             item.extract()        
  64.         for item in btag.findAll('h2'):
  65.             item.extract()        
  66.         for item in soup.findAll(style=True):
  67.             del item['style']
  68.         for item in soup.findAll(font=True):
  69.             del item['font']
  70.         return soup
  71.         
  72.