commit
4c92a23dc8
|
@ -1,16 +1,17 @@
|
||||||
import logging
|
import logging
|
||||||
import math
|
import math
|
||||||
import re
|
import re
|
||||||
import urllib
|
|
||||||
import urllib2
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
import unicodedata
|
import unicodedata
|
||||||
from urlparse import urlparse
|
from urlparse import urlparse
|
||||||
|
|
||||||
from sorl.thumbnail import get_thumbnail
|
import requests
|
||||||
|
|
||||||
|
from botocore.exceptions import ClientError
|
||||||
from PIL import ImageFile
|
from PIL import ImageFile
|
||||||
|
from sorl.thumbnail import get_thumbnail
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
@ -1197,13 +1198,13 @@ class Ebook(models.Model):
|
||||||
return ebf.file
|
return ebf.file
|
||||||
|
|
||||||
def get_archive_ebf(self): # returns an ebf
|
def get_archive_ebf(self): # returns an ebf
|
||||||
if not self.ebook_files.filter(asking=False):
|
if not self.ebook_files.filter(asking=False).count():
|
||||||
if not self.provider in good_providers:
|
if not self.provider in good_providers:
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
r = urllib2.urlopen(self.url)
|
r = requests.get(self.url)
|
||||||
try:
|
if r.status_code == 200:
|
||||||
self.filesize = int(r.info().getheaders("Content-Length")[0])
|
self.filesize = len(r.content)
|
||||||
if self.save:
|
if self.save:
|
||||||
self.filesize = self.filesize if self.filesize < 2147483647 else 2147483647 # largest safe positive integer
|
self.filesize = self.filesize if self.filesize < 2147483647 else 2147483647 # largest safe positive integer
|
||||||
self.save()
|
self.save()
|
||||||
|
@ -1213,20 +1214,23 @@ class Ebook(models.Model):
|
||||||
format=self.format,
|
format=self.format,
|
||||||
source=self.url
|
source=self.url
|
||||||
)
|
)
|
||||||
ebf.file.save(path_for_file(ebf, None), ContentFile(r.read()))
|
ebf.file.save(path_for_file(ebf, None), ContentFile(r.content))
|
||||||
ebf.file.close()
|
ebf.file.close()
|
||||||
ebf.save()
|
ebf.save()
|
||||||
return ebf
|
return ebf
|
||||||
except IndexError:
|
else:
|
||||||
# response has no Content-Length header probably a bad link
|
|
||||||
logging.error('Bad link error: {}'.format(self.url))
|
logging.error('Bad link error: {}'.format(self.url))
|
||||||
except IOError:
|
except IOError:
|
||||||
logger.error(u'could not open {}'.format(self.url))
|
logger.error(u'could not open {}'.format(self.url))
|
||||||
else:
|
else:
|
||||||
ebf = self.ebook_files.filter(asking=False).order_by('-created')[0]
|
ebf = self.ebook_files.filter(asking=False).order_by('-created')[0]
|
||||||
if not self.filesize:
|
if not self.filesize:
|
||||||
|
try:
|
||||||
self.filesize = ebf.file.size
|
self.filesize = ebf.file.size
|
||||||
self.save()
|
self.save()
|
||||||
|
except ClientError:
|
||||||
|
# error thrown when the can't access the S3 bucket
|
||||||
|
pass
|
||||||
return ebf
|
return ebf
|
||||||
|
|
||||||
def set_provider(self):
|
def set_provider(self):
|
||||||
|
|
|
@ -307,7 +307,7 @@ class CustomRegistrationView(RegistrationView):
|
||||||
return self.pretend_success()
|
return self.pretend_success()
|
||||||
return super(CustomRegistrationView, self).form_valid(form)
|
return super(CustomRegistrationView, self).form_valid(form)
|
||||||
|
|
||||||
SUSPICIOUSUN = re.compile(r'^[A-Z]([a-z]{4,8})[a-z]{3}$', )
|
SUSPICIOUSUN = re.compile(r'^[A-Z][a-z]{7}[a-z]*$', )
|
||||||
MANYDOTS = re.compile(r'(\.[^\.]+){4}')
|
MANYDOTS = re.compile(r'(\.[^\.]+){4}')
|
||||||
def similar(s1, s2):
|
def similar(s1, s2):
|
||||||
#trigrams in common
|
#trigrams in common
|
||||||
|
|
|
@ -14,8 +14,8 @@ anyjson==0.3.3
|
||||||
appdirs==1.4.0
|
appdirs==1.4.0
|
||||||
billiard==3.3.0.23
|
billiard==3.3.0.23
|
||||||
awscli>=1.15.52
|
awscli>=1.15.52
|
||||||
boto==2.48.0
|
boto==2.49.0
|
||||||
boto3==1.7.33
|
boto3==1.9.167
|
||||||
celery==3.1.23
|
celery==3.1.23
|
||||||
certifi==2019.3.9
|
certifi==2019.3.9
|
||||||
chardet==3.0.4
|
chardet==3.0.4
|
||||||
|
|
Loading…
Reference in New Issue