184 lines
7.5 KiB
Bash
Raw Normal View History

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")
2023-11-12 17:32:24 +05:00
camera_image=data/image_$date.png
satellite_image=data/satellite_image_$date.png
speedtest_ookla=data/speedtest_ookla_$date.json
2023-11-12 12:30:55 +05:00
speedtest_libre=data/speedtest_libre_$date.json
speedtest_fast=data/speedtest_fast_$date.json
2023-11-11 23:18:19 +05:00
weather_file=data/weather_$date.json
edited_image=data/edited_image_$date.png
2023-11-11 23:18:19 +05:00
2023-11-12 21:51:52 +05:00
#################################################################################
latency(){
echo $(ping -c 1 $1) | \
grep 'time=' | \
awk -F'time=' '{print $2}' | \
awk '{print $1}'
}
#################################################################################
2023-11-11 23:18:19 +05:00
#################################################################################
2023-11-12 17:32:24 +05:00
echo Grabbing Camara Image
2023-11-11 23:18:19 +05:00
# Capture a frame from RTSP stream
2023-11-12 17:32:24 +05:00
mpv $RTSP_URL --frames=1 --vo=image --ovc=png --o=$camera_image >> /dev/null
echo Camera Image grabbed
#################################################################################
#################################################################################
echo Grabbing Satellite Image
2023-11-12 20:34:56 +05:00
# scrap html, get image link and download it.
curl -s $(curl -s "https://www.meteorology.gov.mv/" | \
grep -o 'https://mobile.codeworks.mv/uploads/Satellite/[^"]*' | \
tail -n 1) -o $satellite_image
2023-11-12 17:32:24 +05:00
echo Satellite Image grabbed
2023-11-11 23:18:19 +05:00
#################################################################################
#################################################################################
echo Doing speedtest by Ookla
2023-11-11 23:18:19 +05:00
# Run speedtest and output to a file
speedtest --json > $speedtest_ookla
2023-11-11 23:18:19 +05:00
# 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")
2023-11-12 12:55:40 +05:00
ookla_bytes_received=$(jq '.bytes_received' "$speedtest_ookla")
ookla_bytes_sent=$(jq '.bytes_sent' "$speedtest_ookla")
2023-11-12 12:30:55 +05:00
# Converting to human readable units
2023-11-12 13:09:23 +05:00
ookla_download_mbps=$(echo "scale=2; $ookla_download / 1000000" | bc)
ookla_upload_mbps=$(echo "scale=2; $ookla_upload / 1000000" | bc)
2023-11-12 12:55:40 +05:00
ookla_bytes_received_mb=$(echo "scale=2; $ookla_bytes_received / 1048576" | bc)
ookla_bytes_sent_mb=$(echo "scale=2; $ookla_bytes_sent / 1048576" | bc)
2023-11-12 21:14:18 +05:00
ookla_total=$(echo $ookla_bytes_sent_mb+$ookla_bytes_received_mb | bc)
2023-11-13 11:19:41 +05:00
#echo Starting LibreSpeed
#librespeed-cli --json > $speedtest_libre
2023-11-12 12:30:55 +05:00
# Parsing JSON data
2023-11-13 11:19:41 +05:00
#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")
2023-11-12 12:30:55 +05:00
# Converting to human readable units
2023-11-13 11:19:41 +05:00
#libre_bytes_sent_mb=$(echo "scale=2; $libre_bytes_sent / 1048576" | bc)
#libre_bytes_received_mb=$(echo "scale=2; $libre_bytes_received / 1048576" | bc)
2023-11-12 12:30:55 +05:00
2023-11-13 11:19:41 +05:00
#libre_total=$(echo $libre_bytes_sent_mb+$libre_bytes_received_mb | bc)
2023-11-12 21:14:18 +05:00
2023-11-13 11:19:41 +05:00
#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")
2023-11-13 11:19:41 +05:00
#fast_total=$(echo $fast_downloaded+$fast_uploaded | bc)
2023-11-13 11:28:34 +05:00
total_wasted=$ookla_total
2023-11-12 21:14:18 +05:00
2023-11-12 12:30:55 +05:00
echo Speedtests complete
2023-11-11 23:18:19 +05:00
#################################################################################
2023-11-12 21:51:52 +05:00
#################################################################################
valorant_ping=$(latency dynamodb.ap-southeast-1.amazonaws.com)
cfdns_ping=$(latency 1.1.1.1)
googledns_ping=$(latency 8.8.8.8)
#################################################################################
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}&current_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" ;;
2023-11-13 23:34:48 +05:00
1) current_weather="☀️ Mainly clear";;
2) current_weather="☁️ Partly cloudy" ;;
3) current_weather="☁️ Overcast" ;;
45) current_weather="🌫️ Fog" ;;
48) current_weather="🌫️ Depositing rime fog" ;;
51) current_weather="🌧️ Light drizzle" ;;
53) current_weather="🌧️ Moterate drizzle" ;;
55) current_weather="🌧️ Dense drizzle" ;;
56) current_weather="🌧️ Light freezing drizzle" ;;
57) current_weather="🌧️ Dense freezing drizzle" ;;
61) current_weather="🌦️ Slight rain" ;;
63) current_weather="🌦️ Moderate rain" ;;
65) current_weather="🌦️ Heavy rain" ;;
66) current_weather="🌦️ Light freezing rain" ;;
67) current_weather="🌦️ Heavy freezing rain" ;;
71) current_weather="🌨️ Slight snow fall" ;;
73) current_weather="🌨️ Moderate snow fall" ;;
75) current_weather="🌨️ Heavy snow fall" ;;
77) current_weather="🌨️ Snow grains" ;;
80) current_weather="🌧️ Slight rain showers" ;;
81) current_weather="🌧️ Moderate rain showers" ;;
82) current_weather="🌧️ Violent rain showers" ;;
85) current_weather="🌨️ Slight nnow showers" ;;
86) current_weather="🌨️ Heavy snow showers" ;;
95) current_weather="⛈️ Slight thunderstorm" ;;
96) current_weather="⛈️ Thunderstorm with slight hail" ;;
99) current_weather="⛈️ Thunderstorm with heavy hail" ;;
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 21:51:52 +05:00
🔫 Valorant SEA ping: $valorant_ping ms
🌐 1.1.1.1 ping: $cfdns_ping ms
🌐 8.8.8.8 ping: $googledns_ping ms
2023-11-12 12:30:55 +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*: $ookla_upload_mbps Mbit/s, Used: $ookla_bytes_sent_mb MB
2023-11-12 21:14:18 +05:00
Total data wasted: $total_wasted MB
2023-11-11 23:18:19 +05:00
"
#################################################################################
#################################################################################
2023-11-12 17:32:24 +05:00
#convert "$camera_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-12 17:32:24 +05:00
curl -X POST https://api.telegram.org/bot$TG_BOT_TOKEN/sendMediaGroup \
-F chat_id=$TG_CHATID \
2023-11-12 17:32:24 +05:00
-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
2023-11-11 23:18:19 +05:00
#################################################################################
2023-11-12 21:54:23 +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