Ivan Dimitrov
1642dde323
Squashed commit of the following: commit a8683efbd6a90b242f19a7f7527801cbabc600cc Author: Ivan Dimitrov <ivan@idimitrov.dev> Date: Thu Feb 1 16:50:57 2024 +0200 service config commit c15c55f09c3915b1505052c51a8a471861691fba Author: Ivan Dimitrov <ivan@idimitrov.dev> Date: Thu Feb 1 16:38:03 2024 +0200 replace original bingwp with nushell v commit d67d4832b0fb22aed660dafe2d6a52da1cc17e6f Author: Ivan Dimitrov <ivan@idimitrov.dev> Date: Thu Feb 1 16:34:10 2024 +0200 working bingwp in nushell commit 5c5e52a0ea2b749d1ca9233d02388918a8752f79 Author: Ivan Dimitrov <ivan@idimitrov.dev> Date: Mon Jan 29 08:09:22 2024 +0000 initial
34 lines
763 B
Plaintext
Executable File
34 lines
763 B
Plaintext
Executable File
#!/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))
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
def cleanup [] {
|
|
if (is_empty $today_img_file) {
|
|
rm -rf $today_img_file
|
|
}
|
|
}
|
|
|
|
cleanup
|
|
|
|
if $is_new and (not (exists $today_img_file)) {
|
|
fetch
|
|
}
|
|
|
|
cleanup
|