fix scrape bugs
This commit is contained in:
parent
af1eba56b2
commit
211f94d403
7 changed files with 33 additions and 9 deletions
|
@ -567,6 +567,7 @@ def click_to_scrape(request):
|
|||
msg = _("ISBN与现有图书重复")
|
||||
else:
|
||||
msg = _("爬取数据失败😫")
|
||||
logger.error(str(form.errors))
|
||||
return render(request, 'common/error.html', {'msg': msg})
|
||||
else:
|
||||
return HttpResponseBadRequest()
|
||||
|
|
|
@ -37,9 +37,16 @@ class JSONField(postgres.JSONField):
|
|||
if not value:
|
||||
return None
|
||||
json = {}
|
||||
pairs = eval(value)
|
||||
for pair in pairs:
|
||||
json = {**json, **pair}
|
||||
if isinstance(value, dict):
|
||||
json = value
|
||||
else:
|
||||
pairs = eval(value)
|
||||
if isinstance(pairs, dict):
|
||||
json = pairs
|
||||
else:
|
||||
# list or tuple
|
||||
for pair in pairs:
|
||||
json = {**json, **pair}
|
||||
return super().to_python(json)
|
||||
|
||||
|
||||
|
|
|
@ -297,8 +297,13 @@ def scrape_douban_movie(url):
|
|||
if showtime_elem:
|
||||
showtime = []
|
||||
for st in showtime_elem:
|
||||
time = st.split('(')[0]
|
||||
region = st.split('(')[1][0:-1]
|
||||
parts = st.split('(')
|
||||
if len(parts) == 1:
|
||||
time = st.split('(')[0]
|
||||
region = ''
|
||||
else:
|
||||
time = st.split('(')[0]
|
||||
region = st.split('(')[1][0:-1]
|
||||
showtime.append({time: region})
|
||||
else:
|
||||
showtime = None
|
||||
|
|
|
@ -55,8 +55,18 @@ function keyValueInput(valueKeyWidget, hiddenInput) {
|
|||
finalValue.push(JSON.stringify(json))
|
||||
});
|
||||
hiddenInput.val(finalValue.toString());
|
||||
} else {
|
||||
|
||||
} else if(keys.length - values.length == 1) {
|
||||
let finalValue = [];
|
||||
keys.forEach(function (key, i) {
|
||||
let json = new Object;
|
||||
if (i < keys.length - 1) {
|
||||
json[key] = values[i];
|
||||
} else {
|
||||
json[key] = ''
|
||||
}
|
||||
finalValue.push(JSON.stringify(json))
|
||||
});
|
||||
hiddenInput.val(finalValue.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -143,7 +143,7 @@ class Movie(Resource):
|
|||
)
|
||||
|
||||
year = models.PositiveIntegerField(null=True, blank=True)
|
||||
duration = models.CharField(blank=True, default='', max_length=100)
|
||||
duration = models.CharField(blank=True, default='', max_length=200)
|
||||
|
||||
cover = models.ImageField(_("poster"), upload_to=movie_cover_path, default=DEFAULT_MOVIE_IMAGE, blank=True)
|
||||
|
||||
|
|
|
@ -172,7 +172,7 @@
|
|||
<div>{% if movie.showtime %}{% trans '上映时间:' %}
|
||||
{% for showtime in movie.showtime %}
|
||||
{% for time, region in showtime.items %}
|
||||
<span>{{ time }}({{ region }})</span>
|
||||
<span>{{ time }}{% if region != '' %}({{ region }}){% endif %}</span>
|
||||
{% endfor %}
|
||||
{% if not forloop.last %} / {% endif %}
|
||||
{% endfor %}
|
||||
|
|
|
@ -571,6 +571,7 @@ def click_to_scrape(request):
|
|||
return redirect(reverse('movies:retrieve', args=[form.instance.id]))
|
||||
else:
|
||||
msg = _("爬取数据失败😫")
|
||||
logger.error(str(form.errors))
|
||||
return render(request, 'common/error.html', {'msg': msg})
|
||||
else:
|
||||
return HttpResponseBadRequest()
|
||||
|
|
Loading…
Add table
Reference in a new issue