replace null values

This commit is contained in:
Shihaam Abdul Rahman 2023-11-28 02:05:18 +05:00
parent 361b91fad2
commit 120fec0843
Signed by: shihaam
GPG Key ID: 6DA2E87EBC227636

25
bot.sh
View File

@ -62,6 +62,13 @@ ookla_upload=$(jq '.upload' "$speedtest_ookla")
ookla_bytes_received=$(jq '.bytes_received' "$speedtest_ookla")
ookla_bytes_sent=$(jq '.bytes_sent' "$speedtest_ookla")
# replacing null values
[ "$ookla_ping" = "" ] && ookla_ping="-" || ookla_ping=$ookla_ping
[ "$ookla_download" = "" ] && ookla_download=0 || ookla_download=$ookla_download
[ "$ookla_upload" = "" ] && ookla_upload=0 || ookla_upload=$ookla_upload
[ "$ookla_bytes_received" = "" ] && ookla_bytes_received=0 || ookla_bytes_received=$ookla_bytes_received
[ "$ookla_bytes_sent" = "" ] && ookla_bytes_sent=0 || ookla_bytes_sent=$ookla_bytes_sent
# Converting to human readable units
ookla_download_mbps=$(echo "scale=2; $ookla_download / 1000000" | bc)
ookla_upload_mbps=$(echo "scale=2; $ookla_upload / 1000000" | bc)
@ -81,7 +88,14 @@ libre_upload=$(jq '.[0].upload' "$speedtest_libre")
libre_download=$(jq '.[0].download' "$speedtest_libre")
libre_server_name=$(jq -r '.[0].server.name' "$speedtest_libre")
# Converting to human readable units
# replacing null values
[ "$libre_ping" = "null" ] && libre_ping="-" || libre_ping=$libre_ping
[ "$libre_download" = "null" ] && libre_download=0 || libre_download=$libre_download
[ "$libre_upload" = "null" ] && libre_upload=0 || libre_upload=$libre_upload
[ "$libre_bytes_received" = "null" ] && libre_bytes_received=0 || libre_bytes_received=$libre_bytes_received
[ "$libre_bytes_sent" = "null" ] && libre_bytes_sent=0 || libre_bytes_sent=$libre_bytes_sent
# Converting to human readable units and replacing null values with 0
libre_bytes_sent_mb=$(echo "scale=2; $libre_bytes_sent / 1048576" | bc)
libre_bytes_received_mb=$(echo "scale=2; $libre_bytes_received / 1048576" | bc)
@ -95,6 +109,12 @@ fast_latency=$(jq '.latency' "$speedtest_fast")
fast_downloaded=$(jq '.downloaded' "$speedtest_fast")
fast_uploaded=$(jq '.uploaded' "$speedtest_fast")
[ "$fast_latency" = "" ] && fast_latency="-" || fast_latency=$fast_latency
[ "$fast_download_speed" = "" ] && fast_download_speed=0 || fast_download_speed=$fast_download_speed
[ "$fast_upload_speed" = "" ] && fast_upload_speed=0 || fast_upload_speed=$fast_upload_speed
[ "$fast_downloaded" = "" ] && fast_downloaded=0 || fast_downloaded=$fast_downloaded
[ "fast_uploaded" = "" ] && fast_uploaded=0 || fast_uploaded=$fast_uploaded
fast_total=$(echo $fast_downloaded+$fast_uploaded | bc)
average_download=$(echo $ookla_download_mbps+$libre_download+$fast_download_speed/3 | bc)
@ -108,6 +128,9 @@ echo Speedtests complete
valorant_ping=$(latency dynamodb.ap-southeast-1.amazonaws.com)
cfdns_ping=$(latency 1.1.1.1)
googledns_ping=$(latency 8.8.8.8)
[ "$valorant_ping" = "" ] && valorant_ping="-" || valorant_ping=$valorant_ping
[ "$cfdns_ping" = "" ] && cfdns_ping="-" || cfdns_ping=$cfdns_ping
[ "$googledns_ping" = "" ] && googledns_ping="-" || googledns_ping=$valorant_ping
#################################################################################
#################################################################################