-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcourses-add
More file actions
executable file
·96 lines (70 loc) · 3.36 KB
/
courses-add
File metadata and controls
executable file
·96 lines (70 loc) · 3.36 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/bash
auth 2>/dev/null || authn 2>/dev/null
tenant=$(cat tenant)
okapi_url=$(cat okapi.url)
okapi_token=$(cat okapi.token)
SECONDS=1
infile="courses.tsv"
declare -A dept_dict
declare -A term_dict
declare -A coursetype_dict
default_coursetype='default'
default_term='Spring 2025'
default_dept='migration'
# get list of course departments and populate array using name as key with uuid as value
eval "$(curl -s -w '\n' -X GET -H "Accept: application/json" -H "X-Okapi-Tenant: ${tenant}" -H "x-okapi-token: ${okapi_token}" "${okapi_url}/coursereserves/departments?limit=1000" | jq -r '.departments[] | @sh "dept_dict[\(.name|tostring|ascii_downcase |gsub("[^0-9a-z]"; ""))]=\(.id|tostring)"')"
# get list of course terms/types and populate array using name as key with uuid as value
eval "$(curl -s -w '\n' -X GET -H "Accept: application/json" -H "X-Okapi-Tenant: ${tenant}" -H "x-okapi-token: ${okapi_token}" "${okapi_url}/coursereserves/terms?limit=1000" | jq -r '.terms[] | @sh "term_dict[\(.name|tostring|ascii_downcase |gsub("[^0-9a-z]"; ""))]=\(.id|tostring)"')"
eval "$(curl -s -w '\n' -X GET -H "Accept: application/json" -H "X-Okapi-Tenant: ${tenant}" -H "x-okapi-token: ${okapi_token}" "${okapi_url}/coursereserves/coursetypes?limit=1000" | jq -r '.courseTypes[] | @sh "coursetype_dict[\(.name|tostring|ascii_downcase |gsub("[^0-9a-z]"; ""))]=\(.id|tostring)"')"
#while IFS=$'\t' read -r dept courseNumber courseName term;do
while IFS=$'\t' read -r courseNumber courseName dept;do
if [[ $SECONDS -gt 500 ]]; then
auth 2>/dev/null || authn 2>/dev/null
okapi_token=$(cat okapi.token)
SECONDS=1
OFFSET=$(($OFFSET + 1))
TIMER=$(($OFFSET * 500 + $SECONDS))
fi
if [[ -z ${dept} ]];then dept="${default_dept}";fi
if [[ -z ${term} ]];then term="${default_term}";fi
if [[ -z ${coursetype} ]];then coursetype="${default_coursetype}";fi
term=$(tr -dc [a-z0-9] <<< "${term,,}")
dept=$(tr -dc [a-z0-9] <<< "${dept,,}")
coursetype=$(tr -dc [a-z0-9] <<< "${coursetype,,}")
#courseNumber="${dept} ${courseNumber}"
#dept=$(tr -dc "[0-9a-z]" <<< ${dept,,})
#dept=$(tr -dc "[a-z]" <<< ${courseNumber,,})
departmentId=${dept_dict[${dept}]}
termId=${term_dict[${term}]}
coursetypeId=${coursetype_dict[${coursetype}]}
external=''
registrar=''
coursetype=''
if [[ ${externalId} != "" ]];then external="\"externalId\":\"${externalId}\",";fi
if [[ ${registrarId} != "" ]];then registrar="\"registrarId\":\"${registrarId}\",";fi
if [[ ${courseTypeId} != "" ]];then coursetype="\"courseTypeId\":\"${courseTypeId}\",";fi
listingid=$(uuidgen)
IFS='' read -r -d '' courselisting << EndOfCourseListing
{
"id": "${listingid}",
${coursetype}
${registrar}
${external}
"termId": "${termId}"
}
EndOfCourseListing
courseid=$(uuidgen)
IFS='' read -r -d '' course << EndOfCourse
{
"id": "${courseid}",
"departmentId": "${departmentId}",
"name": "${courseName}",
"courseNumber": "${courseNumber}",
"courseListingId": "${listingid}"
}
EndOfCourse
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 "${courselisting}" "${okapi_url}/coursereserves/courselistings")
echo -e "${apicall}"
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 "${course}" "${okapi_url}/coursereserves/courses")
echo -e "${apicall}"
done < "${infile}"