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

  1. #!/usr/bin/env  python
  2.  
  3. __license__   = 'GPL v3'
  4. __copyright__ = '2009, Darko Miletic <darko.miletic at gmail.com>'
  5. '''
  6. laprensa.com.ni
  7. '''
  8.  
  9. import datetime
  10. import time
  11. from calibre.web.feeds.news import BasicNewsRecipe
  12.  
  13. class LaPrensa_ni(BasicNewsRecipe):
  14.     title                 = 'La Prensa - Nicaragua'
  15.     __author__            = 'Darko Miletic'
  16.     description           = 'LA PRENSA - EL Diario de los Nicaraguenses'
  17.     publisher             = 'La Prensa'
  18.     category              = 'Nicaragua, nicaragua, la prensa, La Prensa, prensa, Prensa, diario, Diario, periodico, noticias, internacional, economia, dinero, opinion, ultimas noticias, deportes, politica, managua, Managua, ultima hora, daily, newspaper, news, breaking news, urgente, tecnologia, tiempo, weather, buscador, magazine, Magazine, nosotras, Nosotras, journalism, clasificados, avisos, classified, ads, media, publicidad, arroba, arroba de oro'
  19.     oldest_article        = 1
  20.     max_articles_per_feed = 100
  21.     no_stylesheets        = True
  22.     use_embedded_content  = False
  23.     encoding              = 'cp1252'
  24.     remove_javascript     = True
  25.     language = 'es_NI'
  26.  
  27.     months_es             = ['enero','febrero','marzo','abril','mayo','junio','julio','agosto','septiembre','octubre','noviembre','diciembre']
  28.     current_month         = months_es[datetime.date.today().month - 1]
  29.     current_index         = time.strftime("http://www.laprensa.com.ni/archivo/%Y/" + current_month + "/%d/noticias/")
  30.  
  31.     html2lrf_options = [
  32.                           '--comment', description
  33.                         , '--category', category
  34.                         , '--publisher', publisher
  35.                         , '--ignore-tables'
  36.                         ]
  37.  
  38.     html2epub_options = 'publisher="' + publisher + '"\ncomments="' + description + '"\ntags="' + category + '"\nlinearize_tables=True'
  39.  
  40.     feeds = [(u'Portada', current_index + 'portada/')]
  41.  
  42.     def print_version(self, url):
  43.         return url.replace('.shtml','_print.shtml')
  44.  
  45.     def preprocess_html(self, soup):
  46.         del soup.body['onload']
  47.         mtag = '<meta http-equiv="Content-Language" content="es-NI"/>'
  48.         soup.head.insert(0,mtag)
  49.         atag = soup.find('span',attrs={'class':'mas_noticias'})
  50.         if atag:
  51.            atag.extract()
  52.         btag = soup.find('a',attrs={'href':'/archivo'})
  53.         if btag:
  54.            btag.extract()
  55.         for item in soup.findAll(style=True):
  56.             del item['style']
  57.         return soup
  58.  
  59.     def parse_index(self):
  60.         totalfeeds = []
  61.         lfeeds = self.get_feeds()
  62.         for feedobj in lfeeds:
  63.             feedtitle, feedurl = feedobj
  64.             self.report_progress(0, _('Fetching feed')+' %s...'%(feedtitle if feedtitle else feedurl))
  65.             articles = []
  66.             soup = self.index_to_soup(feedurl)
  67.             for item in soup.findAll('a', attrs={'class':['titular','titulonotamed']}):
  68.                 description = ''
  69.                 url         = feedurl + item['href']
  70.                 title       = self.tag_to_string(item)
  71.                 date        = time.strftime(self.timefmt)
  72.                 articles.append({
  73.                                   'title'      :title
  74.                                  ,'date'       :date
  75.                                  ,'url'        :url
  76.                                  ,'description':description
  77.                                 })
  78.             totalfeeds.append((feedtitle, articles))
  79.         return totalfeeds
  80.  
  81.