wecker/generate_text.sh
Ratatoskr 313e9c8737
Update generate_text.sh script
The generate_text.sh script has been modified with the following changes:

- Updated the variable name 'markdown_file' to 'html_file' to reflect the change in the file format from Markdown to HTML.
- Modified the HTML structure to create a formatted table for the handout, enhancing readability and presentation.
- Added inline CSS styling to the HTML file to improve the table layout and appearance.

These changes improve the generate_text.sh script by switching from Markdown to HTML for better presentation and readability of the handout. Additionally, the HTML table is now more structured and visually appealing.

The commit also includes the removal of the previous notification-related code, which was commented out and not in use.

The goal is to enhance the script's functionality and improve the presentation of the generated handout in HTML format.
2024-02-01 13:54:36 +01:00

111 lines
3.2 KiB
Bash
Executable File

#!/bin/bash
#######################################
# generate_text.sh - Create text files (German and Spanish)
#
# Author: Michael Haider
# Created on: 26.01.2024
# Description: This script generates various text files with information such as date, time, news, and weather in German and Spanish.
#######################################
text_dir="/root/iobroker_scripts/general/.text"
html_file="$text_dir/handout.html"
all=("date" "time") # Add more elements as needed
# remove files in text_dir
rm -f $text_dir/*
# Function to get the IP address of Lisa's iPhone
check_ip() {
mac_address="e4:cd:d1" # Replace this with the MAC address
attempts=10
interval=5
for ((i = 1; i <= $attempts; i++)); do
A72_ip=$(arp-scan -r 3 -v --localnet | grep "$mac_address" | awk '{print $1}')
if [ -n "$A72_ip" ]; then
echo "Found IP: $A72_ip"
return 0 # Success: IP address found
fi
if [ $i -lt $attempts ]; then
echo "Wait $interval seconds before the next attempt."
sleep $interval
fi
done
# All attempts unsuccessful
echo "The target could not be reached after $attempts attempts."
return 1 # Error: IP address not found
}
# Execute the check_ip function.
check_ip
# Function to generate the text files
generate_text() {
# German
date_de=$(date '+Heute ist %A, der %d. %B %Y.')
echo "$date_de" > "$text_dir/date_de.txt"
time_de=$(date '+Es ist %H:%M Uhr.')
echo "$time_de" > "$text_dir/time_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"
}
# Call the generate_text function
generate_text
# Create HTML file
echo "<!DOCTYPE html>" > "$html_file"
echo "<html>" >> "$html_file"
echo "<head>" >> "$html_file"
echo "<title>Handout</title>" >> "$html_file"
echo "<style>" >> "$html_file"
echo "table {" >> "$html_file"
echo " border-collapse: collapse;" >> "$html_file"
echo " width: 50%;" >> "$html_file"
echo " margin: auto;" >> "$html_file"
echo "}" >> "$html_file"
echo "th, td {" >> "$html_file"
echo " border: 1px solid black;" >> "$html_file"
echo " padding: 8px;" >> "$html_file"
echo " text-align: left;" >> "$html_file"
echo "}" >> "$html_file"
echo "th {" >> "$html_file"
echo " background-color: #f2f2f2;" >> "$html_file"
echo "}" >> "$html_file"
echo "</style>" >> "$html_file"
echo "</head>" >> "$html_file"
echo "<body>" >> "$html_file"
echo "<h2>Handout:</h2>" >> "$html_file"
echo "<table>" >> "$html_file"
echo "<tr><th>Deutsch</th><th>Español</th></tr>" >> "$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")
echo "<tr><td>$german_output</td><td>$spanish_output</td></tr>" >> "$html_file"
done
echo "</table>" >> "$html_file"
echo "</body>" >> "$html_file"
echo "</html>" >> "$html_file"
# Transfer files to A72
scp -r -i /root/.ssh/A72 "$text_dir" root@$A72_ip:/data/scripts/
# Display Markdown file content
cat $markdown_file
# 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 &