Exemplo n.º 1
0
    def download(self, index):
        image = self.container[index]
        filename = image['filename']
        href = image['href']
        # filename=href.split('/')[-1]

        if os.path.isfile(self.save_path + '/' + filename):
            return
        print 'Downloading picture:' + href + '   filename   ' + filename

        # urllib.urlretrieve(href, self.save_path + '/' + filename, cbk)

        if len(str(href)) < 300 and Match.isUrlOk(href):
            # Debug.print_in_single_line(u'Downloading picture: {}'.format(href))
            rely_url = str(href).split('@')[0]
            content = Http.get_content(url=rely_url,
                                       timeout=Config.timeout_download_picture)
        else:
            Debug.print_in_single_line(u"Href of the Picture seems wrong...")
            content = None
        if not content:
            return
        with open(self.save_path + '/' + filename, 'wb') as image:
            image.write(content)
        return