refactor speedtest, added support for fast
This commit is contained in:
parent
73675b8532
commit
73c61a98d6
@ -1,7 +1,8 @@
|
||||
FROM archlinux
|
||||
|
||||
WORKDIR /root
|
||||
RUN pacman -Sy --noconfirm mpv jq curl speedtest-cli
|
||||
RUN pacman -Sy --noconfirm mpv jq curl speedtest-cli bc npm \
|
||||
&& npm install --global fast-cli
|
||||
|
||||
COPY . .
|
||||
|
||||
|
59
bot.sh
59
bot.sh
@ -6,7 +6,8 @@ while true; do
|
||||
|
||||
date=$(date "+%Y%m%d_%H%M%S")
|
||||
image=data/image_$date.png
|
||||
speedtest_result=data/speedtest_$date.txt
|
||||
speedtest_ookla=data/speedtest_ookla_$date.json
|
||||
speedtest_fast=data/speedtest_fast_$date.json
|
||||
weather_file=data/weather_$date.json
|
||||
edited_image=data/edited_image_$date.png
|
||||
|
||||
@ -18,28 +19,36 @@ echo Image grabbed
|
||||
#################################################################################
|
||||
|
||||
#################################################################################
|
||||
echo Doing speedtest
|
||||
echo Doing speedtest by Ookla
|
||||
# Run speedtest and output to a file
|
||||
speedtest --json > $speedtest_result
|
||||
speedtest --json > $speedtest_ookla
|
||||
# Extract information from the speedtest output
|
||||
|
||||
# Parsing JSON data
|
||||
download=$(jq '.download' "$speedtest_result")
|
||||
upload=$(jq '.upload' "$speedtest_result")
|
||||
ping=$(jq '.ping' "$speedtest_result")
|
||||
bytes_received=$(jq '.bytes_received' "$speedtest_result")
|
||||
bytes_sent=$(jq '.bytes_sent' "$speedtest_result")
|
||||
isp=$(jq -r '.client.isp' "$speedtest_result")
|
||||
country=$(jq -r '.client.country' "$speedtest_result")
|
||||
cc=$(jq -r '.client.cc' "$speedtest_result")
|
||||
ookla_server=$(jq -r '.server.sponsor' "$speedtest_ookla")
|
||||
ookla_city=$(jq -r '.server.name' "$speedtest_ookla")
|
||||
ookla_country=$(jq -r '.server.country' "$speedtest_ookla")
|
||||
ookla_ping=$(jq '.ping' "$speedtest_ookla")
|
||||
ookla_download=$(jq '.download' "$speedtest_ookla")
|
||||
ookla_upload=$(jq '.upload' "$speedtest_ookla")
|
||||
ooka_bytes_received=$(jq '.bytes_received' "$speedtest_ookla")
|
||||
ooka_bytes_sent=$(jq '.bytes_sent' "$speedtest_ookla")
|
||||
|
||||
# Converting download and upload speeds from bytes per second to Mbit/s
|
||||
download_mbps=$(echo "scale=3; $download / 125000" | bc)
|
||||
upload_mbps=$(echo "scale=3; $upload / 125000" | bc)
|
||||
ookla_download_mbps=$(echo "scale=4; $download / 1000000" | bc)
|
||||
ookla_upload_mbps=$(echo "scale=4; $upload / 1000000" | bc)
|
||||
|
||||
# Converting bytes to MB
|
||||
bytes_received_mb=$(echo "scale=2; $bytes_received / 1048576" | bc)
|
||||
bytes_sent_mb=$(echo "scale=2; $bytes_sent / 1048576" | bc)
|
||||
ookla_bytes_received_mb=$(echo "scale=2; $bytes_received / 1048576" | bc)
|
||||
ookla_bytes_sent_mb=$(echo "scale=2; $bytes_sent / 1048576" | bc)
|
||||
|
||||
|
||||
fast --upload --json > $speedtest_fast
|
||||
fast_download_speed=$(jq '.downloadSpeed' "$speedtest_fast")
|
||||
fast_upload_speed=$(jq '.uploadSpeed' "$speedtest_fast")
|
||||
fast_latency=$(jq '.latency' "$speedtest_fast")
|
||||
fast_downloaded=$(jq '.downloaded' "$speedtest_fast")
|
||||
fast_uploaded=$(jq '.uploaded' "$speedtest_fast")
|
||||
|
||||
echo Speedtest complete
|
||||
#################################################################################
|
||||
@ -68,10 +77,22 @@ echo Weather checked
|
||||
caption="
|
||||
$current_weather
|
||||
|
||||
🌐 *ISP*: $isp, $country, $cc
|
||||
🏓 *Latency*: $ping ms
|
||||
⬇️ *Download*: $download_mbps Mbit/s, Used: $bytes_received_mb MB
|
||||
⬆️ *Upload*: Upload: $upload_mbps Mbit/s, Used: $bytes_sent_mb MB
|
||||
Speedtest by Ookla:
|
||||
🌐 *Server*: $ookla_server, $ookla_city, $ookla_country
|
||||
🏓 *Latency*: $ookla_ping ms
|
||||
⬇️ *Download*: $ookla_download_mbps Mbit/s, Used: $ookla_bytes_received_mb MB
|
||||
⬆️ *Upload*: Upload: $ookla_upload_mbps Mbit/s, Used: $ookla_bytes_sent_mb MB
|
||||
|
||||
LibreSpeed:
|
||||
🌐 *Server*:
|
||||
🏓 *Latency*: ms
|
||||
⬇️ *Download*: Mbit/s, Used: MB
|
||||
⬆️ *Upload*: Upload: Mbit/s, Used MB
|
||||
|
||||
Fast Powered by Netflix:
|
||||
🏓 *Latency*: $fast_latency ms
|
||||
⬇️ *Download*: $fast_download_speed Mbit/s, Used: $fast_downloaded MB
|
||||
⬆️ *Upload*: Upload: $fast_upload_speed Mbit/s, Used: $fast_uploaded MB
|
||||
"
|
||||
#################################################################################
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user