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

  1. from calibre.web.feeds.news import re
  2. from calibre.web.feeds.recipes import BasicNewsRecipe
  3. from BeautifulSoup import Tag
  4.  
  5. class RevistaMuyInteresante(BasicNewsRecipe):
  6.  
  7.     title       = 'Revista Muy Interesante'
  8.     __author__  = 'Jefferson Frantz'
  9.     description = 'Revista de divulgacion'
  10.     timefmt = ' [%d %b, %Y]'
  11.     language = 'es'
  12.  
  13.     no_stylesheets = True
  14.     remove_javascript = True
  15.  
  16.     conversion_options = {'linearize_tables': True}
  17.  
  18.     extra_css              = ' .txt_articulo{ font-family: sans-serif; font-size: medium; text-align: justify } .contentheading{font-family: serif; font-size: large; font-weight: bold; color: #000000; text-align: center}'
  19.  
  20.  
  21.     def preprocess_html(self, soup):
  22.             for item in soup.findAll(style=True):
  23.                del item['style']
  24.  
  25.             for img_tag in soup.findAll('img'):
  26.                 imagen = img_tag
  27.                 new_tag = Tag(soup,'p')
  28.                 img_tag.replaceWith(new_tag)
  29.                 div = soup.find(attrs={'class':'article_category'})
  30.                 div.insert(0,imagen)
  31.                 break
  32.             return soup
  33.  
  34.  
  35.     preprocess_regexps = [
  36.         (re.compile(r'<td class="contentheading" width="100%">.*?</td>', re.DOTALL|re.IGNORECASE), lambda match: '<td class="contentheading">' + match.group().replace('<td class="contentheading" width="100%">','').strip().replace('</td>','').strip() + '</td>'),
  37.  
  38.     ]
  39.  
  40.  
  41.     keep_only_tags = [dict(name='div', attrs={'class':['article']}),dict(name='td', attrs={'class':['txt_articulo']})]
  42.  
  43.     remove_tags        = [
  44.                              dict(name=['object','link','script','ul','iframe','ins'])
  45.                             ,dict(name='div', attrs={'id':['comment']})
  46.                             ,dict(name='td', attrs={'class':['buttonheading']})
  47.                             ,dict(name='div', attrs={'class':['tags_articles','bajo_title']})
  48.                             ,dict(name='table', attrs={'class':['pagenav']})
  49.                             ,dict(name='form', attrs={'class':['voteform']})
  50.                          ]
  51.  
  52.     remove_tags_after = dict(name='div', attrs={'class':'tags_articles'})
  53.  
  54.  
  55.     #TO GET ARTICLES IN SECTION
  56.     def nz_parse_section(self, url):
  57.             soup = self.index_to_soup(url)
  58.             div = soup.find(attrs={'class':'contenido'})
  59.             current_articles = []
  60.             for x in div.findAllNext(attrs={'class':['headline']}):
  61.                     a = x.find('a', href=True)
  62.                     if a is None:
  63.                         continue
  64.                     title = self.tag_to_string(a)
  65.                     url = a.get('href', False)
  66.                     if not url or not title:
  67.                         continue
  68.                     if url.startswith('/'):
  69.                          url = 'http://www.muyinteresante.es'+url
  70. #                    self.log('\t\tFound article:', title)
  71. #                    self.log('\t\t\t', url)
  72.                     current_articles.append({'title': title, 'url':url,
  73.                         'description':'', 'date':''})
  74.  
  75.             return current_articles
  76.  
  77.  
  78.     # To GET SECTIONS
  79.     def parse_index(self):
  80.             feeds = []
  81.             for title, url in [
  82.                 ('Historia',
  83.                  'http://www.muyinteresante.es/historia-articulos'),
  84.                 ('Ciencia',
  85.                  'http://www.muyinteresante.es/ciencia-articulos'),
  86.                 ('Naturaleza',
  87.                  'http://www.muyinteresante.es/naturaleza-articulos'),
  88.                 ('Tecnolog├¡a',
  89.                  'http://www.muyinteresante.es/tecnologia-articulos'),
  90.                 ('Salud',
  91.                  'http://www.muyinteresante.es/salud-articulos'),
  92.                 ('M├ís Muy',
  93.                  'http://www.muyinteresante.es/muy'),
  94.                 ('Innova - Automoci├│n',
  95.                  'http://www.muyinteresante.es/articulos-innovacion-autos'),
  96.                 ('Innova - Salud',
  97.                  'http://www.muyinteresante.es/articulos-innovacion-salud'),
  98.                 ('Innova - Medio Ambiente',
  99.                  'http://www.muyinteresante.es/articulos-innovacion-medio-ambiente'),
  100.                 ('Innova - Alimentaci├│n',
  101.                  'http://www.muyinteresante.es/articulos-innovacion-alimentacion'),
  102.                 ('Innova - Sociedad',
  103.                  'http://www.muyinteresante.es/articulos-innovacion-sociedad'),
  104.                 ('Innova - Tecnolog├¡a',
  105.                  'http://www.muyinteresante.es/articulos-innovacion-tecnologia'),
  106.                 ('Innova - Ocio',
  107.                  'http://www.muyinteresante.es/articulos-innovacion-ocio'),
  108.              ]:
  109.                articles = self.nz_parse_section(url)
  110.                if articles:
  111.                    feeds.append((title, articles))
  112.             return feeds
  113.  
  114.     def get_cover_url(self):
  115.         index = 'http://www.muyinteresante.es/revista'
  116.         soup = self.index_to_soup(index)
  117.         link_item = soup.find('img',attrs={'class':'img_portada'})
  118.         if link_item:
  119.             cover_url = "http://www.muyinteresante.es"+link_item['src']
  120.         return cover_url
  121.  
  122.  
  123.