-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinventory.sh
80 lines (64 loc) · 1.67 KB
/
inventory.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash -i
#TO DO: inventory of disks
function show_help() {
echo
echo -e "reads a barcode and then outputs catalog information to a designated csv"
echo -e "relies on barcode-pull.sh, also in this repository"
echo -e "requires catAPIkey to be set"
echo -e "USAGE: inventory.sh -o /output-directory/filename.csv"
}
function array_contains() {
local array="$1[@]"
local seeking=$2
local in=1
for element in "${!array}"; do
if [[ $element == $seeking ]]; then
in=0
break
fi
done
return $in
}
OPTIND=1
barcode=""
diskID=""
# Parse arguments
while getopts "h?o:" opt; do
case "$opt" in
h|\?)
show_help
exit
;;
o) outCSV=$OPTARG
;;
esac
done
shift $((OPTIND-1))
[ "$1" = "--" ] && shift
garbage="$@"
# Check all required parameters are present
if [ -z "$outCSV" ]; then
echo "output directory (-o) is required!"
elif [ "$garbage" ]; then
echo "$garbage is garbage."
fi
another="y"
while [[ "$another" == "y" ]]; do
IFS= read -re -p 'Scan barcode: ' barcode
bash barcode-pull.sh -b ${barcode} -f > tmp.json
#echo "Using barcode: ${barcode}"
diskID=$(jq -r .holding_data.permanent_call_number tmp.json)
MMSID=$(jq -r .bib_data.mms_id tmp.json)
title=$(jq .bib_data.title tmp.json)
barcode=${barcode}
dateTime=`date +"%Y-%m-%d %T"`
#diskID="${diskID^^// /-//./-//--/-//\"}" # replace spaces, dots and double dashes with single dashes, remove double quotes
diskID=${diskID// /-}
diskID=${diskID//./-}
diskID=${diskID^^}
diskID=${diskID//--/-}
diskID=${diskID//\"/}
echo "$diskID, $title, alma$MMSID, $dateTime, $barcode"
echo "$diskID,$title,alma$MMSID,$dateTime, $barcode" >> $outCSV
rm tmp.json
done