summaryrefslogtreecommitdiff
path: root/dump.sh
diff options
context:
space:
mode:
authorkaa <kaa@disroot.org>2023-11-19 11:32:23 -0800
committerkaa <kaa@disroot.org>2023-11-19 11:32:23 -0800
commit3df21ef899aafd2461570687ef3b9b1c9f9a555e (patch)
tree91659e8964062709853460ad9ee80dbd1099edc9 /dump.sh
parentc11b26e1f75b643997787b76f5181731058a28f9 (diff)
Dump Canvas account directory structure. Start of directory parsing.
Diffstat (limited to 'dump.sh')
-rwxr-xr-xdump.sh38
1 files changed, 37 insertions, 1 deletions
diff --git a/dump.sh b/dump.sh
index 21ae5da..18ed1f4 100755
--- a/dump.sh
+++ b/dump.sh
@@ -1,4 +1,40 @@
#!/bin/sh
-curl -s -X GET "https://sdccd.instructure.com/api/v1/users/self/files" -H "Authorization: Bearer $CANKEY" | tr '}' '\n' | sed -e 's/{//g' -e's/\[//g' -e 's/\]//g' -e 's/^,//g' > dump
+cd dump
+base=https://sdccd.instructure.com/api/v1/
+get()
+{
+ url=$base$1
+ curl -s -X GET "$url" -H "Authorization: Bearer $CANKEY" | tr '}' '\n' | sed -e 's/{//g' -e's/\[//g' -e 's/\]//g' -e 's/^,//g'
+}
+get users/self/folders > folders
+get users/self/files > files
+fi
+
+get_id()
+{
+ < folders sed -e 's/,.*//g' -e 's/.*://g'
+}
+
+# Recursively resolve directories and files.
+# Empty response: []
+get_dir()
+{
+ id=$1
+ echo $id
+ mkdir $id
+ cd $id
+ get folders/$id/files > files
+ get folders/$id/folders > folders
+ for i in $(get_id)
+ do
+ get_dir $i
+ done
+ cd ..
+}
+
+for i in $(get_id)
+do
+ get_dir $i
+done