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

  1. __license__   = 'GPL v3'
  2. __copyright__ = '2011, Darko Miletic <darko.miletic at gmail.com>'
  3. '''
  4. ambito.com/diario
  5. '''
  6.  
  7. import time
  8. from calibre import strftime
  9. from calibre.web.feeds.news import BasicNewsRecipe
  10.  
  11. class Ambito_Financiero(BasicNewsRecipe):
  12.     title                 = 'Ambito Financiero'
  13.     __author__            = 'Darko Miletic'
  14.     description           = 'Informacion Libre las 24 horas'
  15.     publisher             = 'Editorial Nefir S.A.'
  16.     category              = 'news, politics, economy, Argentina'
  17.     no_stylesheets        = True
  18.     encoding              = 'cp1252'
  19.     masthead_url          = 'http://www.ambito.com/diario/img/logo_af.gif'
  20.     publication_type      = 'newspaper'
  21.     needs_subscription    = 'optional'
  22.     use_embedded_content  = False
  23.     language              = 'es_AR'
  24.     PREFIX                = 'http://www.ambito.com'
  25.     INDEX                 = PREFIX + '/diario/index.asp'
  26.     LOGIN                 = PREFIX + '/diario/login/entrada.asp'
  27.     extra_css             = """
  28.                                 body{font-family: "Trebuchet MS",Verdana,sans-serif}
  29.                                 .volanta{font-size: small}
  30.                                 .t2_portada{font-size: xx-large; font-family: Georgia,serif; color: #026698}
  31.                             """
  32.  
  33.     conversion_options = {
  34.                           'comment'   : description
  35.                         , 'tags'      : category
  36.                         , 'publisher' : publisher
  37.                         , 'language'  : language
  38.                         }
  39.  
  40.     keep_only_tags    = [dict(name='div', attrs={'align':'justify'})]
  41.     remove_tags       = [dict(name=['object','link','embed','iframe','meta','link','table','img'])]
  42.     remove_attributes = ['align']
  43.  
  44.     def get_browser(self):
  45.         br = BasicNewsRecipe.get_browser()
  46.         br.open(self.INDEX)
  47.         if self.username is not None and self.password is not None:
  48.             br.open(self.LOGIN)
  49.             br.select_form(name='frmlogin')
  50.             br['USER_NAME'] = self.username
  51.             br['USER_PASS'] = self.password
  52.             br.submit()
  53.         return br
  54.  
  55.     def print_version(self, url):
  56.         return url.replace('/diario/noticia.asp?','/noticias/imprimir.asp?')
  57.  
  58.     def preprocess_html(self, soup):
  59.         for item in soup.findAll(style=True):
  60.             del item['style']
  61.         for item in soup.findAll('a'):
  62.             str = item.string
  63.             if str is None:
  64.                str = self.tag_to_string(item)
  65.             item.replaceWith(str)
  66.         return soup
  67.  
  68.     def parse_index(self):
  69.         soup = self.index_to_soup(self.INDEX)
  70.         cover_item = soup.find('img',attrs={'class':'fotodespliegue'})
  71.         if cover_item:
  72.            self.cover_url = self.PREFIX + cover_item['src']
  73.         articles = []
  74.         checker  = []
  75.         for feed_link in soup.findAll('a', attrs={'class':['t0_portada','t2_portada','bajada']}):
  76.             url   = self.PREFIX + feed_link['href']
  77.             title = self.tag_to_string(feed_link)
  78.             date  = strftime("%a, %d %b %Y %H:%M:%S +0000",time.gmtime())
  79.             if url not in checker:
  80.                 checker.append(url)
  81.                 articles.append({
  82.                                   'title'      :title
  83.                                  ,'date'       :date
  84.                                  ,'url'        :url
  85.                                  ,'description':u''
  86.                                 })
  87.         return [(self.title, articles)]
  88.