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

  1. __license__   = 'GPL v3'
  2. __copyright__ = '2010, Hiroshi Miura <miurahr@linux.com>'
  3. '''
  4. paperli
  5. '''
  6.  
  7. from calibre.web.feeds.news import BasicNewsRecipe
  8. from calibre import strftime
  9.  
  10. class paperli_topics(BasicNewsRecipe):
  11.     # Customize this recipe and change paperli_tag and title below to
  12.     # download news on your favorite tag
  13.     paperli_tag = 'climate'
  14.     title          = u'The #climate Daily - paperli'
  15. #-------------------------------------------------------------
  16.     __author__     = 'Hiroshi Miura'
  17.     oldest_article = 7
  18.     max_articles_per_feed = 100
  19.     description    = 'paper.li page about '+ paperli_tag
  20.     publisher      = 'paper.li'
  21.     category       = 'paper.li'
  22.     language       = 'en'
  23.     encoding       = 'utf-8'
  24.     remove_javascript = True
  25.     masthead_title = u'The '+ paperli_tag +' Daily'
  26.     timefmt        = '[%y/%m/%d]'
  27.     base_url     = 'http://paper.li'
  28.     index          = base_url+'/tag/'+paperli_tag
  29.  
  30.  
  31.     def parse_index(self):
  32.         # get topics
  33.         topics = []
  34.         soup   = self.index_to_soup(self.index)
  35.         topics_lists = soup.find('div',attrs={'class':'paper-nav-bottom'})
  36.         for item in topics_lists.findAll('li', attrs={'class':""}):
  37.             itema = item.find('a',href=True)
  38.             topics.append({'title': itema.string, 'url': itema['href']})
  39.  
  40.         #get feeds
  41.         feeds = []
  42.         for topic in topics:
  43.             newsarticles = []
  44.             soup   = self.index_to_soup(''.join([self.base_url, topic['url'] ]))
  45.             topstories = soup.findAll('div',attrs={'class':'yui-u'})
  46.             for itt in topstories:
  47.                 itema = itt.find('a',href=True,attrs={'class':'ts'})
  48.                 if itema is not None:
  49.                     itemd = itt.find('div',text=True, attrs={'class':'text'})
  50.                     newsarticles.append({
  51.                                       'title'      :itema.string
  52.                                      ,'date'     :strftime(self.timefmt)
  53.                                      ,'url'        :itema['href']
  54.                                      ,'description':itemd.string
  55.                                     })
  56.             feeds.append((topic['title'], newsarticles))
  57.         return feeds
  58.  
  59.