Compare commits

..

4 Commits

Author SHA1 Message Date
a61f9f2d2d
Initial commit of weather.sh script
This script retrieves current weather information from OpenWeatherMap API. It includes:
- OpenWeatherMap API key for data retrieval.
- Location settings for specifying the city and country.
- API request using cURL to fetch weather data.
- Extraction of relevant information from the JSON response using jq.
- Conversion of temperature from Kelvin to Celsius.
- Formulation of the weather information in a formatted English text.
- Output of the weather information.

Author: Michael Haider
Date: 2024-02-08
2024-02-08 16:03:47 +01:00
0a77d93643
Update wecker.sh script
- Add an echo statement to output the current notification information when the alarm is turned off.
- Call 'generate_text.sh' script from '/root/iobroker_scripts/general/' when the alarm is turned off, providing a visual notification update.
- Remove the call to 'generate_text.sh' when the alarm is dismissed, as it is now handled when the alarm is turned off.
2024-02-08 16:01:53 +01:00
eb6911acf8
Update generate_text.sh script
- Add 'weather' to the 'all' array, allowing inclusion of weather information in the generated text.
- Create directories /sdcard/.mp3/ and /sdcard/.text/ to store MP3 and text files respectively.
- Update txt_dir and mp3_dir paths to use /sdcard/ instead of /root/iobroker_scripts/general/.
- Modify the 'generate_text' function to include weather information in both German and Spanish.
- Create an HTML file (handout.html) for better presentation of text information.
- Style the HTML content with a table for improved readability.
- Add processing messages for each component during HTML generation.
- Extract IP address retrieval into a separate function 'check_ip'.
- Transfer the HTML and text files to A72's /sdcard/ directory using SCP.
- Start 'generate_mp3.sh' on A72 asynchronously using nohup.
2024-02-08 16:01:06 +01:00
b1390cb435
Enhance generate_mp3.sh script
- Add 'weather' to category_order array to include weather information in the generated MP3 files.
- Create directories /sdcard/.mp3/ and /sdcard/.text/ to store MP3 and text files respectively.
- Update txt_dir and mp3_dir paths to use /sdcard/ instead of /data/scripts/.
- Modify the 'am start' command to open handout.html in a Chromium tabbed activity for better compatibility.
- Remove unnecessary commented-out am start command and replace it with an updated command.
- Improve comments for better script understanding.
2024-02-08 15:59:47 +01:00
4 changed files with 92 additions and 23 deletions

View File

@ -14,16 +14,21 @@ export PATH=$PATH:/data/data/com.termux/files/usr/bin
# Array with the desired languages in order # Array with the desired languages in order
lang_order=("es" "de" "es-l") lang_order=("es" "de" "es-l")
category_order=("date" "time") category_order=("date" "time" "weather")
# Create Directories
mkdir -p /sdcard/.mp3/
mkdir -p /sdcard/.text/
# Directories # Directories
txt_dir="/data/scripts/.text" txt_dir="/sdcard/.text"
mp3_dir="/data/scripts/.mp3" mp3_dir="/sdcard/.mp3"
# remove old files # remove old files
rm -f "$txt_dir"/*complete.txt rm -f "$txt_dir"/*complete.txt
# open handout.md file # open handout.md file
am start --user 0 -a android.intent.action.VIEW -d file:///sdcard/handout.html -t text #am start --user 0 -a android.intent.action.VIEW -d content://pl.solidexplorer2.files/storage/emulated/0/.text/handout.html -t text/html
am start --user 0 -n org.bromite.chromium/org.chromium.chrome.browser.ChromeTabbedActivity -d content://pl.solidexplorer2.files/storage/emulated/0/.text/handout.html -t text/html
# Function to create MP3 files # Function to create MP3 files
create_mp3_files() { create_mp3_files() {

View File

@ -11,7 +11,7 @@
text_dir="/root/iobroker_scripts/general/.text" text_dir="/root/iobroker_scripts/general/.text"
html_file="$text_dir/handout.html" html_file="$text_dir/handout.html"
all=("date" "time") # Add more elements as needed all=("date" "time" "weather") # Add more elements as needed
# remove files in text_dir # remove files in text_dir
rm -f $text_dir/* rm -f $text_dir/*
@ -51,44 +51,67 @@ generate_text() {
echo "$date_de" > "$text_dir/date_de.txt" echo "$date_de" > "$text_dir/date_de.txt"
time_de=$(date '+Es ist %H:%M Uhr.') time_de=$(date '+Es ist %H:%M Uhr.')
echo "$time_de" > "$text_dir/time_de.txt" echo "$time_de" > "$text_dir/time_de.txt"
weather_de=$(trans -b :en :de "$(/root/iobroker_scripts/general/weather.sh)")
echo "$weather_de" > "$text_dir/weather_de.txt"
# Spanish # Spanish
date_es=$(trans -b :de :es "$date_de") date_es=$(trans -b :de :es "$date_de")
echo "$date_es" > "$text_dir/date_es.txt" echo "$date_es" > "$text_dir/date_es.txt"
time_es=$(trans -b :de :es "$time_de") time_es=$(trans -b :de :es "$time_de")
echo "$time_es" > "$text_dir/time_es.txt" echo "$time_es" > "$text_dir/time_es.txt"
weather_es=$(trans -b :en :es "$(/root/iobroker_scripts/general/weather.sh)")
echo "$weather_es" > "$text_dir/weather_es.txt"
} }
# Call the generate_text function # Call the generate_text function
generate_text generate_text
# Create Markdown content # Create HTML file
markdown_content="**Handout:** echo "<!DOCTYPE html>" >> "$html_file"
\n echo "<html>" >> "$html_file"
| Deutsch | Español | echo "<head>" >> "$html_file"
| ------- | -------- |" echo "<title>Handout</title>" >> "$html_file"
echo "<meta charset="UTF-8">" >> "$html_file"
echo "<style>" >> "$html_file"
echo "body {" >> "$html_file"
echo "font-size: 24px;" >> "$html_file"
echo "}" >> "$html_file"
echo "table {" >> "$html_file"
echo " border-collapse: collapse;" >> "$html_file"
echo " width: 100%;" >> "$html_file"
echo " margin: auto;" >> "$html_file"
echo "}" >> "$html_file"
echo "th, td {" >> "$html_file"
echo " border: 3px solid black;" >> "$html_file"
echo " padding: 8px;" >> "$html_file"
echo " text-align: center;" >> "$html_file"
echo "}" >> "$html_file"
echo "th {" >> "$html_file"
echo " background-color: #00ff00;" >> "$html_file"
echo "}" >> "$html_file"
echo "</style>" >> "$html_file"
echo "</head>" >> "$html_file"
echo "<body>" >> "$html_file"
echo "<h1>Handout:</h1>" >> "$html_file"
echo "<table>" >> "$html_file"
echo "<h2><tr><th>Deutsch</th><th>Español</th></tr></h2>" >> "$html_file"
for component in "${all[@]}"; do for component in "${all[@]}"; do
echo "processing: $component"
german_output=$(cat "$text_dir/${component}_de.txt") german_output=$(cat "$text_dir/${component}_de.txt")
spanish_output=$(cat "$text_dir/${component}_es.txt") spanish_output=$(cat "$text_dir/${component}_es.txt")
markdown_content+="\n| $german_output | $spanish_output |" echo "<tr><td>$german_output</td><td>$spanish_output</td></tr>" >> "$html_file"
done done
# Send Notification to A72 with Markdown content echo "</table>" >> "$html_file"
curl_command="curl -u 'Michaelis:u5ptufUFuDL6q4yEcSN3iqas5gtXNkN77Lx3cy3oX8UoSgFWdifYy9FVopv2Zwtu' \ echo "</body>" >> "$html_file"
-H 'Priority:High' \ echo "</html>" >> "$html_file"
-d \"$markdown_content\" \
-H 'Markdown: yes' \
https://ntfy.michaelis.digital/ioBroker"
echo "curl_command: $curl_command" # Get ip of a72
eval "$curl_command" # Execute the constructed curl command check_ip
# Transfer files to A72 # Transfer files to A72
scp -r -i /root/.ssh/A72 "$text_dir" root@$A72_ip:/sdcard/ scp -r -i /root/.ssh/A72 "$text_dir" root@$A72_ip:/sdcard/
# Display Markdown content
echo -e "$markdown_content"
# Start generate_mp3.sh on A72 # Start generate_mp3.sh on A72
nohup ssh -i /root/.ssh/A72 -f root@$A72_ip '/data/scripts/generate_mp3.sh' > /root/generate_mp3.log & nohup ssh -i /root/.ssh/A72 -f root@$A72_ip '/data/scripts/generate_mp3.sh' > /root/generate_mp3.log &

40
weather.sh Normal file
View File

@ -0,0 +1,40 @@
#!/bin/bash
################################################################################
# OpenWeatherMap Weather Script
# Author: Michael Haider
# Date: 2024-02-08
#
# This script retrieves current weather information from OpenWeatherMap API
# based on the specified city and country. It then extracts relevant data,
# converts temperature from Kelvin to Celsius, and outputs the information
# in a formatted English text.
################################################################################
# OpenWeatherMap API key
api_key="da7765a8c6d2975b7dfe68f2a1775631"
# Location settings
city="Pfarrkirchen"
country="de"
# Make API request and retrieve data
weather_data=$(curl -s "http://api.openweathermap.org/data/2.5/weather?q=${city},${country}&appid=${api_key}")
# Extract relevant information from the JSON response
description=$(echo "$weather_data" | jq -r '.weather[0].description')
temperature=$(echo "$weather_data" | jq -r '.main.temp')
humidity=$(echo "$weather_data" | jq -r '.main.humidity')
wind_speed=$(echo "$weather_data" | jq -r '.wind.speed')
# Convert temperature from Kelvin to Celsius
temperature_celsius=$(awk "BEGIN {print $temperature - 273.15}")
# Formulate the text in English
weather="Current weather in $city: $description.
The temperature is ${temperature_celsius}°C, humidity is ${humidity}%.
Wind speed is ${wind_speed} m/s."
# Output the text
echo "$weather"

View File

@ -135,8 +135,10 @@ check_notification() {
elif [[ $output == *"com.urbandroid.sleep"* && $output != *"AlarmKlaxon"* ]]; then elif [[ $output == *"com.urbandroid.sleep"* && $output != *"AlarmKlaxon"* ]]; then
# Alarm turned off # Alarm turned off
date && echo "Alarm turned off." date && echo "Alarm turned off."
echo "$output"
ssh -i /root/.ssh/A72 root@$A72_ip 'killall mpv' ssh -i /root/.ssh/A72 root@$A72_ip 'killall mpv'
iobroker state set zigbee.0.04cd15fffee03198.state false iobroker state set zigbee.0.04cd15fffee03198.state false
/root/iobroker_scripts/general/generate_text.sh # Call generate_text.sh script
exit # Exit the script when the alarm is turned off exit # Exit the script when the alarm is turned off
else else
# Phone unreachable # Phone unreachable
@ -279,7 +281,6 @@ if [ $current_brightness -eq $end_brightness ] && [ $current_colortemp -eq $end_
fi fi
if [ "$alarm_dismissed" = true ]; then if [ "$alarm_dismissed" = true ]; then
echo "Alarm dismissed" echo "Alarm dismissed"
/root/iobroker_scripts/general/generate_text.sh # Call generate_text.sh script
exit # Exit the script when the alarm is dismissed exit # Exit the script when the alarm is dismissed
fi fi
done done