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

  1. #!/usr/bin/env  python
  2.  
  3. __license__   = 'GPL v3'
  4. __copyright__ = '2010, Derek Liang <Derek.liang.ca @@@at@@@ gmail.com>'
  5. '''
  6. cnd.org
  7. '''
  8. import re
  9.  
  10. from calibre.web.feeds.news import BasicNewsRecipe
  11.  
  12. class TheCND(BasicNewsRecipe):
  13.  
  14.     title      = 'CND'
  15.     __author__ = 'Derek Liang'
  16.     description = ''
  17.     INDEX = 'http://cnd.org'
  18.     language = 'zh'
  19.     conversion_options = {'linearize_tables':True}
  20.  
  21.     remove_tags_before = dict(name='div', id='articleHead')
  22.     remove_tags_after  = dict(id='copyright')
  23.     remove_tags        = [dict(name='table', attrs={'align':'right'}), dict(name='img', attrs={'src':'http://my.cnd.org/images/logo.gif'}), dict(name='hr', attrs={}), dict(name='small', attrs={})]
  24.     no_stylesheets     = True
  25.  
  26.     preprocess_regexps = [(re.compile(r'<!--.*?-->', re.DOTALL), lambda m: '')]
  27.  
  28.     def print_version(self, url):
  29.         if url.find('news/article.php') >= 0:
  30.             return re.sub("^[^=]*", "http://my.cnd.org/modules/news/print.php?storyid", url)
  31.         else:
  32.             return re.sub("^[^=]*", "http://my.cnd.org/modules/wfsection/print.php?articleid", url)
  33.  
  34.     def parse_index(self):
  35.         soup = self.index_to_soup(self.INDEX)
  36.  
  37.         feeds = []
  38.         articles = {}
  39.  
  40.         for a in soup.findAll('a', attrs={'target':'_cnd'}):
  41.             url = a['href']
  42.             if url.find('article.php') < 0 :
  43.                 continue
  44.             if url.startswith('/'):
  45.                 url = 'http://cnd.org'+url
  46.             title = self.tag_to_string(a)
  47.             self.log('\tFound article: ', title, 'at', url)
  48.             date = a.nextSibling
  49.             if (date is not None) and len(date)>2:
  50.                 if not articles.has_key(date):
  51.                     articles[date] = []
  52.                 articles[date].append({'title':title, 'url':url, 'description': '', 'date':''})
  53.                 self.log('\t\tAppend to : ', date)
  54.  
  55.         self.log('log articles', articles)
  56.         mostCurrent = sorted(articles).pop()
  57.         self.title = 'CND ' + mostCurrent
  58.  
  59.         feeds.append((self.title, articles[mostCurrent]))
  60.  
  61.         return feeds
  62.  
  63.     def populate_article_metadata(self, article, soup, first):
  64.         header = soup.find('h3')
  65.         self.log('header: ' + self.tag_to_string(header))
  66.         pass
  67.  
  68.