Fix #6757 (News Download of taz Digiabo fails)

This commit is contained in:
Kovid Goyal 2010-09-17 12:02:43 -06:00
parent 466cfa9412
commit 6566014a8b
2 changed files with 34 additions and 27 deletions

View File

@ -8,8 +8,9 @@ __docformat__ = 'restructuredtext de'
''' '''
www.taz.de/digiabo www.taz.de/digiabo
''' '''
import os, urllib2, zipfile, tempfile import os, urllib2, zipfile
from calibre.web.feeds.news import BasicNewsRecipe from calibre.web.feeds.news import BasicNewsRecipe
from calibre.ptempfile import PersistentTemporaryFile
class TazDigiabo(BasicNewsRecipe): class TazDigiabo(BasicNewsRecipe):
@ -26,7 +27,6 @@ class TazDigiabo(BasicNewsRecipe):
} }
def build_index(self): def build_index(self):
if self.username is not None and self.password is not None:
domain = "http://www.taz.de" domain = "http://www.taz.de"
url = domain + "/epub/" url = domain + "/epub/"
@ -46,11 +46,12 @@ class TazDigiabo(BasicNewsRecipe):
raise ValueError('Failed to login, check your username and' raise ValueError('Failed to login, check your username and'
' password') ' password')
tmp = tempfile.TemporaryFile() tmp = PersistentTemporaryFile(suffix='.epub')
self.report_progress(0,_('downloading epub')) self.report_progress(0,_('downloading epub'))
tmp.write(f.read()) tmp.write(f.read())
tmp.close()
zfile = zipfile.ZipFile(tmp, 'r') zfile = zipfile.ZipFile(tmp.name, 'r')
self.report_progress(0,_('extracting epub')) self.report_progress(0,_('extracting epub'))
zfile.extractall(self.output_dir) zfile.extractall(self.output_dir)
@ -61,3 +62,4 @@ class TazDigiabo(BasicNewsRecipe):
self.report_progress(1,_('epub downloaded and extracted')) self.report_progress(1,_('epub downloaded and extracted'))
return index return index

View File

@ -10,6 +10,7 @@ import os
from calibre.customize.conversion import InputFormatPlugin, OptionRecommendation from calibre.customize.conversion import InputFormatPlugin, OptionRecommendation
from calibre.constants import numeric_version from calibre.constants import numeric_version
from calibre import walk
class RecipeDisabled(Exception): class RecipeDisabled(Exception):
pass pass
@ -111,6 +112,10 @@ class RecipeInput(InputFormatPlugin):
if f.endswith('.opf'): if f.endswith('.opf'):
return os.path.abspath(f) return os.path.abspath(f)
for f in walk('.'):
if f.endswith('.opf'):
return os.path.abspath(f)
def postprocess_book(self, oeb, opts, log): def postprocess_book(self, oeb, opts, log):
if self.recipe_object is not None: if self.recipe_object is not None:
self.recipe_object.postprocess_book(oeb, opts, log) self.recipe_object.postprocess_book(oeb, opts, log)