Compare commits

..

56 Commits

Author SHA1 Message Date
ae44bf94b0 fix build, enaled libre and ookla 2023-12-30 10:32:47 +05:00
71095eb629 highest value instead of averae 2023-11-28 02:32:07 +05:00
ef5d9031e3 better null handling 2023-11-28 02:22:01 +05:00
99951c1fb3 disable ookla and libre 2023-11-28 02:06:46 +05:00
120fec0843 replace null values 2023-11-28 02:05:18 +05:00
361b91fad2 spit in a distance 2023-11-27 22:30:05 +05:00
b98e3b6d34 fix upload value 2023-11-27 22:28:59 +05:00
d143be1ed0 spit them out 2023-11-27 22:28:00 +05:00
a588e2807f add average download and upload to caption 2023-11-27 22:11:09 +05:00
d173d6904d enabled libre and fast, added average speed meter 2023-11-27 22:00:42 +05:00
6c96c6efb5 Merge pull request 'main' (#1) from ibattus/starlink_status:main into main
Reviewed-on: #1
2023-11-22 18:30:31 +05:00
b72f95407a added weather files 2023-11-22 17:54:07 +05:00
315a49fe57 added weather files 2023-11-22 17:53:57 +05:00
793310303b added weather files 2023-11-22 17:53:43 +05:00
e7448cf7be weather images 2023-11-22 17:53:18 +05:00
d4818361c2 Delete resources/tornado.png 2023-11-22 17:51:34 +05:00
95b055db9b Delete resources/thunder_cloud_and_rain.png 2023-11-22 17:51:29 +05:00
f10f8cb3e4 Delete resources/sweat_drops.png 2023-11-22 17:51:24 +05:00
d6bd88d23a Delete resources/sun.png 2023-11-22 17:51:20 +05:00
b69d6335ec Delete resources/snowflake.png 2023-11-22 17:51:15 +05:00
1a374005ef Delete resources/shower.png 2023-11-22 17:51:10 +05:00
e7944da8c7 Delete resources/snow_cloud.png 2023-11-22 17:51:04 +05:00
30f7ba26da Delete resources/rainbow.png 2023-11-22 17:50:59 +05:00
270874bac7 Delete resources/rain_cloud.png 2023-11-22 17:50:53 +05:00
f3a56b21c4 Delete resources/ocean.png 2023-11-22 17:50:47 +05:00
1b0e5ad2d2 Delete resources/partly_sunny_rain.png 2023-11-22 17:42:31 +05:00
bfe0a6e67a Delete resources/partly_sunny.png 2023-11-22 17:42:25 +05:00
0afade2057 Delete resources/needle.png 2023-11-22 17:42:20 +05:00
556fdc21cf Delete resources/mostly_sunny.png 2023-11-22 17:42:15 +05:00
70c69b036e Delete resources/lightning.png 2023-11-22 17:42:10 +05:00
782f224f7f Delete resources/globe_with_meridians.png 2023-11-22 17:42:06 +05:00
7ffc527e78 Delete resources/fog.png 2023-11-22 17:41:56 +05:00
5adf9e1dd1 Delete resources/droplet.png 2023-11-22 17:41:48 +05:00
7a785deac1 Delete resources/dash.png 2023-11-22 17:41:42 +05:00
6f24123e5d Delete resources/cyclone.png 2023-11-22 17:41:31 +05:00
02c6a11db9 Delete resources/crescent_moon.png 2023-11-22 17:41:26 +05:00
fd18087026 Delete resources/cloud.png 2023-11-22 17:41:21 +05:00
3e3bf5d5b8 Delete resources/christmas_tree.png 2023-11-22 17:41:16 +05:00
3daee5433a Delete resources/barely_sunny.png 2023-11-22 17:41:11 +05:00
337c8ac62f Delete resources/wind_blowing_face.png 2023-11-22 17:41:04 +05:00
973a34fecb Delete resources/zap.png 2023-11-22 17:40:55 +05:00
c0eb6ef02d Merge pull request 'added weather image resources' (#1) from ibattus-main into main
Reviewed-on: ibattus/starlink_status#1
2023-11-22 16:17:46 +05:00
46a9833d50 added weather image resources 2023-11-22 16:13:47 +05:00
9ca0c748b7 emoji png for weather 2023-11-22 14:52:43 +05:00
ce1e9bcff7 updated image to better handle text background color 2023-11-21 21:08:51 +05:00
b9aea5db34 added scale to image 2023-11-21 11:27:18 +05:00
61e055ee84 new image 2023-11-21 10:56:02 +05:00
fa6d73bf48 WHAT THE FUCK ITS UPLOAD 2023-11-21 10:52:52 +05:00
4beae61f76 white more readable 2023-11-21 10:48:25 +05:00
50c42090d4 customize meter scale, set new font style and color 2023-11-21 10:40:09 +05:00
c11d561bba customize scale and location of meter 2023-11-21 10:19:40 +05:00
0c81f7a1fe overlay speed result on image dependecy 2023-11-21 09:58:50 +05:00
3cc77a9ead overlay speed result on image 2023-11-21 09:57:13 +05:00
652c209fef update ignore 2023-11-21 06:24:31 +05:00
c35dfac2db rm 2023-11-14 01:03:20 +05:00
c6e4b5c26a slightly cleaner code 2023-11-14 01:02:32 +05:00
25 changed files with 136 additions and 53 deletions

View File

@@ -2,11 +2,14 @@ FROM archlinux
WORKDIR /root
# update all
RUN pacman -Syu --noconfirm
# Basic
RUN pacman -Sy --noconfirm mpv jq curl bc
RUN pacman -S --noconfirm mpv jq curl bc
# Ookla Speedtest
RUN pacman -Sy --noconfirm speedtest-cli
RUN pacman -S --noconfirm speedtest-cli
# LibreSpeed
RUN curl -LOJ https://github.com/librespeed/speedtest-cli/releases/download/v1.0.10/librespeed-cli_1.0.10_linux_amd64.tar.gz \
@@ -18,6 +21,9 @@ RUN curl -LOJ https://github.com/librespeed/speedtest-cli/releases/download/v1.0
RUN pacman -S --noconfirm atk cups libxcomposite nodejs npm nss \
&& npm install --global fast-cli
# Image Magic
RUN pacman -S --noconfirm imagemagick
COPY . .
CMD ./bot.sh

1
.gitignore vendored
View File

@@ -1 +1,2 @@
.env
tmp/

Binary file not shown.

169
bot.sh
View File

@@ -2,6 +2,11 @@
source .env
download_meter=resources/download_meter.png
upload_meter=resources/upload_meter.png
needle=resources/needle.png
font=resources/CODE_Bold.otf
while true; do
date=$(date "+%Y%m%d_%H%M%S")
@@ -10,9 +15,12 @@ satellite_image=data/satellite_image_$date.png
speedtest_ookla=data/speedtest_ookla_$date.json
speedtest_libre=data/speedtest_libre_$date.json
speedtest_fast=data/speedtest_fast_$date.json
speedtest_download_meter=data/speedtest_download_meter_$date.png
speedtest_upload_meter=data/speedtest_upload_meter_$date.png
speedtest_meter_image=data/speedtest_meter_image_$date.png
weather_file=data/weather_$date.json
edited_image=data/edited_image_$date.png
tg_log=data/tg_log_$date.json
#################################################################################
latency(){
echo $(ping -c 1 $1) | \
@@ -41,7 +49,7 @@ echo Satellite Image grabbed
#################################################################################
echo Doing speedtest by Ookla
# Run speedtest and output to a file
speedtest --json > $speedtest_ookla
speedtest --json | tee $speedtest_ookla
# Extract information from the speedtest output
# Parsing JSON data
@@ -54,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
[ -z "$ookla_ping" ] && ookla_ping="-"
[ -z "$ookla_download" ] && ookla_download=0
[ -z "$ookla_upload" ] && ookla_upload=0
[ -z "$ookla_bytes_received" ] && ookla_bytes_received=0
[ -z "$ookla_bytes_sent" ] && ookla_bytes_sent=0
# 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)
@@ -62,34 +77,51 @@ ookla_bytes_sent_mb=$(echo "scale=2; $ookla_bytes_sent / 1048576" | bc)
ookla_total=$(echo $ookla_bytes_sent_mb+$ookla_bytes_received_mb | bc)
#echo Starting LibreSpeed
#librespeed-cli --json > $speedtest_libre
echo Starting LibreSpeed
librespeed-cli --json | tee $speedtest_libre
# Parsing JSON data
#libre_bytes_sent=$(jq '.[0].bytes_sent' "$speedtest_libre")
#libre_bytes_received=$(jq '.[0].bytes_received' "$speedtest_libre")
#libre_ping=$(jq '.[0].ping' "$speedtest_libre")
#libre_upload=$(jq '.[0].upload' "$speedtest_libre")
#libre_download=$(jq '.[0].download' "$speedtest_libre")
#libre_server_name=$(jq -r '.[0].server.name' "$speedtest_libre")
libre_bytes_sent=$(jq '.[0].bytes_sent' "$speedtest_libre")
libre_bytes_received=$(jq '.[0].bytes_received' "$speedtest_libre")
libre_ping=$(jq '.[0].ping' "$speedtest_libre")
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
#libre_bytes_sent_mb=$(echo "scale=2; $libre_bytes_sent / 1048576" | bc)
#libre_bytes_received_mb=$(echo "scale=2; $libre_bytes_received / 1048576" | bc)
# replacing null values
[ "$libre_ping" = "null" ] || [ -z "$libre_ping" ] && libre_ping="-"
[ "$libre_download" = "null" ] || [ -z "$libre_download" ] && libre_download=0
[ "$libre_upload" = "null" ] || [ -z "$libre_upload" ] && libre_upload=0
[ "$libre_bytes_received" = "null" ] || [ -z "$libre_bytes_received" ] && libre_bytes_received=0
[ "$libre_bytes_sent" = "null" ] || [ -z "$libre_bytes_sent" ] && libre_bytes_sent=0
#libre_total=$(echo $libre_bytes_sent_mb+$libre_bytes_received_mb | bc)
# 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)
#echo Starting Fast
#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")
libre_total=$(echo $libre_bytes_sent_mb+$libre_bytes_received_mb | bc)
#fast_total=$(echo $fast_downloaded+$fast_uploaded | bc)
echo Starting Fast
fast --upload --json | tee $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")
total_wasted=$ookla_total
[ -z "$fast_latency" ] && fast_latency="-"
[ -z "$fast_download_speed" ] && fast_download_speed=0
[ -z "$fast_upload_speed" ] && fast_upload_speed=0
[ -z "$fast_downloaded" ] && fast_downloaded=0
[ -z "$fast_uploaded" ] && fast_uploaded=0
fast_total=$(echo $fast_downloaded+$fast_uploaded | bc)
average_download=$(echo $ookla_download_mbps+$libre_download+$fast_download_speed/3 | bc)
average_upload=$(echo $ookla_upload_mbps+$libre_upload+$fast_upload_speed/3| bc)
highest_download=$(echo $ookla_download_mbps $libre_download $fast_download_speed | tr ' ' '\n' | sort -nr | head -n1)
highest_upload=$(echo $ookla_upload_mbps $libre_upload $fast_upload_speed | tr ' ' '\n' | sort -nr | head -n1)
total_wasted=$(echo $ookla_total+$libre_total+$fast_total | bc)
echo Speedtests complete
#################################################################################
@@ -98,32 +130,21 @@ 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)
[ -z "$valorant_ping" ] && valorant_ping="-"
[ -z "$cfdns_ping" ] && cfdns_ping="-"
[ -z "$googledns_ping" ] && googledns_ping="-"
#################################################################################
#################################################################################
echo Checking weather
# Make the API request
curl -s "https://api.open-meteo.com/v1/forecast?latitude=${LATITUDE}&longitude=${LONGITUDE}&current_weather=true" > $weather_file
curl -s "https://api.open-meteo.com/v1/forecast?latitude=${LATITUDE}&longitude=${LONGITUDE}&current_weather=true" | tee $weather_file
# Extract Weather Condition and day or not
weather_condition=$(jq '.current_weather.weathercode' "$weather_file")
is_day=$(jq '.current_weather.is_day' "$weather_file")
case $weather_condition in
0)
if [ "$is_day" = "1" ]
then
current_weather="☀️ Clear Sky"
else
current_weather="🌙 Clear Sky"
fi
;;
1)
if [ "$is_day" = "1" ]
then
current_weather="☀️ Mainly Clear"
else
current_weather="🌙 Mainly Clear"
fi
;;
0) current_weather="$([ "$is_day" = "1" ] && echo "☀️" || echo "🌙") Clear Sky";;
1) current_weather="$([ "$is_day" = "1" ] && echo "☀️" || echo "🌙") Mainly Clear";;
2) current_weather="⛅ Partly Cloudy" ;;
3) current_weather="☁️ Overcast" ;;
45) current_weather="🌫️ Fog" ;;
@@ -155,6 +176,51 @@ esac
echo Weather checked
#################################################################################
#################################################################################
download_angle=$(echo "scale=2; -118 + ($highest_download - 0) / ($MAX_DOWNLOAD_SPEED - 0) * (118 - -118)" | bc)
upload_angle=$(echo "scale=2; -118 + ($highest_upload - 0) / ($MAX_UPLOAD_SPEED - 0) * (118 - -118)" | bc)
convert $download_meter \
\( $needle -background none \
-rotate $download_angle \) \
-gravity center \
-compose over \
-composite \
-pointsize 41 \
-font $font \
-fill white \
-annotate +0+-15 $highest_download \
-annotate +120+85 $MAX_DOWNLOAD_SPEED \
$speedtest_download_meter
convert $upload_meter \
\( $needle -background none \
-rotate $upload_angle \) \
-gravity center \
-compose over \
-composite \
-pointsize 41 \
-font $font \
-fill white \
-annotate +0+-15 $highest_upload \
-annotate +120+85 $MAX_UPLOAD_SPEED \
$speedtest_upload_meter
convert $camera_image \
\( $speedtest_download_meter \
-resize $METER_SCALE% \
-gravity southwest \
-geometry +10+0 \) \
-composite \
\( $speedtest_upload_meter \
-resize $METER_SCALE% \
-gravity southwest \
-geometry +$UPLOAD_METER_LOCATION+0 \) \
-composite \
$speedtest_meter_image
#################################################################################
#################################################################################
caption="
$current_weather
@@ -169,27 +235,28 @@ $current_weather
⬇️ *Download*: $ookla_download_mbps Mbit/s, Used: $ookla_bytes_received_mb MB
⬆️ *Upload*: $ookla_upload_mbps Mbit/s, Used: $ookla_bytes_sent_mb MB
*LibreSpeed*:
🌐 *Server*: $libre_server_name
🏓 *Latency*: $libre_ping ms
⬇️ *Download*: $libre_download Mbit/s, Used: $libre_bytes_received_mb MB
⬆️ *Upload*: $libre_upload Mbit/s, Used $libre_bytes_sent_mb MB
*Fast Powered by Netflix*:
🏓 *Latency*: $fast_latency ms
⬇️ *Download*: $fast_download_speed Mbit/s, Used: $fast_downloaded MB
⬆️ *Upload*: $fast_upload_speed Mbit/s, Used: $fast_uploaded MB
Total data wasted: $total_wasted MB
"
#################################################################################
#################################################################################
#convert "$camera_image" \
# -gravity South \
# -font $PWD/JoyPixels.ttf \
# -pointsize 20 \
# -annotate +0+10 "$caption" \
# $edited_image
#################################################################################
#################################################################################
echo Uploading to Telegram
curl -X POST https://api.telegram.org/bot$TG_BOT_TOKEN/sendMediaGroup \
-F chat_id=$TG_CHATID \
-F media='[{"type": "photo", "media": "attach://photo1", "caption": "'"$caption"'", "parse_mode": "Markdown"}, {"type": "photo", "media": "attach://photo2"}]' \
-F photo1=@$camera_image \
-F photo2=@$satellite_image >> /dev/null
-F photo1=@$speedtest_meter_image \
-F photo2=@$satellite_image | tee $tg_log
#################################################################################
echo Ok done, Sleeping for $DELAY

View File

@@ -15,3 +15,12 @@ RTSP_URL=rtsp://
# Use some maps service to fetch this, this is used to fetch weather from API. (Default is Male', Maldives)
LATITUDE="4.1752"
LONGITUDE="73.5092"
# Change these as you see fit based on RTSP image resolution
UPLOAD_METER_LOCATION=510 # in px starting from download meter start
METER_SCALE=100 # in percentage
# Change meter scale in Mbps
MAX_DOWNLOAD_SPEED=300
MAX_UPLOAD_SPEED=50

BIN
resources/CODE_Bold.otf Normal file

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

BIN
resources/cloud.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
resources/crescent_moon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
resources/droplet.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

BIN
resources/needle.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

BIN
resources/rainbow.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

BIN
resources/snowflake.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

BIN
resources/sun.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

BIN
resources/upload_meter.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

BIN
resources/wind-face.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB