harvest_online_ebooks should count books actually harvested
parent
7863fbfe0e
commit
db9b6e5221
|
@ -369,7 +369,7 @@ DROPBOX_DL = re.compile(r'"(https://dl.dropboxusercontent.com/content_link/[^"]+
|
||||||
|
|
||||||
def dl_online(ebook):
|
def dl_online(ebook):
|
||||||
if ebook.format != 'online':
|
if ebook.format != 'online':
|
||||||
return
|
return None, False
|
||||||
|
|
||||||
if ebook.url.find(u'dropbox.com/s/') >= 0:
|
if ebook.url.find(u'dropbox.com/s/') >= 0:
|
||||||
response = requests.get(ebook.url, headers={"User-Agent": settings.USER_AGENT})
|
response = requests.get(ebook.url, headers={"User-Agent": settings.USER_AGENT})
|
||||||
|
@ -387,7 +387,7 @@ def dl_online(ebook):
|
||||||
|
|
||||||
def make_dl_ebook(url, ebook):
|
def make_dl_ebook(url, ebook):
|
||||||
if EbookFile.objects.filter(source=ebook.url):
|
if EbookFile.objects.filter(source=ebook.url):
|
||||||
return EbookFile.objects.filter(source=ebook.url)[0]
|
return EbookFile.objects.filter(source=ebook.url)[0], False
|
||||||
response = requests.get(url, headers={"User-Agent": settings.USER_AGENT})
|
response = requests.get(url, headers={"User-Agent": settings.USER_AGENT})
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
filesize = int(response.headers.get("Content-Length", 0))
|
filesize = int(response.headers.get("Content-Length", 0))
|
||||||
|
@ -413,7 +413,7 @@ def make_dl_ebook(url, ebook):
|
||||||
)
|
)
|
||||||
new_ebf.ebook = new_ebook
|
new_ebf.ebook = new_ebook
|
||||||
new_ebf.save()
|
new_ebf.save()
|
||||||
return new_ebf
|
return new_ebf, True
|
||||||
|
|
||||||
def type_for_url(url, content_type=None):
|
def type_for_url(url, content_type=None):
|
||||||
if not url:
|
if not url:
|
||||||
|
|
|
@ -12,8 +12,8 @@ class Command(BaseCommand):
|
||||||
onlines = Ebook.objects.filter(format='online')
|
onlines = Ebook.objects.filter(format='online')
|
||||||
done = 0
|
done = 0
|
||||||
for online in onlines:
|
for online in onlines:
|
||||||
new_ebf = dl_online(online)
|
new_ebf, new = dl_online(online)
|
||||||
if new_ebf:
|
if new_ebf and new:
|
||||||
done += 1
|
done += 1
|
||||||
if done > limit:
|
if done > limit:
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in New Issue