Add script to append exercices
This commit is contained in:
parent
8465f442c6
commit
d4ee546a91
1 changed files with 124 additions and 0 deletions
124
admin/fill_exercices.sh
Executable file
124
admin/fill_exercices.sh
Executable file
|
@ -0,0 +1,124 @@
|
|||
#!/bin/sh
|
||||
|
||||
BASEURL="http://localhost:8081"
|
||||
BASEURI="http://srs.epita.fr/owncloud/remote.php/webdav/FIC 2016/"
|
||||
|
||||
new_theme() {
|
||||
NAME="$1"
|
||||
curl -f -s -d "{\"name\": \"$NAME\"}" "${BASEURL}/api/themes/" |
|
||||
grep -Eo '"id":[0-9]+,' | grep -Eo "[0-9]+"
|
||||
}
|
||||
|
||||
new_exercice() {
|
||||
THEME="$1"
|
||||
TITLE="$2"
|
||||
STATEMENT="$3"
|
||||
HINT="$4"
|
||||
DEPEND="$5"
|
||||
GAIN="$6"
|
||||
VIDEO="$7"
|
||||
|
||||
curl -f -s -d "{\"title\": \"$TITLE\", \"statement\": \"$STATEMENT\", \"hint\": \"$HINT\", \"depend\": $DEPEND, \"gain\": $GAIN, \"videoURI\": \"$VIDEO\"}" "${BASEURL}/api/themes/$THEME" |
|
||||
grep -Eo '"id":[0-9]+,' | grep -Eo "[0-9]+"
|
||||
}
|
||||
|
||||
new_file() {
|
||||
THEME="$1"
|
||||
EXERCICE="$2"
|
||||
URI="$3"
|
||||
|
||||
curl -f -s -d "{\"URI\": \"$URI\"}" "${BASEURL}/api/themes/$THEME/$EXERCICE/files" |
|
||||
grep -Eo '"id":[0-9]+,' | grep -Eo "[0-9]+"
|
||||
}
|
||||
|
||||
new_key() {
|
||||
THEME="$1"
|
||||
EXERCICE="$2"
|
||||
NAME="$3"
|
||||
KEY="$4"
|
||||
|
||||
curl -f -s -d "{\"name\": \"$NAME\", \"key\": \"$KEY\"}" "${BASEURL}/api/themes/$THEME/$EXERCICE/keys" |
|
||||
grep -Eo '"id":[0-9]+,' | grep -Eo "[0-9]+"
|
||||
}
|
||||
|
||||
# Theme
|
||||
while read -p "Theme name: " THEME_NAME
|
||||
do
|
||||
if [ -z "$THEME_NAME" ]; then
|
||||
break
|
||||
fi
|
||||
|
||||
THEME_ID=`new_theme "$THEME_NAME"`
|
||||
echo ">>> New theme created: $THEME_ID - $THEME_NAME"
|
||||
|
||||
LAST=null
|
||||
EXO_NUM=1
|
||||
THM_BASEURI=
|
||||
echo
|
||||
echo "--- Filling exercice ${EXO_NUM} in theme ${THEME_NAME}"
|
||||
while read -p "Exercice title (^D to pass to the next theme) [Exercice ${EXO_NUM}]: " EXO_NAME
|
||||
do
|
||||
if [ -z "${EXO_NAME}" ]; then
|
||||
EXO_NAME="Exercice ${EXO_NUM}"
|
||||
fi
|
||||
|
||||
if [ "${LAST}" = "null" ]; then
|
||||
echo ">>> Assuming this exercice has no dependency"
|
||||
else
|
||||
echo ">>> Assuming this exercice depends on the last entry (id=${LAST})"
|
||||
fi
|
||||
|
||||
EXO_GAIN=$((5 ** $EXO_NUM))
|
||||
echo ">>> Using default gain: ${EXO_GAIN} points"
|
||||
|
||||
echo "--- Enter the description for ${EXO_NUM} in theme ${THEME_NAME}"
|
||||
EXO_DESC=`cat`
|
||||
|
||||
echo "--- Enter the optional hint for ${EXO_NUM} in theme ${THEME_NAME}"
|
||||
EXO_HINT=`cat`
|
||||
|
||||
if [ -z "${THM_BASEURI}" ]
|
||||
then
|
||||
read -p "Base URI for the theme: ${BASEURI}" THM_BASEURI
|
||||
fi
|
||||
|
||||
read -p "Video URI: ${BASEURI}${THM_BASEURI}" EXO_VIDEO
|
||||
|
||||
EXO_ID=`new_exercice "${THEME_ID}" "${EXO_NAME}" "${EXO_DESC}" "${EXO_HINT}" "${LAST}" "${EXO_GAIN}" "${EXO_VIDEO}"`
|
||||
echo ">>> New exercice created: $EXO_ID - $EXO_NAME"
|
||||
|
||||
|
||||
# Keys
|
||||
while read -p "New key: " KEY_RAW
|
||||
do
|
||||
if [ -z "${KEY_RAW}" ]
|
||||
then
|
||||
break
|
||||
fi
|
||||
|
||||
read -p "Key type/kind/hint: " KEY_TYPE
|
||||
|
||||
KEY_ID=`new_key "${THEME_ID}" "${EXO_ID}" "${KEY_TYPE}" "${KEY_RAW}"`
|
||||
echo ">>> New key created: $KEY_ID - $KEY_TYPE"
|
||||
done
|
||||
|
||||
|
||||
# Files
|
||||
while read -p "Import file ${BASEURI}${THM_BASEURI}" FILE_URI
|
||||
do
|
||||
if [ -z "${FILE_URI}" ]
|
||||
then
|
||||
break
|
||||
fi
|
||||
|
||||
FILE_ID=`new_file "${THEME_ID}" "${EXO_ID}" "${BASEURI}${THM_BASEURI}${FILE_URI}"`
|
||||
echo ">>> New file added: $FILE_ID - $FILE_URI"
|
||||
done
|
||||
|
||||
|
||||
LAST=$EXO_ID
|
||||
EXO_NUM=$((EXO_NUM + 1))
|
||||
echo
|
||||
echo "--- Filling exercice ${EXO_NUM} in theme ${THEME_NAME}"
|
||||
done
|
||||
done
|
Reference in a new issue