Example #1
0
def cli(count, year_month, raw, position, **kwargs):

    def print_item(item):
        click.echo(json.dumps(item, sort_keys=True, indent=2))

    all_items = list(get_history(year_month))
    if position is not None:
        print_item(all_items[int(position)][0])
        return
    items = all_items[::-1][:count][::-1]
    if raw:
        print_item(items)
        return
    for item in items:
        print_item(item[0])
Example #2
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)
Example #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)