146 lines
6.0 KiB
Bash
Executable File
146 lines
6.0 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
source .env
|
|
|
|
while true; do
|
|
|
|
date=$(date "+%Y%m%d_%H%M%S")
|
|
camera_image=data/image_$date.png
|
|
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
|
|
weather_file=data/weather_$date.json
|
|
edited_image=data/edited_image_$date.png
|
|
|
|
#################################################################################
|
|
echo Grabbing Camara Image
|
|
# Capture a frame from RTSP stream
|
|
mpv $RTSP_URL --frames=1 --vo=image --ovc=png --o=$camera_image >> /dev/null
|
|
echo Camera Image grabbed
|
|
#################################################################################
|
|
|
|
#################################################################################
|
|
echo Grabbing Satellite Image
|
|
# scrap html and get image link
|
|
satellite_image_url=$(curl "https://www.meteorology.gov.mv/" -s | \
|
|
grep -o 'https://mobile.codeworks.mv/uploads/Satellite/[^"]*' | \
|
|
tail -n 1)
|
|
# Download the Setellite Image
|
|
curl $satellite_image_url -o $satellite_image
|
|
echo Satellite Image grabbed
|
|
#################################################################################
|
|
|
|
#################################################################################
|
|
echo Doing speedtest by Ookla
|
|
# Run speedtest and output to a file
|
|
speedtest --json > $speedtest_ookla
|
|
# Extract information from the speedtest output
|
|
|
|
# Parsing JSON data
|
|
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")
|
|
ookla_bytes_received=$(jq '.bytes_received' "$speedtest_ookla")
|
|
ookla_bytes_sent=$(jq '.bytes_sent' "$speedtest_ookla")
|
|
|
|
# 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)
|
|
ookla_bytes_received_mb=$(echo "scale=2; $ookla_bytes_received / 1048576" | bc)
|
|
ookla_bytes_sent_mb=$(echo "scale=2; $ookla_bytes_sent / 1048576" | bc)
|
|
|
|
echo Starting LibreSpeed
|
|
librespeed-cli --json > $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")
|
|
|
|
# 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)
|
|
|
|
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")
|
|
|
|
echo Speedtests complete
|
|
#################################################################################
|
|
|
|
#################################################################################
|
|
echo Checking weather
|
|
# Make the API request
|
|
curl -s "https://api.open-meteo.com/v1/forecast?latitude=${LATITUDE}&longitude=${LONGITUDE}¤t_weather=true" > $weather_file
|
|
# Extract Weather Condition
|
|
weather_condition=$(cat $weather_file | jq '.current_weather.weathercode')
|
|
case $weather_condition in
|
|
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" ;;
|
|
*) current_weather="🌐 Weather condition not recognized" ;;
|
|
esac
|
|
echo Weather checked
|
|
#################################################################################
|
|
|
|
#################################################################################
|
|
caption="
|
|
$current_weather
|
|
|
|
*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*: $libre_server_name
|
|
🏓 *Latency*: $libre_ping ms
|
|
⬇️ *Download*: $libre_download Mbit/s, Used: $libre_bytes_received_mb MB
|
|
⬆️ *Upload*: 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*: Upload: $fast_upload_speed Mbit/s, Used: $fast_uploaded 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
|
|
#################################################################################
|
|
echo Ok done, Sleeping for $DELAY
|
|
sleep $DELAY
|
|
|
|
done
|