configuration.nix/bin/bingwp

34 lines
763 B
Plaintext
Raw Normal View History

#!/usr/bin/env nu
let today = (date now | format date '%Y-%m-%d')
let bg_dir = (xdg-user-dir PICTURES) | path join "bg"
let today_img_file = $bg_dir | path join ([$today, ".png"] | str join)
let is_new = ((date now | format date "%H" | into int) >= 10)
mkdir $bg_dir
def exists [file: path] {
return ($file | path exists)
}
def is_empty [file: path] {
return ((exists $file) and ((ls $file | get size | first | into int) == 0))
2023-12-25 18:56:16 +01:00
}
def fetch [] {
curl ("https://bing.com" + ((curl "https://www.bing.com/HPImageArchive.aspx?format=js&n=1" | from json).images.0.url)) --output $today_img_file
2023-11-14 20:21:12 +01:00
}
def cleanup [] {
if (is_empty $today_img_file) {
rm -rf $today_img_file
}
}
cleanup
if $is_new and (not (exists $today_img_file)) {
fetch
}
2023-11-04 12:48:07 +01:00
cleanup