Update scantap

This commit is contained in:
The Magician 2024-09-05 10:52:00 +01:00
parent 43ffa2803f
commit 77a515cba4
2 changed files with 23 additions and 11 deletions

View File

@ -1,8 +1,8 @@
USE sevenkeys; USE sevenkeys;
CREATE TABLE IF NOT EXISTS CardScans ( CREATE TABLE IF NOT EXISTS CardScan (
Id INT PRIMARY KEY AUTO_INCREMENT, Id INT PRIMARY KEY AUTO_INCREMENT,
StorageBox VARCHAR(20) NOT NULL, StorageAreaId INT NOT NULL,
Position INT NOT NULL, FOREIGN KEY (StorageAreaId) REFERENCES StorageArea(Id),
Source VARCHAR(100) NULL Position INT NOT NULL
); );

View File

@ -3,14 +3,21 @@
mysql --user=root --password="$(pass show sevenkeys/mysql)" <createtable.sql mysql --user=root --password="$(pass show sevenkeys/mysql)" <createtable.sql
printf "scantap: Enter name of storage box: " printf "scantap: Enter name of storage box: "
read storageBox read storageAreaName
startPosition="$(mysql --silent --silent --user=root --password="$(pass show sevenkeys/mysql)" -e "USE sevenkeys; SELECT Position FROM CardScans WHERE StorageBox = '$storageBox' ORDER BY Position DESC LIMIT 1;")" 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)) position=$((startPosition + 1))
printf "scantap: Enter card source: "
read cardSource
printf "scantap: Enter mode (foil/nonfoil): " printf "scantap: Enter mode (foil/nonfoil): "
read foilMode read foilMode
outputDir="images/$foilMode" outputDir="images/$foilMode"
@ -33,10 +40,15 @@ while true; do
ADD_CARDS=0 ADD_CARDS=0
if ! test -e tmp1.png || ! test -e tmp2.png; then if ! test -e tmp1.png || ! test -e tmp2.png; then
echo "scantap: Failed to create temporary image files" echo "scantap: Failed to create temporary image files" >&2
exit 1
fi fi
key="$(mysql --silent --silent --user=root --password="$(pass show sevenkeys/mysql)" -e "USE sevenkeys; INSERT INTO CardScans (StorageBox, Position, Source) VALUES ('$storageBox', '$position', '$cardSource'); SELECT Id FROM CardScans ORDER BY Id DESC LIMIT 1;")" 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)) position=$((position + 1))
convert -rotate 180 tmp1.png tmp1.png convert -rotate 180 tmp1.png tmp1.png