Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Unsplash collections #15

Merged
merged 1 commit into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Venus can be configured for specific search terms to get a category of images.
Edit the config file located in:

```
~.config/venus/config
~/.config/venus/config
```

By default, the search terms are empty, which means the image selection will be random. To choose what kind of images you want, enter search terms separated by commas.
Expand All @@ -70,6 +70,13 @@ Here is an example:
SEARCH_TERMS = landscape,nature,car
```

To get images of a specific Unsplash [collection](https://unsplash.com/collections), use its id:

```
COLLECTION_ID = 1053828
```
> Note: If `COLLECTION_ID` is set, the `SEARCH_TERMS` is ignored.

By default all images are stored as temporary files in the temp directory of the operating system. To change the location where the images are stored, edit the OUTPUT_PATH option.


Expand Down
13 changes: 10 additions & 3 deletions venus/venus.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import glob


def get_wall(resolution="1920x1080", search_term=None, output_path=None):
def get_wall(resolution="1920x1080", search_term=None, output_path=None, collection_id=None):
"""
This method downloads a random wallpaper to use from unsplash. The file is
saved to a temporary file so it can be taken care of by the operating
Expand All @@ -18,7 +18,12 @@ def get_wall(resolution="1920x1080", search_term=None, output_path=None):
:return - the picture file retrieved
"""

base_url = 'https://source.unsplash.com/' + resolution + '/?' + search_term
# If collection_id is empty, then get images based on search_term
if collection_id == '':
base_url = 'https://source.unsplash.com/' + resolution + '/?' + search_term
# Get images from a collection
else:
base_url = 'https://source.unsplash.com/collection/' + collection_id + '/' + resolution

r = requests.get(base_url)

Expand Down Expand Up @@ -65,6 +70,7 @@ def main():
cache_items_config = config.get('SETTINGS', 'CACHE_ITEMS', fallback=0)
use_pywal_config = config.getboolean(
'SETTINGS', 'USE_PYWAL', fallback=False)
collection_id_config = config.get('SETTINGS', 'COLLECTION_ID', fallback='')

# default path for empty OUTPUT_PATH setting
if not output_path_config:
Expand All @@ -81,7 +87,8 @@ def main():

system.set_wall(get_wall(resolution=screen_resolution_config,
search_term=search_term_config,
output_path=output_path_config), use_pywal_config)
output_path=output_path_config,
collection_id=collection_id_config), use_pywal_config)
if cache_items_config and output_path_config:
cacheFiles = glob.glob(output_path_config+"/*")
cacheFiles.sort(key=os.path.getmtime, reverse=True)
Expand Down