-
Notifications
You must be signed in to change notification settings - Fork 0
/
arch-division.fish
executable file
·110 lines (97 loc) · 3.71 KB
/
arch-division.fish
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env fish
# handle Architecture Division's special taxonomies, which include departmental codes
# usage:
# ./arch-division.fish
#
# run ONLY AFTER extracting all the departmental CSVs, e.g. by running the Informer
# report & running ./make-all-taxo-csvs.fish data/_informer.csv
# load log function
source log.fish
set -x LOGFILE logs/(date "+%Y-%m-%d")-architecture.txt
set taxo_file data/taxonomies.json
set depts ARCHT BARCH INTER MARCH
set div 'ARCH DIV'
set dir data
set taxo_file data/taxonomies.json
set un (jq -r '.username' ~/.equellarc)
set pw $argv[1]
if [ -z $pw ];
set pw (op item get "VAULT ($un)" --reveal --fields password || jq -r '.password' ~/.equellarc)
end
if [ $un = "" ]
echo "Error: requires a username property in ~/.equellarc"
exit 1
else if [ -z $pw ]; or [ $pw = null ]
echo "Error: requires either a OnePassword login named 'VAULT ($un)' or a password property in ~/.equellarc"
exit 1
end
if [ ! -e "$taxo_file" ]
log "Downloading taxonomy list to $taxo_file"
# make sure to get all of them with the length param
eq tax --path '?length=5000' >$taxo_file
end
# combine departmental CSVs into division-level ones
# wipe out any previous division-level taxos, lets the script be run multiple times
log 'Deleting any previous taxonomy files'
rm -v $dir/$div-course-list-taxo.csv $dir/$div-course-titles.csv \
$dir/$div-courses.csv $dir/$div-faculty-names.csv \
$dir/$div-section-names.csv 2>/dev/null
# concatenate program data to make division-level taxos,
# silencing stderr because one of ARCHT/BARCH will always be missing
for dept in $depts
cat $dir/$dept-course-list-taxo.csv 2>/dev/null >>$dir/$div-course-list-taxo.csv
cat $dir/$dept-course-titles.csv 2>/dev/null >>$dir/$div-course-titles.csv
cat $dir/$dept-courses.csv 2>/dev/null >>$dir/$div-courses.csv
cat $dir/$dept-faculty-names.csv 2>/dev/null >>$dir/$div-faculty-names.csv
cat $dir/$dept-section-names.csv 2>/dev/null >>$dir/$div-section-names.csv
csvcut -c 7 $dir/$dept.csv 2>/dev/null | sort | uniq | sed '/""/d' >>$dir/$div-xlist.csv
end
# upload new, division-level CSVs to appropriate taxonomies
# main course list
set tax "$div - COURSE LIST"
set uuid (jq -r ".results[] | select(.name == \"$tax\") | .uuid" $taxo_file)
if [ -n "$uuid" ]
log "Updating $tax taxonomy"
log (uptaxo --tid $uuid --pw $pw --un $un \
--csv $dir/$div-course-list-taxo.csv)
end
# course titles
set tax "$div - course titles"
set uuid (jq -r ".results[] | select(.name == \"$tax\") | .uuid" $taxo_file)
if [ -n "$uuid" ]
log "Updating $tax taxonomy"
log (uptaxo --tid $uuid --pw $pw --un $un \
--csv $dir/$div-course-titles.csv)
end
# faculty names
set tax "$div - faculty"
set uuid (jq -r ".results[] | select(.name == \"$tax\") | .uuid" $taxo_file)
if [ -n "$uuid" ]
log "Updating $tax taxonomy"
log (uptaxo --tid $uuid --pw $pw --un $un \
--csv $dir/$div-faculty-names.csv)
end
# course names e.g. ARCHT-101
set tax "$div - course names"
set uuid (jq -r ".results[] | select(.name == \"$tax\") | .uuid" $taxo_file)
if [ -n "$uuid" ]
log "Updating $tax taxonomy"
log (uptaxo --tid $uuid --pw $pw --un $un \
--csv $dir/$div-courses.csv)
end
# course sections
set tax "$div - course sections"
set uuid (jq -r ".results[] | select(.name == \"$tax\") | .uuid" $taxo_file)
if [ -n "$uuid" ]
log "Updating $tax taxonomy"
log (uptaxo --tid $uuid --pw $pw --un $un \
--csv $dir/$div-section-names.csv)
end
# XList IDs
set tax "$div - cross-list keys"
set uuid (jq -r ".results[] | select(.name == \"$tax\") | .uuid" $taxo_file)
if [ -n "$uuid" ]
log "Updating $tax taxonomy"
log (uptaxo --tid $uuid --pw $pw --un $un \
--csv $dir/$div-xlist.csv)
end