Skip to content

Commit

Permalink
Merge pull request #99 from arrrlo/develop
Browse files Browse the repository at this point in the history
hotfix/cli-default-params
  • Loading branch information
arrrlo authored Feb 23, 2021
2 parents 5824e87 + fa67a83 commit 94b5351
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 19 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
25 changes: 15 additions & 10 deletions google_images_search/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -32,31 +33,35 @@ 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,
'safe': safe,
'fileType': filetype,
'imgType': imagetype,
'rights': usagerights,
'imgSize': imagesize.upper(),
'imgSize': imagesize,
'imgDominantColor': dominantcolor
}

Expand Down
8 changes: 5 additions & 3 deletions google_images_search/fetch_resize_save.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
9 changes: 5 additions & 4 deletions google_images_search/google_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import requests
from apiclient.discovery import build
from apiclient import discovery


class GoogleCustomSearch(object):
Expand Down Expand Up @@ -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()
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',

Expand Down

0 comments on commit 94b5351

Please sign in to comment.