home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_4063 < prev    next >
Encoding:
Text File  |  2010-03-08  |  1.4 KB  |  63 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, tempfile
  12. from calibre.web.feeds.news import BasicNewsRecipe
  13.  
  14. class TazDigiabo(BasicNewsRecipe):
  15.  
  16.     title = u'Taz Digiabo'
  17.     description = u'Das EPUB DigiAbo der Taz'
  18.     language = 'de'
  19.     lang = 'de-DE'
  20.  
  21.     __author__ = 'Lars Jacob'
  22.     needs_subscription = True
  23.  
  24.     conversion_options = {
  25.         'no_default_epub_cover' : True
  26.     }
  27.  
  28.     def build_index(self):
  29.         if self.username is not None and self.password is not None:
  30.             domain = "http://www.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.                 return
  47.  
  48.             tmp = tempfile.TemporaryFile()
  49.             self.report_progress(0,_('downloading epub'))
  50.             tmp.write(f.read())
  51.  
  52.             zfile = zipfile.ZipFile(tmp, 'r')
  53.             self.report_progress(0,_('extracting epub'))
  54.  
  55.             zfile.extractall(self.output_dir)
  56.  
  57.             tmp.close()
  58.             index = os.path.join(self.output_dir, 'content.opf')
  59.  
  60.             self.report_progress(1,_('epub downloaded and extracted'))
  61.  
  62.             return index
  63.