Python Unsplash random image downloader manager.
Project description
UnsplashRandDownloader
Python Unsplash Random Image Downloader.
This component periodically download and store random images based of specified topics from Unsplash platform and allows the user to request one of the downloaded images. It keeps control of the Unsplash API requests limits, and using some kind of "image files rotate" of the storage (removing and replacing older images with newer ones), it also control and limit the maximum number of images downloaded in the filesytem.
Installation
From Pypi:
python3 -m pip install unsplash_rand_downloader
From Sources:
git clone https://www.github.com/J-Rios/unsplash_rand_downloader
cd unsplash_rand_downloader
python3 -m pip install .
Usage
# Import the module
from unsplash_rand_downloader import UnsplashRandDownloader
# Set your Unsplash API access account identification parameters
# (Application Name, Client ID and Client Secret Key)
APP_NAME = "XXXXXXXXXXXXXXX"
CLIENT_ID = "XXXXXXXXXXX_XXXXX-XX-XXXXXXXXXXXXXXXXXXXXXX"
CLIENT_SECRET = "XXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
# Unsplash API mode to use (API_DEMO or API_PRODUCTION)
API_MODE = UnsplashRandDownloader.API_DEMO
# Limit the number of images to be downloaded (None, to use the maximum
# calculated number from Unsplash API request limits DEMO/PRODUCTION)
LIMIT_MAX_NUM_IMG = None
# Path of directory to store the downloaded images
IMAGES_DOWNLOAD_DIR = "./images"
# Size of images to download
IMG_WIDTH = 320
IMG_HEIGHT = 240
# Topics of images to download
TOPICS = ["bird", "halloween", "fire", "computer"]
# Setup the Downloader
unsplash = UnsplashRandDownloader(APP_NAME, CLIENT_ID, CLIENT_SECRET, API_MODE)
unsplash.setup(IMAGES_DOWNLOAD_DIR, TOPICS, IMG_WIDTH, IMG_HEIGHT,
LIMIT_MAX_NUM_IMG)
# Launch the Downloader
unsplash.start()
# Wait some time to allow UnsplashRandDownloader download some images
# ...
# Request a random image from downloaded images
img = unsplash.get_random_image()
if img is not None:
print("Image Topic: {}".format(img["topic"]))
print("Image ID: {}".format(img["id"]))
print("Image Attribution: {}".format(img["attribution"]))
#print("Image Raw: {}".format(img["image"]))
# To exit your application, remember to stop the downloader before
unsplash.stop()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file unsplash_rand_downloader-1.0.0.tar.gz
.
File metadata
- Download URL: unsplash_rand_downloader-1.0.0.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.20.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2aa5baf37ac0a9a5518fc8630bc74ce8517b96bcaba13f0e68c9928454e3fc2b |
|
MD5 | 174977d79ae0474221e7241e75219403 |
|
BLAKE2b-256 | af400c762deb1395028b1432056b2a4b5deb72195cae0b3fcd55e8d004de0564 |
File details
Details for the file unsplash_rand_downloader-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: unsplash_rand_downloader-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.20.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81586103ff842a1440f3b39fd53ac4ed9c9f4a2080ca3582940499deae5c0b45 |
|
MD5 | 2bf855a39603acd3c214c090945efcce |
|
BLAKE2b-256 | bfe75112d3034955e413872f95ea96666c40e60b46dfe5199ff796fdd3002f0b |