12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- #!/bin/bash
- #
- # Garbage generator for writing pseudocredible compliments and reviews about
- # many different things, in this case, students.
- #
- # Assumes that there are 3 different levels of students: Good, Average, Bad.
- # Then pursues to try to form pseudorandom reviews by gluing together pre-made
- # sentences from a database.
- #
- # Usage: garbage_generator Name [LEVEL], where LEVEL is {1,2,3}
- #
- # Data file locations (please do not edit):
- overall=overall.txt
- attitude=attitude.txt
- participation=participation.txt
- conclusion=conclusion.txt
- # Default values that can be overrided by command-line switches:
- LEVEL=2 # goes from 1 (bad) to 3 (good)
- NAME="James Joyce" # Any string works. Quote for full name!
- helper() {
- cat <<EOF
- $(basename $0) - generate random reviews of students.
- USAGE: garbage_generator -n Name -l [LEVEL], where LEVEL is {1,2,3}
- -h: prints this help message.
- EOF
- exit 0
- }
- # Get options:
- if [[ -t 1 ]]
- then
- # Normal program execution
- echo "We are in terminal"
- while [[ -n "$1" ]]
- do
- case "$1" in
- "-h" | "--help" ) helper
- ;;
- "-n" )
- shift
- NAME="$1"
- ;;
- "-l" )
- shift
- case "$1" in
- "1" ) LEVEL=1
- ;;
- "2" ) LEVEL=2
- ;;
- "3" ) LEVEL=3
- ;;
- * )
- echo "Level must be between 1 and 3"
- exit 1
- ;;
- esac
- ;;
- * ) echo "Unrecognized option."
- helper
- exit 1
- ;;
- esac
- shift
- done
- else # We are part of an automation script. Get name from stdin!
- LEVEL=2
- read NAME
- fi
- # Filter sentence databases based on the student's skill, and build the review:
- sentence=$(cat overall.txt | grep "$LEVEL" | shuf | head -1 | cut -d "_" -f 2 )
- sentence="$sentence $NAME $(cat attitude.txt | grep $LEVEL | shuf | head -1 | cut -d _ -f 2 )"
- sentence="$sentence $NAME $(cat participation.txt | grep $LEVEL | shuf | head -1 | cut -d _ -f 2 )"
- sentence="$sentence $NAME $(cat conclusion.txt | grep $LEVEL | shuf | head -1 | cut -d _ -f 2 )"
- # print out the final statement.
- echo "$NAME $sentence"
|