home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_4104 < prev    next >
Encoding:
Text File  |  2010-02-11  |  4.3 KB  |  92 lines

  1. #!/usr/bin/env  python
  2.  
  3. __license__   = 'GPL v3'
  4. __copyright__ = '2009, Darko Miletic <darko.miletic at gmail.com>'
  5. '''
  6. www.torontosun.com
  7. '''
  8.  
  9. from calibre.web.feeds.news import BasicNewsRecipe
  10.  
  11. class TorontoSun(BasicNewsRecipe):
  12.     title                 = 'Toronto SUN'
  13.     __author__            = 'Darko Miletic and Sujata Raman'
  14.     description           = 'News from Canada'
  15.     publisher             = 'Toronto Sun'
  16.     category              = 'news, politics, Canada'
  17.     oldest_article        = 2
  18.     max_articles_per_feed = 100
  19.     no_stylesheets        = True
  20.     use_embedded_content  = False
  21.     encoding              = 'cp1252'
  22.     language              = 'en_CA'
  23.  
  24.     conversion_options  = {
  25.                               'comment'   : description
  26.                             , 'tags'      : category
  27.                             , 'publisher' : publisher
  28.                             , 'language'  : language
  29.                           }
  30.  
  31.     keep_only_tags      = [
  32.                                dict(name='div', attrs={'class':['articleHead','leftBox']})
  33.                               ,dict(name='div', attrs={'id':'channelContent'})
  34.                               ,dict(name='div', attrs={'id':'rotateBox'})
  35.                               ,dict(name='img')
  36.                           ]
  37.     remove_tags         = [
  38.                               dict(name='div',attrs={'class':['bottomBox clear','bottomBox','breadCrumb','articleControls thin','articleControls thin short','extraVideoList']})
  39.                              ,dict(name='h2',attrs={'class':'microhead'})
  40.                              ,dict(name='div',attrs={'id':'commentsBottom'})
  41.                              ,dict(name=['link','iframe','object'])
  42.                              ,dict(name='a',attrs={'rel':'swap'})
  43.                              ,dict(name='a',attrs={'href':'/news/haiti/'})
  44.                              ,dict(name='ul',attrs={'class':['tabs dl contentSwap','micrositeNav clearIt hList','galleryNav rotateNav']})
  45.                           ]
  46.  
  47.     remove_tags_after   = [
  48.                             dict(name='div',attrs={'class':'bottomBox clear'})
  49.                            ,dict(name='div',attrs={'class':'rotateBox'})
  50.                            ,dict(name='div',attrs={'id':'contentSwap'})
  51.                           ]
  52.  
  53.  
  54.     extra_css = '''
  55.                 h1{font-family :Arial,Helvetica,sans-serif; font-size:large;}
  56.                 h2{font-family :Arial,Helvetica,sans-serif; font-size:medium; color:#666666;}
  57.                 h3{font-family :Arial,Helvetica,sans-serif; font-size:medium; color:#000000;}
  58.                 p{font-family :Arial,Helvetica,sans-serif; font-size:x-small;}
  59.                 .bold{font-family :Arial,Helvetica,sans-serif; font-size: xx-small;color:#444444;margin-left: 0px;}
  60.                 .subheading{font-family :Arial,Helvetica,sans-serif; font-size:medium; color:#000000; font-weight: bold;}
  61.                 .byline{color:#666666; font-family :Arial,Helvetica,sans-serif; font-size: xx-small;}
  62.                 .byline span{color:#666666; font-family :Arial,Helvetica,sans-serif; font-size: xx-small; text-transform: uppercase;}
  63.                 .updated{font-family :Arial,Helvetica,sans-serif; font-size: xx-small;}
  64.                 .galleryCaption{font-family :Arial,Helvetica,sans-serif; font-size: x-small;}
  65.                 .galleryUpdated{font-family :Arial,Helvetica,sans-serif; font-size: x-small;}
  66.                 '''
  67.  
  68.  
  69.     feeds = [
  70.               (u'News'       , u'http://www.torontosun.com/news/rss.xml'           )
  71.              ,(u'Canada'     , u'http://www.torontosun.com/news/canada/rss.xml'    )
  72.              ,(u'Columnists' , u'http://www.torontosun.com/news/columnists/rss.xml')
  73.              ,(u'World'      , u'http://www.torontosun.com/news/world/rss.xml'     )
  74.              ,(u'Money'      , u'http://www.torontosun.com/money/rss.xml'          )
  75.             ]
  76.  
  77.     def preprocess_html(self, soup):
  78.         ##To fetch images from the specified source
  79.         for img in soup.findAll('img', src=True):
  80.             url= img.get('src').split('?')[-1].partition('=')[-1]
  81.             if url:
  82.                 img['src'] = url.split('&')[0].partition('=')[0]
  83.                 img['width'] = url.split('&')[-1].partition('=')[-1].split('x')[0]
  84.                 img['height'] =url.split('&')[-1].partition('=')[-1].split('x')[1]
  85.         return soup
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.