Shihaam Abdul Rahman 35c802bf7a
Revert "cleaner json... i think"
This reverts commit 69f687790590d5cfeef8b28658687dddf42307aa.
2024-08-03 02:28:51 +05:00

40 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
INPUT_IMAGE=$1
raw_text=$(tesseract $INPUT_IMAGE stdout --psm 6)
referece=$(echo "$raw_text" | grep -o 'BLAZ[0-9]*')
to_number=$(echo "$raw_text" | grep -oE '\b9[0-9]{16}\b|\b7[0-9]{12}\b')
#date=$(echo "$raw_text" | grep -oE '\b[0-3][0-9]/[0-1][0-9]/[0-9]{4}\b')
#time=$(echo "$raw_text" | grep -oE '\b[0-2][0-9]:[0-5][0-9]\b')
date=$(echo "$raw_text" | grep -oE '[0-3][0-9]/[0-1][0-9]/[0-9]{4}')
time=$(echo "$raw_text" | grep -oE '[0-2][0-9]:[0-5][0-9]')
currency=$(echo "$raw_text" | grep -oP '(?<=Amount\s)[A-Z]{3}')
amount=$(echo "$raw_text" | grep -oP '(?<=Amount\s[A-Z]{3}\s)[0-9]{1,3}(?:,[0-9]{3})*(?:\.[0-9]{2})')
status=$(echo "$raw_text" | grep -oP '(?<=Status\s)[A-Z]+')
remarks=$(echo "$raw_text" | grep Remarks | sed 's/Remarks //')
from=$(echo "$raw_text" | grep From | sed 's/From //')
to_name=$(echo "$raw_text"| grep -B1 $to_number | grep -v $to_number)
json=$(cat <<EOF
{
"Amount": "$amount",
"Currency": "$currency",
"Date": "$date $time",
"From": "$from",
"referece": "$referece",
"Remarks": "$remarks",
"Status": "$status",
"To": {
"Account": "$to_number",
"Name": "$to_name"
}
}
EOF
)
echo $json | jq
#echo $raw_text
#tesseract $INPUT_IMAGE stdout --psm 6