home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / Calibre / calibre-0.8.18.msi / file_280 / dnevnik_cro.recipe < prev    next >
Text File  |  2011-09-09  |  3KB  |  76 lines

  1. #!/usr/bin/env  python
  2.  
  3. __license__   = 'GPL v3'
  4. __copyright__ = '2009, Darko Miletic <darko.miletic at gmail.com>'
  5.  
  6. '''
  7. dnevnik.hr
  8. '''
  9.  
  10. import re
  11. from calibre.web.feeds.recipes import BasicNewsRecipe
  12. from calibre.ebooks.BeautifulSoup import Tag
  13.  
  14. class DnevnikCro(BasicNewsRecipe):
  15.     title                 = 'Dnevnik - Hr'
  16.     __author__            = 'Darko Miletic'
  17.     description           = "Vijesti iz Hrvatske"
  18.     publisher             = 'Dnevnik.hr'
  19.     category              = 'news, politics, Croatia'
  20.     oldest_article        = 2
  21.     max_articles_per_feed = 100
  22.     delay                 = 4
  23.     no_stylesheets        = True
  24.     encoding              = 'utf-8'
  25.     use_embedded_content  = False
  26.     language = 'hr'
  27.  
  28.     lang                  = 'hr-HR'
  29.     direction             = 'ltr'
  30.     extra_css = '@font-face {font-family: "serif1";src:url(res:///opt/sony/ebook/FONT/tt0011m_.ttf)} body{font-family: serif1, serif} .article_description{font-family: serif1, serif}'
  31.  
  32.     conversion_options = {
  33.                           'comment'          : description
  34.                         , 'tags'             : category
  35.                         , 'publisher'        : publisher
  36.                         , 'language'         : lang
  37.                         , 'pretty_print'     : True
  38.                         }
  39.  
  40.     preprocess_regexps = [(re.compile(u'\u0110'), lambda match: u'\u00D0')]
  41.  
  42.     keep_only_tags     = [dict(name='div', attrs={'id':'article'})]
  43.  
  44.     remove_tags = [
  45.                     dict(name=['object','link','embed'])
  46.                    ,dict(name='div', attrs={'class':'menu'})
  47.                    ,dict(name='div', attrs={'id':'video'})
  48.                   ]
  49.  
  50.     remove_tags_after  = dict(name='div', attrs={'id':'content'})
  51.  
  52.     feeds = [(u'Vijesti', u'http://rss.dnevnik.hr/index.rss')]
  53.  
  54.     def preprocess_html(self, soup):
  55.         soup.html['lang'] = self.lang
  56.         soup.html['dir' ] = self.direction
  57.  
  58.         attribs = [  'style','font','valign'
  59.                     ,'colspan','width','height'
  60.                     ,'rowspan','summary','align'
  61.                     ,'cellspacing','cellpadding'
  62.                     ,'frames','rules','border'
  63.                   ]
  64.         for item in soup.body.findAll(name=['table','td','tr','th','caption','thead','tfoot','tbody','colgroup','col']):
  65.             item.name = 'div'
  66.             for attrib in attribs:
  67.                 if item.has_key(attrib):
  68.                    del item[attrib]
  69.  
  70.         mlang = Tag(soup,'meta',[("http-equiv","Content-Language"),("content",self.lang)])
  71.         mcharset = Tag(soup,'meta',[("http-equiv","Content-Type"),("content","text/html; charset=UTF-8")])
  72.         soup.head.insert(0,mlang)
  73.         soup.head.insert(1,mcharset)
  74.         return self.adeify_images(soup)
  75.  
  76.