From 1e627b0bad8c51ff2e3d838bd9f1f8f1c0c4a30e Mon Sep 17 00:00:00 2001 From: Shihaam Abdul Rahman Date: Sat, 11 Nov 2023 23:18:19 +0500 Subject: [PATCH] working --- .gitignore | 1 + bot.sh | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ data/.gitignore | 5 +++++ env_example | 13 +++++++++++ 4 files changed, 78 insertions(+) create mode 100644 .gitignore create mode 100755 bot.sh create mode 100644 data/.gitignore create mode 100644 env_example diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c49bd7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env diff --git a/bot.sh b/bot.sh new file mode 100755 index 0000000..74338e6 --- /dev/null +++ b/bot.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +source .env +date=$(date "+%Y%m%d_%H%M%S") +image=data/image_$date.png +speedtest_result=data/speedtest_$date.txt +weather_file=data/weather_$date.json + +################################################################################# +# Capture a frame from RTSP stream +mpv rtsp://$RTSP_IP --frames=1 --vo=image --ovc=png --o=$image +################################################################################# + +################################################################################# +# Run speedtest and output to a file +speedtest > $speedtest_result +# Extract information from the speedtest output +isp_name=$(grep -oP 'Hosted by \K.*(?= \[)' $speedtest_result) +latency=$(grep -oP 'Hosted by.*\[.*\]: \K[0-9.]+(?= ms)' $speedtest_result) +download_speed=$(grep -oP 'Download: \K.*(?= Mbit/s)' $speedtest_result) +upload_speed=$(grep -oP 'Upload: \K.*(?= Mbit/s)' $speedtest_result) +################################################################################# + +################################################################################# +# Make the API request +response=$(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 +################################################################################# + +################################################################################# +caption=" +$current_weather + +🌐 *ISP*: $isp_name +🏓 *Latency*: $latency ms +⬇️ *Download*: $download_speed Mbit/s +⬆️ *Upload*: $upload_speed Mbit/s +" +################################################################################# + +################################################################################# +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" \ + -F parse_mode=Markdown +################################################################################# diff --git a/data/.gitignore b/data/.gitignore new file mode 100644 index 0000000..6898be8 --- /dev/null +++ b/data/.gitignore @@ -0,0 +1,5 @@ +*.json +*.txt +*.png +*.jpg +*.tmp diff --git a/env_example b/env_example new file mode 100644 index 0000000..c25ec2b --- /dev/null +++ b/env_example @@ -0,0 +1,13 @@ +TG_BOT_API_KEY= +TG_CHANNEL_ID= + +DELAY=10 + +RTSP_AUTH=false +RTSP_IP= +RTSP_PORT= +RTSP_USERNAME= +RTSP_PASSWORD= + +LATITUDE="" +LONGITUDE=""