Merge pull request #679 from Gluejar/fix-b2u-s2k

add get_archive method to acq.mock_ebook
pull/43/head
eshellman 2017-05-08 17:31:33 -04:00 committed by GitHub
commit 2b72402b7d
1 changed files with 13 additions and 2 deletions

View File

@ -287,8 +287,19 @@ class Acq(models.Model):
self.format = 'mobi'
self.filesize = 0
def save(self):
# TODO how to handle filesize?
return True
def get_archive(self):
try:
r = urllib2.urlopen(self.url)
try:
self.filesize = int(r.info().getheaders("Content-Length")[0])
except IndexError:
# response has no Content-Length header probably a bad link
logging.error('Bad link error: {}'.format(self.url))
return r
except IOError:
logger.error(u'could not open {}'.format(self.url))
def ebook(self):
return self.mock_ebook(self)