Verified Commit ac288176 authored by Markus Shepherd's avatar Markus Shepherd 🙈
Browse files

account for item types without image fields

parent a0bc3032
......@@ -219,16 +219,17 @@ class LimitImagesPipeline:
def process_item(self, item, spider):
"""Copy a limited number of image URLs to be downloaded from source to target."""
if self.limit is None or self.limit < 0: # copy through everything
item[self.target_field] = list(arg_to_iter(item.get(self.source_field)))
return item
values = (
arg_to_iter(item.get(self.source_field))
if self.limit is None or self.limit < 0 # copy through everything
else ()
if not self.limit # limit is zero
else islice(arg_to_iter(item.get(self.source_field)), self.limit)
)
if not self.limit: # limit is zero
item[self.target_field] = []
return item
try:
item[self.target_field] = list(values)
except Exception:
pass
# actual limit
item[self.target_field] = list(
islice(arg_to_iter(item.get(self.source_field)), self.limit)
)
return item
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment