home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / Calibre / calibre-0.8.18.msi / file_280 / nrc-nl-epub.recipe < prev    next >
Encoding:
Text File  |  2011-09-09  |  2.1 KB  |  77 lines

  1. #!/usr/bin/env  python2
  2. # -*- coding: utf-8 -*-
  3. #Based on veezh's original recipe and Kovid Goyal's New York Times recipe
  4.  
  5. __license__   = 'GPL v3'
  6. __copyright__ = '2011, Snaab'
  7.  
  8. '''
  9. www.nrc.nl
  10. '''
  11. import os, zipfile
  12. import time
  13. from calibre.web.feeds.news import BasicNewsRecipe
  14. from calibre.ptempfile import PersistentTemporaryFile
  15.  
  16.  
  17. class NRCHandelsblad(BasicNewsRecipe):
  18.  
  19.     title = u'NRC Handelsblad'
  20.     description = u'De ePaper-versie van NRC'
  21.     language = 'nl'
  22.     lang = 'nl-NL'
  23.     needs_subscription = True
  24.  
  25.     __author__ = 'Snaab'
  26.  
  27.     conversion_options = {
  28.         'no_default_epub_cover' : True
  29.     }
  30.  
  31.     def get_browser(self):
  32.         br = BasicNewsRecipe.get_browser()
  33.         if self.username is not None and self.password is not None:
  34.             br.open('http://login.nrc.nl/login')
  35.             br.select_form(nr=0)
  36.             br['username']   = self.username
  37.             br['password'] = self.password
  38.             br.submit()
  39.         return br
  40.  
  41.     def build_index(self):
  42.  
  43.         today = time.strftime("%Y%m%d")
  44.  
  45.         domain = "http://digitaleeditie.nrc.nl"
  46.  
  47.         url = domain + "/digitaleeditie/helekrant/epub/nrc_" + today + ".epub"
  48.         #print url
  49.  
  50.         try:
  51.             br = self.get_browser()
  52.             f = br.open(url)
  53.         except:
  54.             self.report_progress(0,_('Kan niet inloggen om editie te downloaden'))
  55.             raise ValueError('Krant van vandaag nog niet beschikbaar')
  56.  
  57.  
  58.         tmp = PersistentTemporaryFile(suffix='.epub')
  59.         self.report_progress(0,_('downloading epub'))
  60.         tmp.write(f.read())
  61.         f.close()
  62.         br.close()
  63.         if zipfile.is_zipfile(tmp):
  64.             try:
  65.                 zfile = zipfile.ZipFile(tmp.name, 'r')
  66.                 zfile.extractall(self.output_dir)
  67.                 self.report_progress(0,_('extracting epub'))
  68.             except zipfile.BadZipfile:
  69.                 self.report_progress(0,_('BadZip error, continuing'))
  70.  
  71.         tmp.close()
  72.         index = os.path.join(self.output_dir, 'metadata.opf')
  73.  
  74.         self.report_progress(1,_('epub downloaded and extracted'))
  75.  
  76.         return index
  77.