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

  1. # -*- coding: utf-8 -*-
  2.  
  3. import re
  4. from calibre.web.feeds.recipes import BasicNewsRecipe
  5. from calibre.web.feeds import Feed
  6.  
  7. class Menorca(BasicNewsRecipe):
  8.  
  9.     title       = 'Menorca'
  10.     publisher   = 'Editorial Menorca S.A. '
  11.     __author__  = 'M. Sintes'
  12.     description = u'Peri\xf3dico con informaci\xf3n de Menorca, Espa\xf1a'
  13.     category    = 'news, politics, economy, culture, Menorca, Spain '
  14.     language    = 'es'
  15.     enconding   = 'cp1252'
  16.  
  17.     no_stylesheets = True
  18.     oldest_article = 5
  19.     max_articles_per_feed = 25
  20.  
  21.  
  22.     feeds = [   (u'Principal',u'http://www.menorca.info/rss'),
  23.                 (u'Opini\xf3n',u'http://www.menorca.info/rss?seccion=opinion'),
  24.                 (u'Menorca',u'http://www.menorca.info/rss?seccion=menorca'),
  25.                 (u'Alaior',u'http://www.menorca.info/rss?seccion=pueblos/alaior'),
  26.                 (u'Ciutadella', u'http://www.menorca.info/rss?seccion=pueblos/ciutadella'),
  27.                 (u'Es Castell', u'http://www.menorca.info/rss?seccion=pueblos/escastell'),
  28.                 (u'Es Mercadal', u'http://www.menorca.info/rss?seccion=pueblos/esmercadal'),
  29.                 (u'Es Migjorn', u'http://www.menorca.info/rss?seccion=pueblos/esmigjorn'),
  30.                 (u'Ferreries', u'http://www.menorca.info/rss?seccion=pueblos/ferreries'),
  31.                 (u'Fornells', u'http://www.menorca.info/rss?seccion=pueblos/fornells'),
  32.                 (u'Llucma\xe7anes', u'http://www.menorca.info/rss?seccion=pueblos/llucmaanes'),
  33.                 (u'Ma\xf3', u'http://www.menorca.info/rss?seccion=pueblos/mao'),
  34.                 (u'Sant Climent', u'http://www.menorca.info/rss?seccion=pueblos/santcliment'),
  35.                 (u'Sant Llu\xeds', u'http://www.menorca.info/rss?seccion=pueblos/santlluis'),
  36.                 (u'Deportes',u'http://www.menorca.info/rss?seccion=deportes'),
  37.                 (u'Balears', u'http://www.menorca.info/rss?seccion=balears')]
  38.  
  39.     #Seccions amb link rss erroni. Es recupera directament de la pagina web
  40.     seccions_web = [(u'Mundo',u'http://www.menorca.info/actualidad/mundo'),
  41.                 (u'Econom\xeda',u'http://www.menorca.info/actualidad/economia'),
  42.                 (u'Espa\xf1a',u'http://www.menorca.info/actualidad/espana')]
  43.  
  44.     remove_tags_before = dict(name='div', attrs={'class':'bloqueTitulosNoticia'})
  45.     remove_tags_after = dict(name='div', attrs={'class':'compartir'})
  46.     remove_tags = [dict(id = 'utilidades'),
  47.                 dict(name='div', attrs={'class': 'totalComentarios'}),
  48.                 dict(name='div', attrs={'class': 'compartir'}),
  49.                 dict(name='div', attrs={'class': re.compile("img_noticia*")})
  50.                 ]
  51.  
  52.     def print_version(self, url):
  53.         url_imprimir = url + '?d=print'
  54.         return url.replace(url, url_imprimir)
  55.  
  56.     def feed_to_index_append(self, feedObject, masterFeed):
  57.  
  58.         # Loop thru the feed object and build the correct type of article list
  59.         for feed in feedObject:
  60.             newArticles = []
  61.             for article in feed.articles:
  62.                 newArt = {
  63.                                   'title' : article.title,
  64.                                       'url'   : article.url,
  65.                                               'date'  : article.date,
  66.                                       'description' : article.text_summary
  67.                     }
  68.  
  69.                 newArticles.append(newArt)
  70.  
  71.             # append the newly-built list object to the index object                     # passed in as masterFeed.
  72.             masterFeed.append((feed.title,newArticles))
  73.  
  74.  
  75.     def parse_index(self):
  76.  
  77.         rssFeeds = Feed()
  78.         rssFeeds = BasicNewsRecipe.parse_feeds(self)
  79.  
  80.         articles = []
  81.         feeds = []
  82.  
  83.         self.feed_to_index_append(rssFeeds,feeds)
  84.  
  85.  
  86.  
  87.         for (nom_seccio, url_seccio) in self.seccions_web:
  88.  
  89.  
  90.             articles = []
  91.  
  92.             soup = self.index_to_soup(url_seccio)
  93.             for article in soup.findAll('div', attrs={'class':re.compile("articulo noticia|cajaNoticiaPortada")}):
  94.                 h = article.find(['h2','h3'])
  95.                 titol = self.tag_to_string(h)
  96.                 a = article.find('a', href=True)
  97.                 url = 'http://www.menorca.info' +  a['href']
  98.  
  99.                 desc = None
  100.                 autor = ''
  101.                 dt = ''
  102.  
  103.                 soup_art = self.index_to_soup(url)
  104.                 aut = soup_art.find('div', attrs={'class':'autor'})
  105.                 tx = self.tag_to_string(aut)
  106.                 ls = re.split('[,;]',tx)
  107.  
  108.                 t = len(ls)
  109.                 if t >= 1:
  110.                     autor = ls[0]
  111.  
  112.                     if t > 1:
  113.                         d = ls[t-1]
  114.  
  115.                         if len(d) >= 10:
  116.                             lt = len(d) - 10
  117.                             dt = d[lt:]
  118.  
  119.  
  120.  
  121.                 self.log('\tTrobat article: ', titol, 'a', url, 'Seccio: ', nom_seccio, 'Autor: ',  autor, 'Data: ', dt)
  122.  
  123.                 articles.append({'title': titol, 'url': url, 'description': desc, 'date':dt, 'author': autor})
  124.  
  125.  
  126.  
  127.  
  128.  
  129.             if articles:
  130.                 feeds.append((nom_seccio, articles))
  131.  
  132.  
  133.  
  134.  
  135.         return feeds
  136.  
  137.  
  138.  
  139.