2024-02-01 15:59:16 +01:00
|
|
|
#!/usr/bin/env nu
|
|
|
|
|
|
|
|
let today = (date now | format date '%Y-%m-%d')
|
2024-02-17 10:11:42 +01:00
|
|
|
let pic_dir = (xdg-user-dir PICTURES)
|
|
|
|
let bg_dir = $pic_dir | path join "bg"
|
|
|
|
let today_img_file = $bg_dir | path join ( [ $today, ".png" ] | str join )
|
2024-02-01 15:59:16 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2024-02-01 15:59:16 +01:00
|
|
|
def fetch [] {
|
2024-04-04 10:09:22 +02:00
|
|
|
http get ("https://bing.com" + ((http get https://www.bing.com/HPImageArchive.aspx?format=js&n=1).images.0.url)) | save $today_img_file
|
2023-11-14 20:21:12 +01:00
|
|
|
}
|
|
|
|
|
2024-02-01 15:59:16 +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
|
2024-02-17 10:11:42 +01:00
|
|
|
/run/current-system/sw/bin/ln -sf $today_img_file ( $pic_dir | path join "bg.png" )
|
2024-02-01 15:59:16 +01:00
|
|
|
}
|
2023-11-04 12:48:07 +01:00
|
|
|
|
2024-02-01 15:59:16 +01:00
|
|
|
cleanup
|