home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_3644 < prev    next >
Encoding:
Text File  |  2010-01-20  |  4.9 KB  |  122 lines

  1. #!/usr/bin/env  python
  2.  
  3. __license__   = 'GPL v3'
  4.  
  5. '''
  6. www.canada.com
  7. '''
  8.  
  9. from calibre.web.feeds.recipes import BasicNewsRecipe
  10.  
  11.  
  12. class CanWestPaper(BasicNewsRecipe):
  13.  
  14.     # un-comment the following three lines for the Calgary Herald
  15.     title = u'Calgary Herald'
  16.     url_prefix = 'http://www.calgaryherald.com'
  17.     description = u'News from Calgary, AB'
  18.  
  19.     # un-comment the following three lines for the Regina Leader-Post
  20.     #title = u'Regina Leader-Post'
  21.     #url_prefix = 'http://www.leaderpost.com'
  22.     #description = u'News from Regina, SK'
  23.  
  24.     # un-comment the following three lines for the Saskatoon Star-Phoenix
  25.     #title = u'Saskatoon Star-Phoenix'
  26.     #url_prefix = 'http://www.thestarphoenix.com'
  27.     #description = u'News from Saskatoon, SK'
  28.  
  29.     # un-comment the following three lines for the Windsor Star
  30.     #title = u'Windsor Star'
  31.     #url_prefix = 'http://www.windsorstar.com'
  32.     #description = u'News from Windsor, ON'
  33.  
  34.     # un-comment the following three lines for the Ottawa Citizen
  35.     #title = u'Ottawa Citizen'
  36.     #url_prefix = 'http://www.ottawacitizen.com'
  37.     #description = u'News from Ottawa, ON'
  38.  
  39.     # un-comment the following three lines for the Montreal Gazette
  40.     #title = u'Montreal Gazette'
  41.     #url_prefix = 'http://www.montrealgazette.com'
  42.     #description = u'News from Montreal, QC'
  43.  
  44.  
  45.     language = 'en_CA'
  46.     __author__ = 'Nick Redding'
  47.     no_stylesheets = True
  48.     timefmt = ' [%b %d]'
  49.     extra_css = '''
  50.                 .timestamp {  font-size:xx-small; display: block; }
  51.                 #storyheader { font-size: medium; }
  52.                 #storyheader h1 { font-size: x-large; }
  53.                 #storyheader h2 { font-size: large;  font-style: italic; }
  54.                 .byline { font-size:xx-small; }
  55.                 #photocaption { font-size: small; font-style: italic }
  56.                 #photocredit { font-size: xx-small; }'''
  57.     keep_only_tags = [dict(name='div', attrs={'id':'storyheader'}),dict(name='div', attrs={'id':'storycontent'})]
  58.     remove_tags = [{'class':'comments'},
  59.                    dict(name='div', attrs={'class':'navbar'}),dict(name='div', attrs={'class':'morelinks'}),
  60.                    dict(name='div', attrs={'class':'viewmore'}),dict(name='li', attrs={'class':'email'}),
  61.                    dict(name='div', attrs={'class':'story_tool_hr'}),dict(name='div', attrs={'class':'clear'}),
  62.                    dict(name='div', attrs={'class':'story_tool'}),dict(name='div', attrs={'class':'copyright'}),
  63.                    dict(name='div', attrs={'class':'rule_grey_solid'}),
  64.                    dict(name='li', attrs={'class':'print'}),dict(name='li', attrs={'class':'share'}),dict(name='ul', attrs={'class':'bullet'})]
  65.  
  66.     def preprocess_html(self,soup):
  67.         #delete iempty id attributes--they screw up the TOC for unknow reasons
  68.         divtags = soup.findAll('div',attrs={'id':''})
  69.         if divtags:
  70.             for div in divtags:
  71.                 del(div['id'])
  72.         return soup
  73.  
  74.  
  75.     def parse_index(self):
  76.         soup = self.index_to_soup(self.url_prefix+'/news/todays-paper/index.html')
  77.  
  78.         articles = {}
  79.         key = 'News'
  80.         ans = ['News']
  81.  
  82.         # Find each instance of class="sectiontitle", class="featurecontent"
  83.         for divtag in soup.findAll('div',attrs={'class' : ["section_title02","featurecontent"]}):
  84.                 #self.log(" div class = %s" % divtag['class'])
  85.                 if divtag['class'].startswith('section_title'):
  86.                     # div contains section title
  87.                     if not divtag.h3:
  88.                         continue
  89.                     key = self.tag_to_string(divtag.h3,False)
  90.                     ans.append(key)
  91.                     self.log("Section name %s" % key)
  92.                     continue
  93.                 # div contains article data
  94.                 h1tag = divtag.find('h1')
  95.                 if not h1tag:
  96.                     continue
  97.                 atag = h1tag.find('a',href=True)
  98.                 if not atag:
  99.                     continue
  100.                 url = self.url_prefix+'/news/todays-paper/'+atag['href']
  101.                 #self.log("Section %s" % key)
  102.                 #self.log("url %s" % url)
  103.                 title = self.tag_to_string(atag,False)
  104.                 #self.log("title %s" % title)
  105.                 pubdate = ''
  106.                 description = ''
  107.                 ptag = divtag.find('p');
  108.                 if ptag:
  109.                     description = self.tag_to_string(ptag,False)
  110.                     #self.log("description %s" % description)
  111.                 author = ''
  112.                 autag = divtag.find('h4')
  113.                 if autag:
  114.                     author = self.tag_to_string(autag,False)
  115.                     #self.log("author %s" % author)
  116.                 if not articles.has_key(key):
  117.                     articles[key] = []
  118.                 articles[key].append(dict(title=title,url=url,date=pubdate,description=description,author=author,content=''))
  119.  
  120.         ans = [(key, articles[key]) for key in ans if articles.has_key(key)]
  121.         return ans
  122.