Feature request: sorting parameter when getting collections

Posts: 3 · Views: 66
  • 24981

    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.

  • 24983

    this is an inefficient workaround, but get all the wallpaper ids of your collection and do a random selection on that

  • 24984

    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:

    1. This results in multiple calls once instead of 1 call multiple times. Instead of 1 call returning 24 results and you tossing out 23 of them, you use every result. Sure the server can handle the load of 1 call every hour, but every little bit helps right?
    2. If you cache the list locally, you can randomly sort it, and then use it a queue. That way you get a random result but without duplicates, because you dequeue the wallpaper you use. If you get a random one from the API every time, you'll probably get repeats.
    3. After the first call to the API to retrieve the list, subsequent calls will be much faster because it just references the cached list. So no API delay until you need to refresh the list.

    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.

    Last updated

Message