Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for more than one image attribute #18

Open
Netquin opened this issue Apr 28, 2013 · 3 comments
Open

Support for more than one image attribute #18

Netquin opened this issue Apr 28, 2013 · 3 comments
Labels

Comments

@Netquin
Copy link

Netquin commented Apr 28, 2013

Hello,

I think it would be interesting to handle more than one IMAGE attribute.

I think you could replace your DjangoImagesPipeline by this code :

class DjangoImagesPipeline(ImagesPipeline):

    def get_media_requests(self, item, info):
        try:
            for img_elem in info.spider.scraper.get_image_elems():
                if img_elem.scraped_obj_attr.name in item and item[img_elem.scraped_obj_attr.name]:
                    yield Request(item[img_elem.scraped_obj_attr.name])
        except (ScraperElem.DoesNotExist, TypeError):
            pass

    def image_key(self, url):
        image_guid = hashlib.sha1(url).hexdigest()
        return '%s.jpg' % (image_guid)

    def thumb_key(self, url, thumb_id):
        image_guid = hashlib.sha1(url).hexdigest()
        return '%s.jpg' % (image_guid)

    def item_completed(self, results, item, info):
        try:
            img_elems = info.spider.scraper.get_image_elems()
        except ScraperElem.DoesNotExist:
            return item
        for i in range(len(results)):
            if results[i][0]:
                print(results[i][1])
                for img_elem in img_elems:
                    if results[i][1]['url'] == item[img_elem.scraped_obj_attr.name]:
                        item[img_elem.scraped_obj_attr.name] = results[i][1]['path']
        return item
@holgerd77
Copy link
Owner

Hi, thanks for your suggestion and sorry for the late answer. I have little time to work on DDS at the moment, but I'll try to have a look at it and integrate in in the next release if I can accept it or I will post here for discussion.

@dominicx
Copy link

Good Job.I need two Image-Fields.

@holgerd77
Copy link
Owner

Will see if I can have a look at it again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants