Skip to content

Commit

Permalink
Merge pull request ultralytics#10 from NicolasGrosjean/patch-6
Browse files Browse the repository at this point in the history
Fix time_range argument
  • Loading branch information
Joeclinton1 authored Sep 26, 2021
2 parents 9070776 + a0c18fd commit e13cc55
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions google_images_download/google_images_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def user_input():
parser.add_argument('-w', '--time', help='image age', type=str, required=False,
choices=['past-24-hours', 'past-7-days', 'past-month', 'past-year'])
parser.add_argument('-wr', '--time_range',
help='time range for the age of the image. should be in the format {"time_min":"MM/DD/YYYY","time_max":"MM/DD/YYYY"}',
help='time range for the age of the image. should be in the format {"time_min":"YYYY-MM-DD","time_max":"YYYY-MM-DD"}',
type=str, required=False)
parser.add_argument('-a', '--aspect_ratio', help='comma separated additional words added to keywords', type=str,
required=False,
Expand Down Expand Up @@ -501,13 +501,6 @@ def build_url_parameters(self, arguments):
else:
lang_url = ''

if arguments['time_range']:
json_acceptable_string = arguments['time_range'].replace("'", "\"")
d = json.loads(json_acceptable_string)
time_range = ',cdr:1,cd_min:' + d['time_min'] + ',cd_max:' + d['time_max']
else:
time_range = ''

if arguments['exact_size']:
size_array = [x.strip() for x in arguments['exact_size'].split(',')]
exact_size = ",isz:ex,iszw:" + str(size_array[0]) + ",iszh:" + str(size_array[1])
Expand Down Expand Up @@ -555,7 +548,7 @@ def build_url_parameters(self, arguments):
else:
built_url = built_url + ',' + ext_param
counter += 1
built_url = lang_url + built_url + exact_size + time_range
built_url = lang_url + built_url + exact_size
return built_url

# building main search URL
Expand Down Expand Up @@ -1046,6 +1039,14 @@ def download_executor(self, arguments):
if arguments['proxy']:
os.environ["http_proxy"] = arguments['proxy']
os.environ["https_proxy"] = arguments['proxy']

# Add time range to keywords if asked
time_range = ''
if arguments['time_range']:
json_acceptable_string = arguments['time_range'].replace("'", "\"")
d = json.loads(json_acceptable_string)
time_range = ' after:' + d['time_min'] + ' before:' + d['time_max']

######Initialization Complete
total_errors = 0
for pky in prefix_keywords: # 1.for every prefix keywords
Expand Down Expand Up @@ -1075,6 +1076,7 @@ def download_executor(self, arguments):

params = self.build_url_parameters(arguments) # building URL with params

search_term += time_range
url = self.build_search_url(search_term, params, arguments['url'], arguments['similar_images'],
arguments['specific_site'],
arguments['safe_search']) # building main search url
Expand Down

0 comments on commit e13cc55

Please sign in to comment.