Scripts: Prevent rate limit on polybar btc module with multi-monitor
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
file="/tmp/polybar-btc-module"
|
||||||
|
|
||||||
# Enable mathematics in POSIX shell
|
# Enable mathematics in POSIX shell
|
||||||
calc() { awk "BEGIN { printf(\"%.2f\", $*) }"; }
|
calc() { awk "BEGIN { printf(\"%.2f\", $*) }"; }
|
||||||
|
|
||||||
@@ -40,7 +42,7 @@ url_last_week="${url}/history?interval=h1&start=${date_last_week_start}&end=${da
|
|||||||
# Current price
|
# Current price
|
||||||
data="$(data "$url")"
|
data="$(data "$url")"
|
||||||
data_first_character="$(echo "$data" | cut -c 1)"
|
data_first_character="$(echo "$data" | cut -c 1)"
|
||||||
if [ "$data_first_character" != "{" ]; then echo "rate limit"; exit; fi
|
if [ "$data_first_character" != "{" ]; then cat "$file"; exit; fi
|
||||||
price="$(echo "$data" | jq --compact-output --raw-output '.data.priceUsd')"
|
price="$(echo "$data" | jq --compact-output --raw-output '.data.priceUsd')"
|
||||||
price=$(calc "$price")
|
price=$(calc "$price")
|
||||||
|
|
||||||
@@ -51,7 +53,7 @@ difference_yesterday="$(calc "$difference_yesterday")"
|
|||||||
# Get last weeks difference
|
# Get last weeks difference
|
||||||
data_last_week="$(data "$url_last_week")"
|
data_last_week="$(data "$url_last_week")"
|
||||||
data_last_week_first_character="$(echo "$data_last_week" | cut -c 1)"
|
data_last_week_first_character="$(echo "$data_last_week" | cut -c 1)"
|
||||||
if [ "$data_last_week_first_character" != "{" ]; then echo "rate limit"; exit; fi
|
if [ "$data_last_week_first_character" != "{" ]; then cat "$file"; exit; fi
|
||||||
price_last_week="$(echo "$data_last_week" | jq --compact-output --raw-output '.data[0].priceUsd')"
|
price_last_week="$(echo "$data_last_week" | jq --compact-output --raw-output '.data[0].priceUsd')"
|
||||||
difference_last_week=$(calc "$price / $price_last_week * 100 - 100")
|
difference_last_week=$(calc "$price / $price_last_week * 100 - 100")
|
||||||
|
|
||||||
@@ -59,4 +61,5 @@ difference_last_week=$(calc "$price / $price_last_week * 100 - 100")
|
|||||||
difference_yesterday_output="d $(output "$difference_yesterday")"
|
difference_yesterday_output="d $(output "$difference_yesterday")"
|
||||||
difference_last_week_output="w $(output "$difference_last_week")"
|
difference_last_week_output="w $(output "$difference_last_week")"
|
||||||
|
|
||||||
|
echo "\$$price $difference_yesterday_output $difference_last_week_output" > "$file"
|
||||||
echo "\$$price $difference_yesterday_output $difference_last_week_output"
|
echo "\$$price $difference_yesterday_output $difference_last_week_output"
|
||||||
|
|||||||
Reference in New Issue
Block a user