From a7420c8897307a03e73ad81d71690fde8d12d66c Mon Sep 17 00:00:00 2001 From: Ivan Arar Date: Tue, 23 Feb 2021 10:55:29 +0100 Subject: [PATCH] hotfix/cli-default-params --- CHANGELOG.md | 6 ++++++ google_images_search/cli.py | 25 ++++++++++++++--------- google_images_search/fetch_resize_save.py | 8 +++++--- google_images_search/google_api.py | 9 ++++---- setup.py | 5 +++-- 5 files changed, 34 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db9843f..2481393 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 1.3.6 + +### Fixed in 1.3.6 + +- CLI used non-null default params (discovered by [@itoche](https://github.com/itoche)) + ## 1.3.5 ### Fixed in 1.3.5 diff --git a/google_images_search/cli.py b/google_images_search/cli.py index e64d3e1..44e605f 100644 --- a/google_images_search/cli.py +++ b/google_images_search/cli.py @@ -22,7 +22,8 @@ def cli(ctx, developer_key, custom_search_cx): DOMINANT_COLORS = ('black', 'blue', 'brown', 'gray', 'green', 'pink', 'purple', 'teal', 'white', 'yellow') SAFE_SEARCH = ('high', 'medium', 'off', ) -USAGE_RIGHTS = ('cc_publicdomain', 'cc_attribute', 'cc_sharealike', 'cc_noncommercial', 'cc_nonderived') +USAGE_RIGHTS = ('cc_publicdomain', 'cc_attribute', 'cc_sharealike', + 'cc_noncommercial', 'cc_nonderived') @cli.command() @@ -32,23 +33,27 @@ def cli(ctx, developer_key, custom_search_cx): @click.option('-s', '--safe', type=click.Choice(SAFE_SEARCH), default='off', help='Search safety level') @click.option('-f', '--filetype', type=click.Choice(FILE_TYPES), - default='jpg', help='Images file type') + help='Images file type') @click.option('-i', '--imagetype', type=click.Choice(IMAGE_TYPES), - default='photo', help='Image type') + help='Image type') @click.option('-s', '--imagesize', type=click.Choice(IMAGE_SIZES), - default='large', help='Image size') + help='Image size') @click.option('-c', '--dominantcolor', type=click.Choice(DOMINANT_COLORS), - default='black', help='Dominant color in images') -@click.option('-r', '--usagerights', type=click.Choice(USAGE_RIGHTS), multiple=True, - default=('cc_publicdomain',), help='Usage rights of images') + help='Dominant color in images') +@click.option('-r', '--usagerights', type=click.Choice(USAGE_RIGHTS), + multiple=True, help='Usage rights of images') @click.option('-d', '--download_path', type=click.Path(dir_okay=True), help='Download images') @click.option('-w', '--width', help='Image crop width') @click.option('-h', '--height', help='Image crop height') @click.option('-m', '--custom_file_name', help='Custom file name') -def search(ctx, query, num, safe, filetype, imagetype, - imagesize, dominantcolor, usagerights, download_path, width, height, custom_file_name): +def search(ctx, query, num, safe, filetype, imagetype, imagesize, + dominantcolor, usagerights, download_path, width, height, + custom_file_name): + usagerights = '|'.join(usagerights) + if imagesize: + imagesize = imagesize.upper() search_params = { 'q': query, 'num': num, @@ -56,7 +61,7 @@ def search(ctx, query, num, safe, filetype, imagetype, 'fileType': filetype, 'imgType': imagetype, 'rights': usagerights, - 'imgSize': imagesize.upper(), + 'imgSize': imagesize, 'imgDominantColor': dominantcolor } diff --git a/google_images_search/fetch_resize_save.py b/google_images_search/fetch_resize_save.py index db6ab1f..c2ac500 100644 --- a/google_images_search/fetch_resize_save.py +++ b/google_images_search/fetch_resize_save.py @@ -40,7 +40,7 @@ def __init__(self, developer_key, custom_search_cx, self._number_of_images = None if progressbar_fn: - # user nserted progressbar fn + # user inserted progressbar fn self._progress = True else: if progress: @@ -120,7 +120,8 @@ def search(self, search_params, path_to_dir=False, width=None, self._search_images(*self._get_data()) - if len(self._search_result) >= self._number_of_images or self.zero_return: + if len(self._search_result) >= self._number_of_images \ + or self.zero_return: break else: # run search again if validation removed some images @@ -277,7 +278,8 @@ def get_raw_data(self, url): if self._progress: self._download_progress[url] += 1 if self._download_progress[url] <= 100: - self._report_progress(url, self._download_progress[url]) + self._report_progress( + url, self._download_progress[url]) yield chunk diff --git a/google_images_search/google_api.py b/google_images_search/google_api.py index a877272..e4a8b7f 100644 --- a/google_images_search/google_api.py +++ b/google_images_search/google_api.py @@ -1,6 +1,6 @@ import os import requests -from apiclient.discovery import build +from apiclient import discovery class GoogleCustomSearch(object): @@ -39,9 +39,10 @@ def _query_google_api(self, search_params, cache_discovery=True): """ if not self._google_build: - self._google_build = build("customsearch", "v1", - developerKey=self._developer_key, - cache_discovery=cache_discovery) + self._google_build = discovery.build( + "customsearch", "v1", + developerKey=self._developer_key, + cache_discovery=cache_discovery) return self._google_build.cse().list( cx=self._custom_search_cx, **search_params).execute() diff --git a/setup.py b/setup.py index 98131b2..4fea181 100644 --- a/setup.py +++ b/setup.py @@ -8,9 +8,10 @@ def readme(): setup( name='Google Images Search', - version="1.3.5", + version="1.3.6", - description='Search for image using Google Custom Search API and resize & crop the image afterwords', + description='Search for image using Google Custom Search ' + 'API and resize & crop the image afterwords', long_description=readme(), long_description_content_type='text/markdown',