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.
This commit is contained in:
parent
b1390cb435
commit
eb6911acf8
@ -11,7 +11,7 @@
|
||||
text_dir="/root/iobroker_scripts/general/.text"
|
||||
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
|
||||
rm -f $text_dir/*
|
||||
@ -51,44 +51,67 @@ generate_text() {
|
||||
echo "$date_de" > "$text_dir/date_de.txt"
|
||||
time_de=$(date '+Es ist %H:%M Uhr.')
|
||||
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
|
||||
date_es=$(trans -b :de :es "$date_de")
|
||||
echo "$date_es" > "$text_dir/date_es.txt"
|
||||
time_es=$(trans -b :de :es "$time_de")
|
||||
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
|
||||
generate_text
|
||||
|
||||
# Create Markdown content
|
||||
markdown_content="**Handout:**
|
||||
\n
|
||||
| Deutsch | Español |
|
||||
| ------- | -------- |"
|
||||
# Create HTML file
|
||||
echo "<!DOCTYPE html>" >> "$html_file"
|
||||
echo "<html>" >> "$html_file"
|
||||
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
|
||||
echo "processing: $component"
|
||||
german_output=$(cat "$text_dir/${component}_de.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
|
||||
|
||||
# Send Notification to A72 with Markdown content
|
||||
curl_command="curl -u 'Michaelis:u5ptufUFuDL6q4yEcSN3iqas5gtXNkN77Lx3cy3oX8UoSgFWdifYy9FVopv2Zwtu' \
|
||||
-H 'Priority:High' \
|
||||
-d \"$markdown_content\" \
|
||||
-H 'Markdown: yes' \
|
||||
https://ntfy.michaelis.digital/ioBroker"
|
||||
echo "</table>" >> "$html_file"
|
||||
echo "</body>" >> "$html_file"
|
||||
echo "</html>" >> "$html_file"
|
||||
|
||||
echo "curl_command: $curl_command"
|
||||
eval "$curl_command" # Execute the constructed curl command
|
||||
# Get ip of a72
|
||||
check_ip
|
||||
|
||||
# Transfer files to A72
|
||||
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
|
||||
nohup ssh -i /root/.ssh/A72 -f root@$A72_ip '/data/scripts/generate_mp3.sh' > /root/generate_mp3.log &
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user