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

  1. from calibre.web.feeds.news import BasicNewsRecipe
  2.  
  3. class ElUniversalImpresaRecipe(BasicNewsRecipe):
  4.     __license__  = 'GPL v3'
  5.     __author__ = 'kwetal'
  6.     language = 'es_MX'
  7.     version = 1
  8.  
  9.     title = u'El Universal (Edici\u00F3n Impresa)'
  10.     publisher = u'El Universal'
  11.     category = u'News, Mexico'
  12.     description = u'News from Mexico'
  13.  
  14.     remove_empty_feeds = True
  15.     remove_javascript = True
  16.  
  17.     INDEX = 'http://www.eluniversal.com.mx'
  18.  
  19.     extra_css = '''
  20.                 body{font-family:verdana,arial,helvetica,geneva,sans-serif;}
  21.                 '''
  22.  
  23.     conversion_options = {'comments': description, 'tags': category, 'language': 'en',
  24.                           'publisher': publisher, 'linearize_tables': True}
  25.  
  26.     def parse_index(self):
  27.         soup = self.index_to_soup('http://www.eluniversal.com.mx/edicion_impresa.html')
  28.         index = []
  29.  
  30.         table = soup.find('table', attrs = {'width': '500'})
  31.         articles = []
  32.         for td in table.findAll(lambda tag: tag.name == 'td' and tag.has_key('class') and tag['class'] == 'arnegro12'):
  33.             a = td.a
  34.             a.extract()
  35.             title = self.tag_to_string(a)
  36.             url = self.INDEX + a['href']
  37.             description = self.tag_to_string(td)
  38.             articles.append({'title': title, 'date': None, 'url': url, 'description' : description})
  39.  
  40.         index.append(('Primera Plana', articles))
  41.  
  42.         for td in table.findAll(lambda tag: tag.name == 'td' and len(tag.attrs) == 0):
  43.             articles = []
  44.             feedTitle = None
  45.             for a in td.findAll('a'):
  46.                 if not feedTitle:
  47.                     feedTitle = self.tag_to_string(a)
  48.                     continue
  49.  
  50.                 title = self.tag_to_string(a)
  51.  
  52.                 url = self.INDEX + a['href']
  53.                 articles.append({'title': title, 'date': None, 'url': url, 'description': ''})
  54.  
  55.             index.append((feedTitle, articles))
  56.  
  57.         return index
  58.  
  59.     def print_version(self, url):
  60.         if url.find('wcarton') >= 0:
  61.             return None
  62.  
  63.         main, sep, id = url.rpartition('/')
  64.  
  65.         return main + '/vi_' + id
  66.  
  67.     def preprocess_html(self, soup):
  68.         table = soup.find('table')
  69.         table.extract()
  70.  
  71.         for p in soup.findAll('p'):
  72.             if self.tag_to_string(p).strip() == '':
  73.                 p.extract()
  74.  
  75.         tag = soup.find('font', attrs = {'color': '#0F046A'})
  76.         if tag:
  77.             for attr in ['color', 'face', 'helvetica,', 'sans-serif', 'size']:
  78.                 if tag.has_key(attr):
  79.                     del tag[attr]
  80.             tag.name = 'h1'
  81.  
  82.         return soup
  83.