2023-11-11 23:18:19 +05:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
source .env
|
2023-11-11 23:49:41 +05:00
|
|
|
|
|
|
|
while true; do
|
|
|
|
|
2023-11-11 23:18:19 +05:00
|
|
|
date=$(date "+%Y%m%d_%H%M%S")
|
|
|
|
image=data/image_$date.png
|
2023-11-12 11:43:10 +05:00
|
|
|
speedtest_ookla=data/speedtest_ookla_$date.json
|
|
|
|
speedtest_fast=data/speedtest_fast_$date.json
|
2023-11-11 23:18:19 +05:00
|
|
|
weather_file=data/weather_$date.json
|
2023-11-11 23:45:57 +05:00
|
|
|
edited_image=data/edited_image_$date.png
|
2023-11-11 23:18:19 +05:00
|
|
|
|
|
|
|
#################################################################################
|
2023-11-12 00:02:47 +05:00
|
|
|
echo Grabbing Image
|
2023-11-11 23:18:19 +05:00
|
|
|
# Capture a frame from RTSP stream
|
2023-11-12 09:44:20 +05:00
|
|
|
mpv $RTSP_URL --frames=1 --vo=image --ovc=png --o=$image >> /dev/null
|
2023-11-12 00:02:47 +05:00
|
|
|
echo Image grabbed
|
2023-11-11 23:18:19 +05:00
|
|
|
#################################################################################
|
|
|
|
|
|
|
|
#################################################################################
|
2023-11-12 11:43:10 +05:00
|
|
|
echo Doing speedtest by Ookla
|
2023-11-11 23:18:19 +05:00
|
|
|
# Run speedtest and output to a file
|
2023-11-12 11:43:10 +05:00
|
|
|
speedtest --json > $speedtest_ookla
|
2023-11-11 23:18:19 +05:00
|
|
|
# Extract information from the speedtest output
|
2023-11-12 10:56:47 +05:00
|
|
|
|
|
|
|
# Parsing JSON data
|
2023-11-12 11:43:10 +05:00
|
|
|
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")
|
2023-11-12 10:56:47 +05:00
|
|
|
|
|
|
|
# Converting download and upload speeds from bytes per second to Mbit/s
|
2023-11-12 11:43:10 +05:00
|
|
|
ookla_download_mbps=$(echo "scale=4; $download / 1000000" | bc)
|
|
|
|
ookla_upload_mbps=$(echo "scale=4; $upload / 1000000" | bc)
|
2023-11-12 10:56:47 +05:00
|
|
|
|
|
|
|
# Converting bytes to MB
|
2023-11-12 11:43:10 +05:00
|
|
|
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")
|
2023-11-12 10:56:47 +05:00
|
|
|
|
2023-11-12 00:02:47 +05:00
|
|
|
echo Speedtest complete
|
2023-11-11 23:18:19 +05:00
|
|
|
#################################################################################
|
|
|
|
|
|
|
|
#################################################################################
|
2023-11-12 00:02:47 +05:00
|
|
|
echo Checking weather
|
2023-11-11 23:18:19 +05:00
|
|
|
# Make the API request
|
2023-11-11 23:24:02 +05:00
|
|
|
curl -s "https://api.open-meteo.com/v1/forecast?latitude=${LATITUDE}&longitude=${LONGITUDE}¤t_weather=true" > $weather_file
|
2023-11-11 23:18:19 +05:00
|
|
|
# Extract Weather Condition
|
|
|
|
weather_condition=$(cat $weather_file | jq '.current_weather.weathercode')
|
|
|
|
case $weather_condition in
|
2023-11-11 23:24:02 +05:00
|
|
|
0) current_weather="☀️ Clear sky" ;;
|
|
|
|
1|2|3) current_weather="☁️ Cloudy" ;;
|
|
|
|
45|48) current_weather="🌫️ Fog" ;;
|
|
|
|
51|53|55|56|57) current_weather="🌧️ Drizzle" ;;
|
|
|
|
61|63|65|66|67) current_weather="🌦️ Rain" ;;
|
|
|
|
80|81|82) current_weather="🌧️ Rain showers" ;;
|
|
|
|
85|86) current_weather="🌨️ Snow showers" ;;
|
|
|
|
95|96|99) current_weather="⛈️ Thunderstorm" ;;
|
2023-11-11 23:18:19 +05:00
|
|
|
*) current_weather="🌐 Weather condition not recognized" ;;
|
|
|
|
esac
|
2023-11-12 00:02:47 +05:00
|
|
|
echo Weather checked
|
2023-11-11 23:18:19 +05:00
|
|
|
#################################################################################
|
|
|
|
|
|
|
|
#################################################################################
|
|
|
|
caption="
|
|
|
|
$current_weather
|
|
|
|
|
2023-11-12 11:43:10 +05:00
|
|
|
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
|
2023-11-11 23:18:19 +05:00
|
|
|
"
|
|
|
|
#################################################################################
|
|
|
|
|
2023-11-11 23:45:57 +05:00
|
|
|
#################################################################################
|
|
|
|
#convert "$image" \
|
|
|
|
# -gravity South \
|
|
|
|
# -font $PWD/JoyPixels.ttf \
|
|
|
|
# -pointsize 20 \
|
|
|
|
# -annotate +0+10 "$caption" \
|
|
|
|
# $edited_image
|
|
|
|
#################################################################################
|
|
|
|
|
2023-11-11 23:18:19 +05:00
|
|
|
#################################################################################
|
2023-11-12 00:02:47 +05:00
|
|
|
echo Uploading to Telegram
|
2023-11-11 23:18:19 +05:00
|
|
|
curl -X POST https://api.telegram.org/bot$TG_BOT_API_KEY/sendPhoto \
|
|
|
|
-F chat_id=$TG_CHANNEL_ID \
|
|
|
|
-F photo=@$image \
|
|
|
|
-F caption="$caption" \
|
2023-11-12 00:02:47 +05:00
|
|
|
-F parse_mode=Markdown >> /dev/null
|
2023-11-11 23:18:19 +05:00
|
|
|
#################################################################################
|
2023-11-12 00:19:34 +05:00
|
|
|
echo Ok done, Sleeping for $DELAY
|
2023-11-11 23:49:41 +05:00
|
|
|
sleep $DELAY
|
|
|
|
|
|
|
|
done
|