Skip to main content

Python module for searching and downloading images from Ecosia

Project description

python-ecosia-images

Python module for searching and downloading images from Ecosia

Installing

pip install ecosia-images

Setup

The only requisite to work with the library is to have a chromedriver executable in the PATH. See the following link for more information.

Examples

Search images and get the links to the pictures

After declaring a crawler and using it to search for a keyword, the resulting links will be accesible by the links property

>>> from ecosia_images import crawler
>>> searcher = crawler()
>>> searcher.search('number 9')
>>> searcher.links
{ ... } # urls

Search with options

Searches can also include the options that Ecosia provides for refining results. The available keys and values for refining searches are stored in ecosia_images.download_options.

>>> from ecosia_images import download_options
>>> download_options
{
    'size': ['small', 'medium', 'large', 'wallpaper'],
    'color': ['colorOnly', 'monochrome', 'red', 'orange', 'yellow', 'green', 'teal', 'blue', 'purple', 'pink', 'brown', 'black', 'gray'],
    'image_type': ['photo', 'clipart', 'line', 'animated'],
    'freshness': ['day', 'week', 'month'],
    'license': ['share', 'shareCommercially', 'modify', 'modifyCommercially', 'public']
}

The selected options can be specified when calling the search method of the crawler.

>>> searcher.search('trees', color='monochrome', size='wallpaper')
>>> searcher.links
{ ... } # links to big pictures of trees in black and white

Gather more links

If more links are needed the function gather_more can be used.

>>> searcher.search('bees')
>>> len(searcher.links)
50  # Give or take
>>> searcher.gather_more()
>>> len(searcher.links)
100 # Give or take

Download images

In all the following cases, the script first checks whether the image has been already downloaded so it does not downloads it again. Also, the functions will return the file paths to the downloaded images.

The download function will download a given number of pictures and save them in a folder whose name coincides with the keyword. This folder will be created inside the one specified when calling the function. In the following example, the images would be saved inside /path/to/folder/downloads/keyword/.

>>> searcher.search('keyword')
>>> searcher.download(100, '/path/to/folder/')
[ ... ] # list with file paths

If no folder is specified, the images will be saved inside a new folder named downloads located in the current working directory.

>>> searcher.search('apples')
>>> searcher.download(100)  # The pictures will be saved at ./downloads/apples/
[ ... ]

There is also the download_all function which will download all the currently available links in the crawler object

>>> searcher.search('pidgeons')
>>> searcher.download_all()
[ ... ]

Stoping the client

It is necessary to stop the crawler to avoid resource leak.

>>> searcher.stop()

Disclaimer

The dowloaded images come from the Ecosia search engine and they may have copyrights. Do not download or use any image that violates its copyright terms.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ecosia_images-0.4.8.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

ecosia_images-0.4.8-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file ecosia_images-0.4.8.tar.gz.

File metadata

  • Download URL: ecosia_images-0.4.8.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.6

File hashes

Hashes for ecosia_images-0.4.8.tar.gz
Algorithm Hash digest
SHA256 d5d955b7cc07b7f34ba5b6de10ba1927364c317393b9eb92f6963c28d453137f
MD5 e37c44bd308ba323cd1548f4e4a86c9b
BLAKE2b-256 7426701b634377478f5f707ac9b604deacb630e723ebff194c216623ec97b9f7

See more details on using hashes here.

File details

Details for the file ecosia_images-0.4.8-py3-none-any.whl.

File metadata

  • Download URL: ecosia_images-0.4.8-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.6

File hashes

Hashes for ecosia_images-0.4.8-py3-none-any.whl
Algorithm Hash digest
SHA256 e050f731bd283699acc73a3995a9c58b0fe39253f93b94f368f2948f60705ae2
MD5 fe1ccf3d33d81af65261d65855336224
BLAKE2b-256 8bffb6cdcb037b4bdf0f0d7fc2cb867a0651232e7564b68439009ba5c57adb06

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page