home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / Calibre / calibre-0.8.18.msi / file_280 / windows_star.recipe < prev    next >
Text File  |  2011-09-09  |  4KB  |  107 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 Windsor Star
  15.     title = u'Windsor Star'
  16.     url_prefix = 'http://www.windsorstar.com'
  17.     description = u'News from Windsor, ON'
  18.  
  19.     # un-comment the following three lines for the Ottawa Citizen
  20.     #title = u'Ottawa Citizen'
  21.     #url_prefix = 'http://www.ottawacitizen.com'
  22.     #description = u'News from Ottawa, ON'
  23.  
  24.     # un-comment the following three lines for the Montreal Gazette
  25.     #title = u'Montreal Gazette'
  26.     #url_prefix = 'http://www.montrealgazette.com'
  27.     #description = u'News from Montreal, QC'
  28.  
  29.  
  30.     language = 'en_CA'
  31.     __author__ = 'Nick Redding'
  32.     no_stylesheets = True
  33.     timefmt = ' [%b %d]'
  34.     extra_css = '''
  35.                 .timestamp {  font-size:xx-small; display: block; }
  36.                 #storyheader { font-size: medium; }
  37.                 #storyheader h1 { font-size: x-large; }
  38.                 #storyheader h2 { font-size: large;  font-style: italic; }
  39.                 .byline { font-size:xx-small; }
  40.                 #photocaption { font-size: small; font-style: italic }
  41.                 #photocredit { font-size: xx-small; }'''
  42.     keep_only_tags = [dict(name='div', attrs={'id':'storyheader'}),dict(name='div', attrs={'id':'storycontent'})]
  43.     remove_tags = [{'class':'comments'},
  44.                    dict(name='div', attrs={'class':'navbar'}),dict(name='div', attrs={'class':'morelinks'}),
  45.                    dict(name='div', attrs={'class':'viewmore'}),dict(name='li', attrs={'class':'email'}),
  46.                    dict(name='div', attrs={'class':'story_tool_hr'}),dict(name='div', attrs={'class':'clear'}),
  47.                    dict(name='div', attrs={'class':'story_tool'}),dict(name='div', attrs={'class':'copyright'}),
  48.                    dict(name='div', attrs={'class':'rule_grey_solid'}),
  49.                    dict(name='li', attrs={'class':'print'}),dict(name='li', attrs={'class':'share'}),dict(name='ul', attrs={'class':'bullet'})]
  50.  
  51.     def preprocess_html(self,soup):
  52.         #delete iempty id attributes--they screw up the TOC for unknow reasons
  53.         divtags = soup.findAll('div',attrs={'id':''})
  54.         if divtags:
  55.             for div in divtags:
  56.                 del(div['id'])
  57.         return soup
  58.  
  59.  
  60.     def parse_index(self):
  61.         soup = self.index_to_soup(self.url_prefix+'/news/todays-paper/index.html')
  62.  
  63.         articles = {}
  64.         key = 'News'
  65.         ans = ['News']
  66.  
  67.         # Find each instance of class="sectiontitle", class="featurecontent"
  68.         for divtag in soup.findAll('div',attrs={'class' : ["section_title02","featurecontent"]}):
  69.                 #self.log(" div class = %s" % divtag['class'])
  70.                 if divtag['class'].startswith('section_title'):
  71.                     # div contains section title
  72.                     if not divtag.h3:
  73.                         continue
  74.                     key = self.tag_to_string(divtag.h3,False)
  75.                     ans.append(key)
  76.                     self.log("Section name %s" % key)
  77.                     continue
  78.                 # div contains article data
  79.                 h1tag = divtag.find('h1')
  80.                 if not h1tag:
  81.                     continue
  82.                 atag = h1tag.find('a',href=True)
  83.                 if not atag:
  84.                     continue
  85.                 url = self.url_prefix+'/news/todays-paper/'+atag['href']
  86.                 #self.log("Section %s" % key)
  87.                 #self.log("url %s" % url)
  88.                 title = self.tag_to_string(atag,False)
  89.                 #self.log("title %s" % title)
  90.                 pubdate = ''
  91.                 description = ''
  92.                 ptag = divtag.find('p');
  93.                 if ptag:
  94.                     description = self.tag_to_string(ptag,False)
  95.                     #self.log("description %s" % description)
  96.                 author = ''
  97.                 autag = divtag.find('h4')
  98.                 if autag:
  99.                     author = self.tag_to_string(autag,False)
  100.                     #self.log("author %s" % author)
  101.                 if not articles.has_key(key):
  102.                     articles[key] = []
  103.                 articles[key].append(dict(title=title,url=url,date=pubdate,description=description,author=author,content=''))
  104.  
  105.         ans = [(key, articles[key]) for key in ans if articles.has_key(key)]
  106.         return ans
  107.