Random image from Unsplash on click
#
In this simple example #CraftMath downloads a random image JSON from Unsplash using their APIs updating it everything
time a click is triggered
Tutorial
#
Video
#
Steps
#
First of all add a Widget (or a wallpaper or any other Kustom item), then:
- Register Unsplash account and request an API key
- Store API key as a “secret” or normal global, name it “key”
- Create a new text global, name it “json”
- Go to Flows, add a new Flow
- Add a “manual trigger” this will trigger the flow manually via touch
- Add an Action of type WebGet and use “
https://api.unsplash.com/photos/random?client_id=$gv(key)$" as URL
- Add an action to store to a Global, select “json” as the global, flow will download the JSON file and assign the
global to the local JSON file path (unless you switch “store file content not path” which will intead store the file
content in the global)
- Finally add an image, switch “Bitmap” to a formula and use $wg(gv(json), json, .urls.raw)$ to use the image url from
the json
- You are done
Random wallpaper daily from reddit.com/r/EarthPorn
#
Lets say you want to get a nice random image from the wonderful sub reddit at
https://reddit.com/r/EarthPorn
Nothing easier:
- Start a blank preset
- Go to the background tab
- Select the bitmap property
- Switch to a formula
- Enter this formula:
$tv(reg, wg("https://www.reddit.com/r/EarthPorn/.rss?refresh="+df(D), url, "i.redd.it", 0), "&.*", "")$
Save and done!
You can update this more frequently by changing for example df(D) to df(H) and it will be updated at the hour (if content changed)
...