fetch from server
This commit is contained in:
parent
e6313d810d
commit
21e17fefa2
@ -19,39 +19,7 @@ top@{ inputs, ... }: {
|
|||||||
extraPlugins = with pkgs.vimPlugins; [ otter-nvim ];
|
extraPlugins = with pkgs.vimPlugins; [ otter-nvim ];
|
||||||
};
|
};
|
||||||
bingwp = pkgs.writers.writeNuBin "bingwp" ''
|
bingwp = pkgs.writers.writeNuBin "bingwp" ''
|
||||||
let today = (date now | format date '%Y-%m-%d')
|
http get "https://pic.idimitrov.dev/latest.png" | save ([(xdg-user-dir PICTURES), "bg.png"] | str join "/")
|
||||||
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 )
|
|
||||||
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 [] {
|
|
||||||
http get ("https://bing.com" + ((http get https://www.bing.com/HPImageArchive.aspx?format=js&n=1).images.0.url)) | save $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
|
|
||||||
/run/current-system/sw/bin/ln -sf $today_img_file ( $pic_dir | path join "bg.png" )
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup
|
|
||||||
'';
|
'';
|
||||||
screenshot = pkgs.writers.writeNuBin "screenshot" ''
|
screenshot = pkgs.writers.writeNuBin "screenshot" ''
|
||||||
let tmp_img = "/tmp/screen.png" | path join
|
let tmp_img = "/tmp/screen.png" | path join
|
||||||
|
Loading…
Reference in New Issue
Block a user