menherahair on Nostr: 翠星石 mangeurdenuage :gnu: :trisquel: :gondola_head: 🌿 :abeshinzo: :ignutius: ...
翠星石 (nprofile…vqps) mangeurdenuage :gnu: :trisquel: :gondola_head: 🌿 :abeshinzo: :ignutius: :descartes: :stargate: (nprofile…y2fr) I haven't even noticed bitcoin is already coded with this api in the provided script, since the "BTC" abbreviation doesn't work... seems the code hasn't been touched in years: https://salsa.debian.org/debian/units/-/blob/74a4a3302809e63a2cec951c358adc8505608213/units_cur#L553
>The issue is finding a non-proprietary, long term API where the exchange rate can be downloaded from.
I've been using cryptocompare.com in a years old script I found somewhere. I hacked it into the upstream python script but it sucks, I'll figure out how to make the thing accommodate crypto better and try to get a proper implementation merged some other time.
For a good hack it's easier to have another script appending the additional units like you kinda suggested, and chain it with the first one in a third one or the cronjob.
```
#!/usr/bin/env bash
base=USD
coins=(XMR BTC)
main() {
for coin in "${coins[@]}"; do
printf "%-20s %s %s\n" \
"$coin" \
$(curl -qs "https://min-api.cryptocompare.com/data/price?fsym=$coin&tsyms=$base"; | awk -F"[\"}{:]" '{print $5}') \
"$base"
done
}
tee -a /var/lib/units/currency.units << eof
# Cryptocurrencies
$(main "$@")
eof
```
The BTC here is of course somewhat redundant with the upstream script, but it hopefully shows how anyone looking can configure in whatever other coins they want.
>The issue is finding a non-proprietary, long term API where the exchange rate can be downloaded from.
I've been using cryptocompare.com in a years old script I found somewhere. I hacked it into the upstream python script but it sucks, I'll figure out how to make the thing accommodate crypto better and try to get a proper implementation merged some other time.
For a good hack it's easier to have another script appending the additional units like you kinda suggested, and chain it with the first one in a third one or the cronjob.
```
#!/usr/bin/env bash
base=USD
coins=(XMR BTC)
main() {
for coin in "${coins[@]}"; do
printf "%-20s %s %s\n" \
"$coin" \
$(curl -qs "https://min-api.cryptocompare.com/data/price?fsym=$coin&tsyms=$base"; | awk -F"[\"}{:]" '{print $5}') \
"$base"
done
}
tee -a /var/lib/units/currency.units << eof
# Cryptocurrencies
$(main "$@")
eof
```
The BTC here is of course somewhat redundant with the upstream script, but it hopefully shows how anyone looking can configure in whatever other coins they want.