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

  1. from calibre import strftime
  2. from calibre.web.feeds.news import BasicNewsRecipe
  3.  
  4. class Volkskrant_full(BasicNewsRecipe):
  5.     # This recipe will download the Volkskrant newspaper,
  6.     # from the subscribers site. It requires a password.
  7.     # Known issues are: articles that are spread out over
  8.     # multiple pages will appear multiple times. Pages
  9.     # that contain only adverts will appear, but empty.
  10.     # The supplement 'Volkskrant Magazine' on saturday
  11.     # is currently not downloaded.
  12.     # You can set a manual date, to download an archived
  13.     # newspaper. Volkskrant stores over a month at the
  14.     # moment of writing. To do so I suggest you unmark
  15.     # the date on the line below, and insert it in the title. Then
  16.     # follow the instructions marked further below.
  17.  
  18.     title = 'De Volkskrant (subscription)' # [za, 13 nov 2010]'
  19.     __author__ = u'Selcal'
  20.     description = u"Volkskrant"
  21.     oldest_article = 30
  22.     max_articles_per_feed = 100
  23.     no_stylesheets = True
  24.     language = 'nl'
  25.     use_embedded_content = False
  26.     simultaneous_downloads = 1
  27.     delay = 1
  28.     needs_subscription = True
  29.     # Set RETRIEVEDATE to 'yyyymmdd' to load an older
  30.     # edition. Otherwise keep '%Y%m%d'
  31.     # When setting a manual date, unmark and add the date
  32.     # to the title above, and unmark the timefmt line to stop
  33.     # Calibre from adding today's date in addition.
  34.  
  35.     # timefmt = ''
  36.     RETRIEVEDATE = strftime('%Y%m%d')
  37.     INDEX_MAIN = 'http://www.volkskrant.nl/vk-online/VK/' + RETRIEVEDATE + '___/VKN01_001/#text'
  38.     INDEX_ARTICLE = 'http://www.volkskrant.nl/vk-online/VK/' + RETRIEVEDATE + '___/VKN01_001/'
  39.     LOGIN = 'http://www.volkskrant.nl/vk/user/loggedIn.do'
  40.     remove_tags = [dict(name='address')]
  41.     cover_url = 'http://www.volkskrant.nl/vk-online/VK/' + RETRIEVEDATE + '___/VKN01_001/page.jpg'
  42.  
  43.     def get_browser(self):
  44.         br = BasicNewsRecipe.get_browser()
  45.  
  46.         if self.username is not None and self.password is not None:
  47.            br.open(self.LOGIN)
  48.            br.select_form(nr = 0)
  49.            br['username'] = self.username
  50.            br['password'] = self.password
  51.            br.submit()
  52.         return br
  53.  
  54.     def parse_index(self):
  55.         krant = []
  56.         def strip_title(_title):
  57.             i = 0
  58.             while ((_title[i] <> ":") and (i <= len(_title))):
  59.                i = i + 1
  60.             return(_title[0:i])
  61.         for temp in range (5):
  62.               try:
  63.                 soup = self.index_to_soup(self.INDEX_MAIN)
  64.                 break
  65.               except:
  66.                 #print '(Retrying main index load)'
  67.                 continue
  68.         mainsoup = soup.find('td', attrs={'id': 'select_page_top'})
  69.         for option in mainsoup.findAll('option'):
  70.            articles = []
  71.            _INDEX = 'http://www.volkskrant.nl/vk-online/VK/' + self.RETRIEVEDATE + '___/' + option['value'] + '/#text'
  72.            _INDEX_ARTICLE = 'http://www.volkskrant.nl/vk-online/VK/' + self.RETRIEVEDATE + '___/' + option['value'] + '/'
  73.            #print ''
  74.            #print '<-------    Processing section: ' + _INDEX + ' ------------------------->'
  75.            for temp in range (5):
  76.               try:
  77.                 soup = self.index_to_soup(_INDEX)
  78.                 break
  79.               except:
  80.                 #print '(Retrying index load)'
  81.                 continue
  82.            for item in soup.findAll('area'):
  83.               art_nr = item['class']
  84.               attrname = art_nr[0:12] + '_section' + option['value'][0:5] + '_' + art_nr[26:len(art_nr)]
  85.               #print '==> Found: ' + attrname;
  86.               index_title = soup.find('div', attrs={'class': attrname})
  87.               get_title = index_title['title'];
  88.               _ARTICLE   = _INDEX_ARTICLE + attrname + '.html#text'
  89.               title = get_title;
  90.               #print '--> Title: ' + title;
  91.               #print '--> URL: ' + _ARTICLE;
  92.               for temp in range (5):
  93.                  try:
  94.                    souparticle =  self.index_to_soup(_ARTICLE);
  95.                    break
  96.                  except:
  97.                    print '(Retrying URL load)'
  98.                    continue
  99.               headerurl = souparticle.findAll('frame')[0]['src'];
  100.               #print '--> Read frame name for header: ' + headerurl;
  101.               url = _INDEX_ARTICLE + headerurl[0:len(headerurl)-12] + '_text.html';
  102.               #print '--> Corrected URL: ' + url;
  103.               if (get_title <> ''):
  104.                  title = strip_title(get_title)
  105.                  date  = strftime(' %B %Y')
  106.               if (title <> ''):
  107.                  articles.append({
  108.                                          'title'      :title
  109.                                         ,'date'       :date
  110.                                         ,'url'        :url
  111.                                         ,'description':''
  112.                                         })
  113.            krant.append( (option.string, articles))
  114.         return krant
  115.  
  116.