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

  1. #!/usr/bin/env  python
  2. # -*- coding: utf-8 -*-
  3.  
  4. __license__   = 'GPL v3'
  5. __copyright__ = '2010, Lars Jacob jacob.lars at gmail.com'
  6. __docformat__ = 'restructuredtext de'
  7.  
  8. '''
  9. www.taz.de/digiabo
  10. '''
  11. import os, urllib2, zipfile
  12. from calibre.web.feeds.news import BasicNewsRecipe
  13. from calibre.ptempfile import PersistentTemporaryFile
  14.  
  15. class TazDigiabo(BasicNewsRecipe):
  16.  
  17.     title = u'Taz Digiabo'
  18.     description = u'Das EPUB DigiAbo der Taz'
  19.     language = 'de'
  20.     lang = 'de-DE'
  21.  
  22.     __author__ = 'Lars Jacob'
  23.     needs_subscription = True
  24.  
  25.     conversion_options = {
  26.         'no_default_epub_cover' : True
  27.     }
  28.  
  29.     def build_index(self):
  30.         domain = "http://dl.taz.de"
  31.  
  32.         url = domain + "/epub/"
  33.  
  34.         auth_handler = urllib2.HTTPBasicAuthHandler()
  35.         auth_handler.add_password(realm='TAZ-ABO',
  36.                                     uri=url,
  37.                                     user=self.username,
  38.                                     passwd=self.password)
  39.         opener = urllib2.build_opener(auth_handler)
  40.         urllib2.install_opener(opener)
  41.  
  42.         try:
  43.             f = urllib2.urlopen(url)
  44.         except urllib2.HTTPError:
  45.             self.report_progress(0,_('Can\'t login to download issue'))
  46.             raise ValueError('Failed to login, check your username and'
  47.                     ' password')
  48.  
  49.         tmp = PersistentTemporaryFile(suffix='.epub')
  50.         self.report_progress(0,_('downloading epub'))
  51.         tmp.write(f.read())
  52.         tmp.close()
  53.  
  54.         zfile = zipfile.ZipFile(tmp.name, 'r')
  55.         self.report_progress(0,_('extracting epub'))
  56.  
  57.         zfile.extractall(self.output_dir)
  58.  
  59.         tmp.close()
  60.         index = os.path.join(self.output_dir, 'content.opf')
  61.  
  62.         self.report_progress(1,_('epub downloaded and extracted'))
  63.  
  64.         return index
  65.  
  66.