-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathduedate-update
More file actions
executable file
·70 lines (52 loc) · 1.91 KB
/
duedate-update
File metadata and controls
executable file
·70 lines (52 loc) · 1.91 KB
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
#!/usr/bin/bash
auth 2>/dev/null || authn 2>/dev/null
tenant=$(cat tenant)
okapi_url=$(cat okapi.url)
okapi_token=$(cat okapi.token)
infile="update"
logfile="duedate.log"
dos2unix "${infile}"
counter=1
rm -f ${logfile}
numrecs=$(wc -l ${infile} |cut -d " " -f1)
while IFS=$'\t' read -r search duedate; do
# duedate is UTC date/time, e.g. 2025-01-31T04:59:00Z
item_uuid=""
item_status=""
loan_uuid=""
apicall=""
if [[ ${search} =~ ^[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*$ ]];then
item_uuid=${search}
else
apicall=$(curl -s -w '\n' -X GET -D \
-H "Accept: application/json" \
-H "X-Okapi-Tenant: ${tenant}" \
-H "x-okapi-token: ${okapi_token}" \
"${okapi_url}/item-storage/items?query=barcode==${search}")
item_uuid=$(echo "${apicall}" |jq -r '.items[0].id')
item_status=$(echo "${apicall}" |jq -r '.items[0].status.name')
fi
if [[ ${item_status} == "Checked out" ]];then
apicall=$(curl -s -w '\n' -X GET -D \
-H "Accept: application/json" \
-H "X-Okapi-Tenant: ${tenant}" \
-H "x-okapi-token: ${okapi_token}" \
"${okapi_url}/loan-storage/loans?query=itemId=%22${item_uuid}%22")
loan_uuid=$(echo "${apicall}" |jq -r '.loans[] |select(.itemStatus == "Checked out") |.id')
IFS='' read -r -d '' data << EndOfJSON
{
"dueDate":"${duedate}"
}
EndOfJSON
apicall=$(curl --http1.1 -s -w '\n' -X POST -H "Content-type: application/json" -H "X-Okapi-Tenant: ${tenant}" -H "x-okapi-token: ${okapi_token}" -d "${data}" "${okapi_url}/circulation/loans/${loan_uuid}/change-due-date" |tr -d '\n')
echo "${apicall}" >> "${logfile}"
fi
echo "Processing ${search} -- record $counter of $numrecs"
counter=$((counter + 1))
if [[ $SECONDS -gt 500 ]]; then
auth 2>/dev/null || authn 2>/dev/null
okapi_token=$(cat okapi.token)
SECONDS=1
fi
done < ${infile}
echo "Processing completed, results logged to ${logfile}"