randate.sh (1619B)
1 #!/bin/sh 2 3 c=0 4 challenge=1 5 flat=0 6 7 OPTS="hc:f" 8 LONGOPTS="help,challenge:,flat" 9 10 parsed=$(getopt --options=$OPTS --longoptions=$LONGOPTS -- "$@") 11 eval set -- "${parsed[@]}" 12 13 while true; do 14 case "$1" in 15 -f|--flat) flat=1 ;; 16 -c|--challenge) 17 c=1 18 challenge=$2 19 shift;; 20 21 --) # end of arguments 22 shift 23 break 24 ;; 25 26 *) 27 printf '%sn' "Error while parsing CLI options" 1>&2 28 ;; 29 esac 30 31 shift 32 done 33 34 successes=0 35 from=0 36 til=0 37 average=0 38 39 if [ "$c" == "1" ]; then 40 clear 41 for i in {3..1}; do 42 echo "$i" 43 sleep 1 44 clear 45 done 46 fi 47 48 for i in $(seq $challenge); do 49 from=$(date "+%s") 50 51 rand=$(shuf -i 1-2147483648 -n 1) 52 export LC_ALL=en_GB.UTF-8 53 date -d "@$rand" '+%A the %d of %B, %Y' 54 export LC_ALL=es_MX.UTF-8 55 56 day=$(python ~/.local/bin/inttoesp.py $(date -d "@$rand" "+%d")) 57 year=$(python ~/.local/bin/inttoesp.py $(date -d "@$rand" "+%Y")) 58 59 if [ "$day" == "uno" ]; then 60 day="primero" 61 fi 62 var=$(date -d "@$rand" "+%A el $day de %B del $year") 63 read user_input 64 65 if [ "$var" == "$user_input" ]; then 66 echo "correcto!" 67 successes=$((successes + 1)) 68 else 69 actual="" 70 for (( j=0; j<${#var}; j++ )); do 71 if [ "${var:$j:1}" == "${user_input:$j:1}" ]; then 72 actual="$actual${var:$j:1}" 73 else 74 actual="$actuale[01;31m${var:$j:1}e[0m" 75 fi 76 done 77 echo -e $actual 78 fi 79 80 til=$(date "+%s") 81 average=$((average + (til - from))) 82 done 83 84 if [ "$c" == "1" ]; then 85 echo "average time: $((average/challenge)) s" 86 echo "total time: $average s" 87 echo "total: $successes / $challenge correct!" 88 fi