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

  1.  
  2. __license__   = 'GPL v3'
  3. __copyright__ = '2009-2010, Darko Miletic <darko.miletic at gmail.com>'
  4. '''
  5. www.thetimes.co.uk
  6. '''
  7. import urllib
  8. from calibre.web.feeds.news import BasicNewsRecipe
  9.  
  10. class TimesOnline(BasicNewsRecipe):
  11.     title                 = 'The Times UK'
  12.     __author__            = 'Darko Miletic'
  13.     description           = 'news from United Kingdom and World'
  14.     language              = 'en_GB'
  15.     publisher             = 'Times Newspapers Ltd'
  16.     category              = 'news, politics, UK'
  17.     oldest_article        = 3
  18.     max_articles_per_feed = 100
  19.     no_stylesheets        = True
  20.     use_embedded_content  = False
  21.     encoding              = 'utf-8'
  22.     delay                 = 1
  23.     needs_subscription    = True
  24.     publication_type      = 'newspaper'
  25.     masthead_url          = 'http://www.thetimes.co.uk/tto/public/img/the_times_460.gif'
  26.     INDEX                 = 'http://www.thetimes.co.uk'
  27.     PREFIX                = u'http://www.thetimes.co.uk/tto/'
  28.     extra_css             = """
  29.                                 .f-ha{font-size: xx-large; font-weight: bold}
  30.                                 .f-author{font-family: Arial,Helvetica,sans-serif}
  31.                                 .caption{font-size: small}
  32.                                 body{font-family: Georgia,"Times New Roman",Times,serif}
  33.                             """
  34.     conversion_options = {
  35.                           'comment'    : description
  36.                         , 'tags'       : category
  37.                         , 'publisher'  : publisher
  38.                         , 'language'   : language
  39.                         }
  40.  
  41.  
  42.     def get_browser(self):
  43.         br = BasicNewsRecipe.get_browser()
  44.         br.open('http://www.timesplus.co.uk/tto/news/?login=false&url=http://www.thetimes.co.uk/tto/news/?lightbox=false')
  45.         if self.username is not None and self.password is not None:
  46.             data = urllib.urlencode({ 'userName':self.username
  47.                                      ,'password':self.password
  48.                                      ,'keepMeLoggedIn':'false'
  49.                                    })
  50.             br.open('https://www.timesplus.co.uk/iam/app/authenticate',data)
  51.         return br
  52.  
  53.     remove_tags      = [
  54.                            dict(name=['object','link','iframe','base','meta'])
  55.                           ,dict(attrs={'class':'tto-counter' })
  56.                         ]
  57.     remove_attributes=['lang']
  58.     keep_only_tags   = [
  59.                           dict(attrs={'class':'heading' })
  60.                          ,dict(attrs={'class':'f-author'})
  61.                          ,dict(attrs={'id':'bodycopy'})
  62.                        ]
  63.  
  64.     feeds = [
  65.                 (u'UK News'     , PREFIX + u'news/uk/?view=list'      )
  66.                ,(u'World'       , PREFIX + u'news/world/?view=list'   )
  67.                ,(u'Politics'    , PREFIX + u'news/politics/?view=list')
  68.                ,(u'Health'      , PREFIX + u'health/news/?view=list'  )
  69.                ,(u'Education'   , PREFIX + u'education/?view=list'    )
  70.                ,(u'Technology'  , PREFIX + u'technology/?view=list'   )
  71.                ,(u'Science'     , PREFIX + u'science/?view=list'      )
  72.                ,(u'Environment' , PREFIX + u'environment/?view=list'  )
  73.                ,(u'Faith'       , PREFIX + u'faith/?view=list'        )
  74.                ,(u'Opinion'     , PREFIX + u'opinion/?view=list'      )
  75.                ,(u'Sport'       , PREFIX + u'sport/?view=list'        )
  76.                ,(u'Business'    , PREFIX + u'business/?view=list'     )
  77.                ,(u'Money'       , PREFIX + u'money/?view=list'        )
  78.                ,(u'Life'        , PREFIX + u'life/?view=list'         )
  79.                ,(u'Arts'        , PREFIX + u'arts/?view=list'         )
  80.             ]
  81.  
  82.     def preprocess_html(self, soup):
  83.         for item in soup.findAll(style=True):
  84.             del item['style']
  85.         return self.adeify_images(soup)
  86.  
  87.     def parse_index(self):
  88.         totalfeeds = []
  89.         lfeeds = self.get_feeds()
  90.         for feedobj in lfeeds:
  91.             feedtitle, feedurl = feedobj
  92.             self.report_progress(0, _('Fetching feed')+' %s...'%(feedtitle if feedtitle else feedurl))
  93.             articles = []
  94.             soup = self.index_to_soup(feedurl)
  95.             for item in soup.findAll('td', attrs={'class':'title'}):
  96.                 atag          = item.find('a')
  97.                 url           = self.INDEX + atag['href']
  98.                 title         = self.tag_to_string(atag)
  99.                 articles.append({
  100.                                       'title'      :title
  101.                                      ,'date'       :''
  102.                                      ,'url'        :url
  103.                                      ,'description':''
  104.                                     })
  105.             totalfeeds.append((feedtitle, articles))
  106.         return totalfeeds
  107.