Esempio n. 1
0
 def find_images(self, response, meta=None):
     sel = parsel.Selector(text=response.text)
     url = sel.xpath("//div[@class='post-image']/a/img/@src").extract_first()
     if url:
         url = utils.fix_url_http(url)
         file_resp = requests.get(url)
         return make_content(file_resp, meta)
     return {}
Esempio n. 2
0
 def find_images(self, response, meta=None):
     sel = parsel.Selector(text=response.text)
     url = sel.xpath(
         "//div[@class='post-image']/a/img/@src").extract_first()
     if url:
         url = utils.fix_url_http(url)
         file_resp = requests.get(url)
         return make_content(file_resp, meta)
     return {}
Esempio n. 3
0
 def download(year_month=None, position=None):
     """
     :param year_month - specify history month, default all of history
     :param position - position of image to ues, default random
     :return: dict{'content': <image_content>, <some meta data>...}
     """
     images = [os.path.join(loc, i['name']) for i, loc in get_history(year_month)]
     if position is None:
         image = random.choice(images)
     elif position <= len(images) or position < 0:
         image = images[position]
     else:
         e = ValueError('Position too high: pos:{}/images found:{}'.format(position, len(images)))
         sys.exit(e)
     # make fake requests response
     image_response = Response()
     image_response.url = image
     with open(image, 'rb') as image_file:
         image_response._content = image_file.read()
     return make_content(image_response)
Esempio n. 4
0
 def download(year_month=None, position=None):
     """
     :param year_month - specify history month, default all of history
     :param position - position of image to ues, default random
     :return: dict{'content': <image_content>, <some meta data>...}
     """
     images = [
         os.path.join(loc, i['name']) for i, loc in get_history(year_month)
     ]
     if position is None:
         image = random.choice(images)
     elif position <= len(images) or position < 0:
         image = images[position]
     else:
         e = ValueError('Position too high: pos:{}/images found:{}'.format(
             position, len(images)))
         sys.exit(e)
     # make fake requests response
     image_response = Response()
     image_response.url = image
     with open(image, 'rb') as image_file:
         image_response._content = image_file.read()
     return make_content(image_response)