Hey there,
I was playing around with the API and wanted to try to basically get one random wallpaper from a collection every hour or so. But sorting=random doesn‘t work when used with the collection endpoint it seems.
Hey there,
I was playing around with the API and wanted to try to basically get one random wallpaper from a collection every hour or so. But sorting=random doesn‘t work when used with the collection endpoint it seems.
this is an inefficient workaround, but get all the wallpaper ids of your collection and do a random selection on that
if your collection doesn't change very often, you can cache the whole list locally and do the random selection from a local copy.
This actually can have a few advantages:
I've actually been doing this in a simple little bash script I wrote for my Ubuntu laptop. Not sure what you're using, but implementing a really simple cached list is pretty easy. You can just parse the JSON and store the list of paths in a file, then when you want a new wallpaper you pop the first line from the file and fetch that url.
Edit: Also forgot to mention - if your collection doesn't shrink often or ever, i.e. you don't remove wallpapers from it but only add, you can use the meta information in the first page to do a quick check if the collection has changed. Unfortunately there is no "last updated" field, but there is a count of the results. You can store that number locally in a file, and compare against it the next time. Then set up a scheduled job that updates the list in the middle of the night every 24 hours or once a week. Then you'll have a updated list ready to go all the time without manually running anything.
All images remain property of their original owners. Site & code © wallhaven.cc 2024. Privacy Policy · Terms of Service