home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_4082 < prev    next >
Encoding:
Text File  |  2009-10-14  |  1.6 KB  |  58 lines

  1. #!/usr/bin/env  python
  2. __license__   = 'GPL v3'
  3. __copyright__ = '2009, Matthew Briggs <hal.sulphur@gmail.com>'
  4. __docformat__ = 'restructuredtext en'
  5.  
  6. '''
  7. theage.com.au
  8. '''
  9. from calibre import strftime
  10. from calibre.web.feeds.news import BasicNewsRecipe
  11. from calibre.ebooks.BeautifulSoup import BeautifulSoup
  12.  
  13.  
  14. class TheAge(BasicNewsRecipe):
  15.  
  16.     title = 'The Age'
  17.     description = 'Business News, World News and Breaking News in Melbourne, Australia'
  18.     __author__ = 'Matthew Briggs'
  19.     language = 'en_AU'
  20.  
  21.  
  22.     def get_browser(self):
  23.         br = BasicNewsRecipe.get_browser()
  24.         br.set_handle_refresh(False)
  25.         return br
  26.  
  27.     def parse_index(self):
  28.  
  29.         soup = BeautifulSoup(self.browser.open('http://www.theage.com.au/text/').read())
  30.  
  31.         feeds, articles = [], []
  32.         feed = None
  33.  
  34.  
  35.         for tag in soup.findAll(['h3', 'a']):
  36.             if tag.name == 'h3':
  37.                 if articles:
  38.                     feeds.append((feed, articles))
  39.                     articles = []
  40.                 feed = self.tag_to_string(tag)
  41.             elif feed is not None and tag.has_key('href') and tag['href'].strip():
  42.                 url = tag['href'].strip()
  43.                 if url.startswith('/'):
  44.                     url   = 'http://www.theage.com.au' + url
  45.                 title = self.tag_to_string(tag)
  46.                 articles.append({
  47.                                  'title': title,
  48.                                  'url'  : url,
  49.                                  'date' : strftime('%a, %d %b'),
  50.                                  'description' : '',
  51.                                  'content'     : '',
  52.                                  })
  53.  
  54.         return feeds
  55.  
  56.  
  57.  
  58.