fetch from server

This commit is contained in:
Ivan Kirilov Dimitrov 2024-07-07 19:35:01 +02:00
parent e6313d810d
commit 21e17fefa2
No known key found for this signature in database
GPG Key ID: 0BDAD4B211C49294

View File

@ -19,39 +19,7 @@ top@{ inputs, ... }: {
extraPlugins = with pkgs.vimPlugins; [ otter-nvim ];
};
bingwp = pkgs.writers.writeNuBin "bingwp" ''
let today = (date now | format date '%Y-%m-%d')
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
http get "https://pic.idimitrov.dev/latest.png" | save ([(xdg-user-dir PICTURES), "bg.png"] | str join "/")
'';
screenshot = pkgs.writers.writeNuBin "screenshot" ''
let tmp_img = "/tmp/screen.png" | path join