Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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