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

  1. #!/usr/bin/env  python
  2.  
  3. __license__   = 'GPL v3'
  4. __copyright__ = '2008-2009, Darko Miletic <darko.miletic at gmail.com>'
  5. '''
  6. jutarnji.hr
  7. '''
  8.  
  9. import re
  10. from calibre.web.feeds.news import BasicNewsRecipe
  11. from calibre.ebooks.BeautifulSoup import Tag
  12.  
  13. class Jutarnji(BasicNewsRecipe):
  14.     title                 = 'Jutarnji'
  15.     __author__            = 'Darko Miletic'
  16.     description           = 'Hrvatski portal'
  17.     publisher             = 'Jutarnji.hr'
  18.     category              = 'news, politics, Croatia'
  19.     oldest_article        = 2
  20.     max_articles_per_feed = 100
  21.     delay                 = 1
  22.     language = 'hr'
  23.  
  24.     no_stylesheets        = True
  25.     use_embedded_content  = False
  26.     encoding              = 'cp1250'
  27.     lang                  = 'hr-HR'
  28.     direction             = 'ltr'
  29.     extra_css = '@font-face {font-family: "serif1";src:url(res:///opt/sony/ebook/FONT/tt0011m_.ttf)} @font-face {font-family: "sans1";src:url(res:///opt/sony/ebook/FONT/tt0003m_.ttf)} body{text-align: justify; font-family: serif1, serif} .article_description{font-family: sans1, sans-serif} .vijestnaslov{font-size: x-large; font-weight: bold}'
  30.  
  31.     conversion_options = {
  32.                           'comment'          : description
  33.                         , 'tags'             : category
  34.                         , 'publisher'        : publisher
  35.                         , 'language'         : lang
  36.                         , 'pretty_print'     : True
  37.                         }
  38.  
  39.  
  40.     preprocess_regexps = [(re.compile(u'\u0110'), lambda match: u'\u00D0')]
  41.  
  42.     remove_tags = [
  43.                     dict(name=['embed','hr','link','object'])
  44.                    ,dict(name='a', attrs={'class':'a11'})
  45.                   ]
  46.  
  47.     feeds = [
  48.               (u'Naslovnica'      , u'http://www.jutarnji.hr/rss'           )
  49.              ,(u'Sport'           , u'http://www.jutarnji.hr/sport/rss'     )
  50.              ,(u'Jutarnji2'       , u'http://www.jutarnji.hr/j2/rss'        )
  51.              ,(u'Kultura'         , u'http://www.jutarnji.hr/kultura/rss'   )
  52.              ,(u'Spektakli'       , u'http://www.jutarnji.hr/spektakli/rss' )
  53.              ,(u'Dom i nekretnine', u'http://www.jutarnji.hr/nekretnine/rss')
  54.              ,(u'Uhvati ritam'    , u'http://www.jutarnji.hr/kalendar/rss'  )
  55.             ]
  56.  
  57.     def print_version(self, url):
  58.         main, split, rest = url.partition('.jl')
  59.         rmain, rsplit, rrest = main.rpartition(',')
  60.         return 'http://www.jutarnji.hr/ispis_clanka.jl?artid=' + rrest
  61.  
  62.     def preprocess_html(self, soup):
  63.         soup.html['lang'] = self.lang
  64.         soup.html['dir' ] = self.direction
  65.  
  66.         attribs = [  'style','font','valign'
  67.                     ,'colspan','width','height'
  68.                     ,'rowspan','summary','align'
  69.                     ,'cellspacing','cellpadding'
  70.                     ,'frames','rules','border'
  71.                   ]
  72.         for item in soup.body.findAll(name=['table','td','tr','th','caption','thead','tfoot','tbody','colgroup','col']):
  73.             item.name = 'div'
  74.             for attrib in attribs:
  75.                 if item.has_key(attrib):
  76.                    del item[attrib]
  77.  
  78.         mlang = Tag(soup,'meta',[("http-equiv","Content-Language"),("content",self.lang)])
  79.         mcharset = Tag(soup,'meta',[("http-equiv","Content-Type"),("content","text/html; charset=UTF-8")])
  80.         soup.head.insert(0,mlang)
  81.         soup.head.insert(1,mcharset)
  82.         return self.adeify_images(soup)
  83.  
  84.