Update card_scanner
This commit is contained in:
parent
ec5328fed1
commit
6a4ff5dffd
|
@ -1,32 +1,15 @@
|
|||
#!/bin/bash
|
||||
|
||||
mysql --user=root --password="$(pass show sevenkeys/mysql)" <createtable.sql
|
||||
|
||||
printf "scantap: Enter name of storage box: "
|
||||
read storageAreaName
|
||||
|
||||
storageAreaId="$(mysql --silent --silent --user=root --password="$(pass show sevenkeys/mysql)" -e "USE sevenkeys; SELECT Id FROM StorageArea WHERE Name = '$storageAreaName';")"
|
||||
if test -z "$storageAreaId"; then
|
||||
echo "scantap: No storage area named \"$storageAreaName\"" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
startPosition="$(mysql --silent --silent --user=root --password="$(pass show sevenkeys/mysql)" -e "USE sevenkeys; SELECT Position FROM CardScan WHERE StorageAreaId = '$storageAreaId' ORDER BY Position DESC LIMIT 1;")"
|
||||
if test "$?" -ne "0"; then
|
||||
echo "scantap: Failed to establish starting position" >&2
|
||||
exit 1
|
||||
fi
|
||||
position=$((startPosition + 1))
|
||||
|
||||
printf "scantap: Enter mode (foil/nonfoil): "
|
||||
read foilMode
|
||||
outputDir="images/$foilMode"
|
||||
mkdir -p "$outputDir"
|
||||
STORAGE_DIR="$HOME/.local/share/sevenkeys/scanimages/"
|
||||
mkdir -p "$STORAGE_DIR"
|
||||
|
||||
ADD_CARDS=0
|
||||
echo "scantap: Beginning scan loop"
|
||||
while true; do
|
||||
scanimage --format=png --batch=tmp%d.png --batch-count=2 --source "ADF Duplex" --mode Color --page-width 63mm --page-height 88mm 2>/dev/null
|
||||
rng="$(cat /dev/random | tr -cd 'a-f0-9' | head -c 32)"
|
||||
filename="$STORAGE_DIR/$rng.png"
|
||||
|
||||
scanimage --output-file="$filename" --source "ADF Front" --mode Color --page-width 63mm --page-height 88mm 2>/dev/null
|
||||
|
||||
# scanimage exits with code 7 if no documents are available in scanner
|
||||
if test $? -eq 7; then
|
||||
|
@ -39,21 +22,11 @@ while true; do
|
|||
fi
|
||||
ADD_CARDS=0
|
||||
|
||||
if ! test -e tmp1.png || ! test -e tmp2.png; then
|
||||
echo "scantap: Failed to create temporary image files" >&2
|
||||
exit 1
|
||||
fi
|
||||
convert -rotate 180 "$filename" "$filename"
|
||||
|
||||
key="$(mysql --silent --silent --user=root --password="$(pass show sevenkeys/mysql)" -e "USE sevenkeys; INSERT INTO CardScan (StorageAreaId, Position) VALUES ('$storageAreaId', '$position'); SELECT Id FROM CardScan ORDER BY Id DESC LIMIT 1;")"
|
||||
if test "$?" -ne "0"; then
|
||||
echo "scantap: Failed to get key from database" >&2
|
||||
exit 1
|
||||
fi
|
||||
position=$((position + 1))
|
||||
|
||||
convert -rotate 180 tmp1.png tmp1.png
|
||||
convert -rotate 180 tmp2.png tmp2.png
|
||||
|
||||
mv tmp1.png "$outputDir/${key}_back.png"
|
||||
mv tmp2.png "$outputDir/${key}_front.png"
|
||||
# TODO: Add "store" command to sevenkeys executable to avoid duplicating insert logic here, then `./sevenkeys --profile=production store --id="0000..0000"`
|
||||
# Return inserted CardLocationId
|
||||
#cardLocationId="1"
|
||||
#mysql --silent --silent --user=root --password="$(pass show sevenkeys/mysql \
|
||||
#-e "USE sevenkeys; INSERT INTO CardScan (CardLocationId, Filename) VALUES ('$cardLocationId', '$filename.png');"
|
||||
done
|
||||
|
|
Loading…
Reference in New Issue