garbage_generator 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/bash
  2. #
  3. # Garbage generator for writing pseudocredible compliments and reviews about
  4. # many different things, in this case, students.
  5. #
  6. # Assumes that there are 3 different levels of students: Good, Average, Bad.
  7. # Then pursues to try to form pseudorandom reviews by gluing together pre-made
  8. # sentences from a database.
  9. #
  10. # Usage: garbage_generator Name [LEVEL], where LEVEL is {1,2,3}
  11. #
  12. # Data file locations (please do not edit):
  13. overall=overall.txt
  14. attitude=attitude.txt
  15. participation=participation.txt
  16. conclusion=conclusion.txt
  17. # Default values that can be overrided by command-line switches:
  18. LEVEL=2 # goes from 1 (bad) to 3 (good)
  19. NAME="James Joyce" # Any string works. Quote for full name!
  20. helper() {
  21. cat <<EOF
  22. $(basename $0) - generate random reviews of students.
  23. USAGE: garbage_generator -n Name -l [LEVEL], where LEVEL is {1,2,3}
  24. -h: prints this help message.
  25. EOF
  26. exit 0
  27. }
  28. # Get options:
  29. if [[ -t 1 ]]
  30. then
  31. # Normal program execution
  32. echo "We are in terminal"
  33. while [[ -n "$1" ]]
  34. do
  35. case "$1" in
  36. "-h" | "--help" ) helper
  37. ;;
  38. "-n" )
  39. shift
  40. NAME="$1"
  41. ;;
  42. "-l" )
  43. shift
  44. case "$1" in
  45. "1" ) LEVEL=1
  46. ;;
  47. "2" ) LEVEL=2
  48. ;;
  49. "3" ) LEVEL=3
  50. ;;
  51. * )
  52. echo "Level must be between 1 and 3"
  53. exit 1
  54. ;;
  55. esac
  56. ;;
  57. * ) echo "Unrecognized option."
  58. helper
  59. exit 1
  60. ;;
  61. esac
  62. shift
  63. done
  64. else # We are part of an automation script. Get name from stdin!
  65. LEVEL=2
  66. read NAME
  67. fi
  68. # Filter sentence databases based on the student's skill, and build the review:
  69. sentence=$(cat overall.txt | grep "$LEVEL" | shuf | head -1 | cut -d "_" -f 2 )
  70. sentence="$sentence $NAME $(cat attitude.txt | grep $LEVEL | shuf | head -1 | cut -d _ -f 2 )"
  71. sentence="$sentence $NAME $(cat participation.txt | grep $LEVEL | shuf | head -1 | cut -d _ -f 2 )"
  72. sentence="$sentence $NAME $(cat conclusion.txt | grep $LEVEL | shuf | head -1 | cut -d _ -f 2 )"
  73. # print out the final statement.
  74. echo "$NAME $sentence"