Automator Programm

Aktuelle Version:

- BOM wird entfernt
- Androidunterstützung

Code:
#!/bin/bash

file="$1"
cd "$(dirname "$file")";

# Create HTML file
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8">
        <link rel="stylesheet" media="screen" href="style.css">
    </head>
    <body>
        <div>
        <h1>WhatsApp Chatverlauf</h1>' >WhatsApp-Chat.htm

# Create CSS file
echo 'body {
    font-family:Lucida Grande, Verdana, Arial;
    align: center;
    padding: 50px;
    background-color: #EEEEEE;
}
h1 {
    font-size: 40px;
    color: #60b82d;
    margin: 0px;
    text-align: center;
}
h2 {
    font-size: 10px;
    color: grey;
    margin: 0px;
    text-align: center;
}
h3 {
    font-size: 14px;
    font-weight: bold;
    color: black;
    margin: 0px;
}
p {
    font-size: 14px;
    color: black;
    margin: 2px;
}
img {
    max-width: 600px;
}
div {
    width: 600px;
    margin: 3px auto;
    padding: 5px;
    background-color: white;
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    border-radius: 5px;
}' >style.css

# read text file
cat "$file" |iconv -t UTF-8|tr -d '"'|grep -v "^$" | awk 'NR==1{sub(/^\xef\xbb\xbf/,"")}1' |\
while read Line
do
  # get date, sender and message
  date=$(echo $Line | grep -Eo '^[0-9.]{8} [0-9:]{8}');
  sender=$(echo $Line | grep -E '^[0-9.]{8} [0-9:]{8}' | sed -E 's/^.{19}//g;' | grep -Eo '^[^ ][^:]*:');
  message=$(echo $Line | sed "s/^$date: //g;s/^$sender//g");
  # Android
  if [[ $date == "" && $sender == "" ]]
  then
    date="$(echo $Line | grep -Eo '^[^-]*')"
    sender="$(echo $Line | grep -Eo '\-[^:]*' | sed 's/^- //g')"
    message="$(echo $Line | sed "s/$date//g;s/^- $sender: //g")"
  fi
  # attachments
  if [[ "$message" = *"<‎angehängt>"* ]]; then
    image=$(echo $message | grep -Eo '[0-9A-Za-z]*.jpg')
    if [[ "$image" = '' ]]; then
        continue; # unknown attachment, continue with next line
    fi
    message=$(echo "<img src=\"$image\">")
  fi
  # write message text
  if [[ "$sender" = '' && "$date" = '' ]]; then
    echo "        <p>$message</p>" >>WhatsApp-Chat.htm;
  else
    echo "        </div><div><h2>$date</h2><h3>$sender</h3><p>$message</p>" >>WhatsApp-Chat.htm;
  fi
done
echo '        </div>
    </body>
</html>' >>WhatsApp-Chat.htm
http://cl.ly/2t2Q0M3D041e
 
Zurück
Oben Unten