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.
This commit is contained in:
Ratatoskr 2024-02-01 13:54:36 +01:00
parent 382e28c481
commit 313e9c8737
Signed by: Ratatoskr
GPG Key ID: 28B77439A6D78F4E

View File

@ -9,7 +9,7 @@
####################################### #######################################
text_dir="/root/iobroker_scripts/general/.text" text_dir="/root/iobroker_scripts/general/.text"
markdown_file="$text_dir/handout.md" html_file="$text_dir/handout.html"
all=("date" "time") # Add more elements as needed all=("date" "time") # Add more elements as needed
@ -62,41 +62,46 @@ generate_text() {
# Call the generate_text function # Call the generate_text function
generate_text generate_text
# Create Markdown file # Create HTML file
echo "## Handout:" > $markdown_file echo "<!DOCTYPE html>" > "$html_file"
echo "| Deutsch | Español |" >> $markdown_file echo "<html>" >> "$html_file"
echo "| ------- | ------- |" >> $markdown_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 for component in "${all[@]}"; do
german_output=$(cat $text_dir/${component}_de.txt) echo "processing: $component"
spanish_output=$(cat $text_dir/${component}_es.txt) german_output=$(cat "$text_dir/${component}_de.txt")
echo "| $german_output | $spanish_output |" >> $markdown_file spanish_output=$(cat "$text_dir/${component}_es.txt")
echo "<tr><td>$german_output</td><td>$spanish_output</td></tr>" >> "$html_file"
done done
echo "</table>" >> "$html_file"
echo "</body>" >> "$html_file"
echo "</html>" >> "$html_file"
# Transfer files to A72 # Transfer files to A72
scp -r -i /root/.ssh/A72 "$text_dir" root@$A72_ip:/data/scripts/ scp -r -i /root/.ssh/A72 "$text_dir" root@$A72_ip:/data/scripts/
# Send Notification to A72 with handout.md file
curl_command="curl -u 'Michaelis:u5ptufUFuDL6q4yEcSN3iqas5gtXNkN77Lx3cy3oX8UoSgFWdifYy9FVopv2Zwtu' \
-H 'Priority:High' \
-T $markdown_file \
-H 'Filename: handout.md' \
-d $'notification_date: Heute ist Dienstag, der 30. Januar 2024.\n"
for component in "${all[@]}"; do
curl_command+="${component}:\n"
curl_command+="$(cat $text_dir/${component}_de.txt)\n"
curl_command+="$(cat $text_dir/${component}_es.txt)\n"
done
curl_command="${curl_command%\\n}" # Remove the trailing newline
curl_command+="\n'"
curl_command+=" https://ntfy.michaelis.digital/ioBroker"
echo "curl_command: $curl_command"
eval "$curl_command" # Execute the constructed curl command
# Display Markdown file content # Display Markdown file content
cat $markdown_file cat $markdown_file