123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- #!/usr/bin/env python
- if __name__ != '__main__': raise Exception("Do not import me!")
- from argparse import ArgumentParser
- from google_images_download import google_images_download #importing the library
- parser = ArgumentParser()
- parser.add_argument("classnames",
- help="file containing a class name in each line")
- parser.add_argument("--output_directory", "-o", default="download",
- help="output folder")
- parser.add_argument("--limit", "-l", default=60, type=int,
- help="number of images to dowload")
- def main(args):
- with open(args.classnames, "r") as f:
- names = f.readlines()
- query_names = [name.strip().partition(".")[-1].replace("_", " ").lower() for name in names if not name.startswith("#")]
- # query_names = [name.strip() for name in names if not name.startswith("#")]
- response = google_images_download.googleimagesdownload() #class instantiation
- print(f"Found {len(query_names)} query names")
- paths = response.download(dict(
- keywords=",".join(query_names),
- limit=args.limit,
- print_urls=False,
- size=">800*600",
- output_directory=args.output_directory,
- chromedriver="chromedriver"
- )) #passing the arguments to the function
- # print(paths) #printing absolute paths of the downloaded images
- main(parser.parse_args())
|