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

  1. import re
  2. from calibre.web.feeds.recipes import BasicNewsRecipe
  3.  
  4.  
  5. class Caijing(BasicNewsRecipe):
  6.  
  7.     title       = 'Caijing Magazine'
  8.     __author__  = 'Eric Chen'
  9.  
  10.     description = '''Bi-weekly Finance and Economics Review. Founded in 1998, the fortnightly CAIJING
  11.                  Magazine has firmly established itself as a news authority and leading voice for
  12.                  business and financial issues in China.
  13.                  CAIJING Magazine closely tracks the most important aspects of China's economic reforms,
  14.                  developments and policy changes, as well as major events in the capital markets. It also
  15.                  offers a broad international perspective through first-hand reporting on international
  16.                  political and economic issues.
  17.                  CAIJING Magazine is China's most widely read business and finance magazine, with a
  18.                  circulation of 225,000 per issue. It boasts top-level readers from government, business
  19.                  and academic circles. '''
  20.     language = 'zh'
  21.     category = 'news, China'
  22.     encoding = 'UTF-8'
  23.     timefmt = ' [%a, %d %b, %Y]'
  24.     needs_subscription = True
  25.  
  26.     remove_tags = [dict(attrs={'class':['topad', 'nav', 'searchbox', 'connav',
  27.         'mbx', 'bianji', 'bianji bj', 'lnewlist', 'rdtj', 'loadComment',
  28.         'conr', 'bottom', 'bottomcopyr', 'emaildy', 'rcom', 'allcontent']}),
  29.                 dict(name=['script', 'noscript', 'style'])]
  30.     no_stylesheets = True
  31.     remove_javascript = True
  32.     current_issue_url = ""
  33.     current_issue_cover = ""
  34.  
  35.  
  36.     def get_browser(self):
  37.         br = BasicNewsRecipe.get_browser()
  38.         if self.username is not None and self.password is not None:
  39.             br.open('http://service.caijing.com.cn/usermanage/login')
  40.             br.select_form(name='mainLoginForm')
  41.             br['username'] = self.username
  42.             br['password'] = self.password
  43.             br.submit()
  44.         return br
  45.  
  46.     def parse_index(self):
  47.         articles = []
  48.         soup0 = self.index_to_soup('http://magazine.caijing.com.cn/2011/cjindex2011/')
  49.         div = soup0.find('div', attrs={'class':'fmcon'})
  50.         link = div.find('a', href=True)
  51.         current_issue_url = link['href']
  52.  
  53.         soup = self.index_to_soup(current_issue_url)
  54.  
  55.         for div_cover in soup.findAll('img', {'src' : re.compile('.')}):
  56.             if re.search('\d{4}-\d{2}-\d{2}', div_cover['src']):
  57.                 self.current_issue_cover = div_cover['src']
  58.  
  59.         feeds = []
  60.         for section in soup.findAll('div', attrs={'class':'cebd'}):
  61.             section_title = self.tag_to_string(section.find('div', attrs={'class':'ceti'}))
  62.             articles = []
  63.             for post in section.findAll('a', href=True):
  64.                 if re.search('\d{4}-\d{2}-\d{2}', post['href']):
  65.                         date = re.search('\d{4}-\d{2}-\d{2}', post['href']).group(0)
  66.                 id = re.search('\d{9}', post['href']).group(0)
  67.                 url = re.sub(r'\d.*', 'templates/inc/chargecontent2.jsp?id=', post['href'])
  68.                 url = url + id + '&time=' + date + '&cl=106&page=all'
  69.  
  70.                 title = self.tag_to_string(post)
  71.                 articles.append({'title':title, 'url':url, 'date':date})
  72.  
  73.             if articles:
  74.                 feeds.append((section_title, articles))
  75.         return feeds
  76.  
  77.     def get_cover_url(self):
  78.         return self.current_issue_cover
  79.  
  80.