optimize finanz
This commit is contained in:
parent
133ef070a4
commit
e61ac41bee
1 changed files with 27 additions and 34 deletions
|
@ -22,41 +22,34 @@ let
|
||||||
|
|
||||||
in {
|
in {
|
||||||
|
|
||||||
systemd.services = let
|
systemd.services.pull_stocks = {
|
||||||
pullService = { name, symbol, currency, friendly_name, ... }: {
|
enable = true;
|
||||||
name = "pull_stock_${friendly_name}";
|
description = "pull stocks for hledger";
|
||||||
value = {
|
serviceConfig = {
|
||||||
enable = true;
|
User = "syncthing";
|
||||||
description = "pull stock_${friendly_name} for hledger";
|
Type = "oneshot";
|
||||||
serviceConfig = {
|
|
||||||
User = "syncthing";
|
|
||||||
Type = "oneshot";
|
|
||||||
};
|
|
||||||
script = ''
|
|
||||||
SYMBOL="${symbol}"
|
|
||||||
APIKEY=${lib.fileContents <secrets/finance/alphavantage/apikey>}
|
|
||||||
${pkgs.curl}/bin/curl --location --silent \
|
|
||||||
"https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=$SYMBOL&apikey=$APIKEY" \
|
|
||||||
| ${pkgs.jq}/bin/jq --raw-output '.["Global Quote"]
|
|
||||||
| "P \(.["07. latest trading day"]) ${name} ${currency}\(.["05. price"] | tonumber)"' \
|
|
||||||
>> ${stocksFile}
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
in builtins.listToAttrs (map pullService stocks);
|
|
||||||
|
|
||||||
systemd.timers = let
|
script = let
|
||||||
pullTimer = { friendly_name, ... }: {
|
command = { symbol, name, currency, ... }: ''
|
||||||
name = "pull_stock_${friendly_name}";
|
APIKEY=${lib.fileContents <secrets/finance/alphavantage/apikey>}
|
||||||
value = {
|
SYMBOL="${symbol}"
|
||||||
enable = true;
|
${pkgs.curl}/bin/curl --location --silent \
|
||||||
wantedBy = [ "multi-user.target" ];
|
"https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=$SYMBOL&apikey=$APIKEY" \
|
||||||
timerConfig = {
|
| ${pkgs.jq}/bin/jq --raw-output '.["Global Quote"]
|
||||||
OnCalendar = "weekly";
|
| "P \(.["07. latest trading day"]) ${name} ${currency}\(.["05. price"] | tonumber)"' \
|
||||||
Persistent = "true";
|
>> ${stocksFile}
|
||||||
};
|
sleep 1
|
||||||
};
|
'';
|
||||||
|
in lib.concatStringsSep "\n" (map command stocks);
|
||||||
|
};
|
||||||
|
|
||||||
|
systemd.timers.pull_stocks = {
|
||||||
|
enable = true;
|
||||||
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
timerConfig = {
|
||||||
|
OnCalendar = "weekly";
|
||||||
|
Persistent = "true";
|
||||||
};
|
};
|
||||||
in builtins.listToAttrs (map pullTimer stocks);
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue