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

  1.  
  2. __license__   = 'GPL v3'
  3. __copyright__ = '2010, Darko Miletic <darko.miletic at gmail.com>'
  4. '''
  5. bhdani.com
  6. '''
  7.  
  8. import re
  9. from calibre import strftime
  10. from calibre.web.feeds.news import BasicNewsRecipe
  11.  
  12. class BHDani(BasicNewsRecipe):
  13.     title                  = 'Dani'
  14.     __author__             = 'Darko Miletic'
  15.     description            = 'On line izdanje najutjecajnijeg bosanskohercegovackog magazina'
  16.     publisher              = 'd.o.o. CIVITAS'
  17.     category               = 'dani, bh, bhdani, magazin, sarajevo, bosna, novine, mediji, listovi, news, magazines, weekly'
  18.     no_stylesheets         = True
  19.     oldest_article         = 15
  20.     encoding               = 'cp1250'
  21.     needs_subscription     = True
  22.     remove_empty_feeds     = True
  23.     PREFIX                 = 'http://bhdani.com'
  24.     INDEX                  = PREFIX + '/'
  25.     LOGIN                  = PREFIX + '/users/login.asp'
  26.     use_embedded_content   = False
  27.     language               = 'bs'
  28.     publication_type       = 'magazine'
  29.     extra_css              = ' @font-face {font-family: "sans1";src:url(res:///opt/sony/ebook/FONT/tt0003m_.ttf)} body{font-family: Arial, sans1, sans-serif} .article_description{font-family: Arial, sans1, sans-serif} .plv18{font-size: xx-large; font-weight: bold; color: #5261A9} .crn10{font-weight: bold} '
  30.  
  31.     conversion_options = {
  32.                           'comment'          : description
  33.                         , 'tags'             : category
  34.                         , 'publisher'        : publisher
  35.                         , 'language'         : language
  36.                         , 'linearize_tables' : True
  37.                         }
  38.  
  39.     preprocess_regexps = [(re.compile(u'\u0110'), lambda match: u'\u00D0')]
  40.     remove_attributes = ['height','width','align']
  41.  
  42.     def get_browser(self):
  43.         br = BasicNewsRecipe.get_browser()
  44.         if self.username is not None and self.password is not None:
  45.             br.open(self.INDEX)
  46.             br.select_form(name='form')
  47.             br['username'] = self.username
  48.             br['password'] = self.password
  49.             br.submit()
  50.         return br
  51.  
  52.     remove_tags       = [dict(name=['link','embed','object','iframe','form'])]
  53.     remove_tags_before= dict(name='div',attrs={'class':'crn10'})
  54.  
  55.     def get_cover_url(self):
  56.         cover_url = None
  57.         soup = self.index_to_soup(self.INDEX)
  58.         link_item = soup.find('img',attrs={'alt':'Naslovna strana'})
  59.         if link_item:
  60.            cover_url = self.PREFIX + link_item['src'].replace('&slika=slika120&','&slika=slika400&')
  61.         return cover_url
  62.  
  63.     def print_version(self, url):
  64.         return url.replace('/default.asp?','/print.asp?')
  65.  
  66.     def parse_index(self):
  67.         articles = []
  68.         soup = self.index_to_soup(self.PREFIX)
  69.         nrtit = soup.find('font',attrs={'class':'broj'})
  70.         nrtitle = 'Dani'
  71.         if nrtit:
  72.            nrtitle += ' ' + self.tag_to_string(nrtit)
  73.         for item in soup.findAll('a',attrs={'class':['naslov12','menilink2']}):
  74.             url   = self.PREFIX + item['href']
  75.             title = self.tag_to_string(item)
  76.             description = ''
  77.             date = strftime(self.timefmt)
  78.             articles.append({
  79.                               'title'      :title
  80.                              ,'date'       :date
  81.                              ,'url'        :url
  82.                              ,'description':description
  83.                             })
  84.         return [(nrtitle, articles)]
  85.  
  86.