Skip to content

Instantly share code, notes, and snippets.

@caiobegotti
Last active July 8, 2020 12:59
Show Gist options
  • Save caiobegotti/d65aae18073e6248edbebaff725cd0cd to your computer and use it in GitHub Desktop.
Save caiobegotti/d65aae18073e6248edbebaff725cd0cd to your computer and use it in GitHub Desktop.
#!/bin/bash
# public domain
# caio begotti
set -euo pipefail
CSVFILE=$(mktemp)
wget https://raw.githubusercontent.com/caiobegotti/Scripts/master/rottentomatoes-ratings-exporter.csv --quiet -O ${CSVFILE}
for decade in $(cat ${CSVFILE} | sed -e '/^[A-Z]\+/d' -e 's/^\(.*\)\, \([12][0-9]\{3\}\).*$/\2/g' -e 's/[0-9]$//g' | sort -u); do
movies=$(grep -c ", ${decade}[0-9]," ${CSVFILE})
ratings=$(grep ", ${decade}[0-9]," ${CSVFILE} | sed -e 's/^.*\([1-5]\)$/\1/g' | paste -s -d+ - | bc)
# since ratings are between 1-5 only, to give them a better real life value we do this to match 0-10 grades
average=$(echo "scale=2; ${ratings} / ${movies} * 2 + 1" | bc)
# rounded up: echo ${decade}0:${movies}:$(LC_ALL=C printf "%.0f\n" "${average}")
echo ${decade}0:${movies}:${average}
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment