Created
June 19, 2019 14:03
-
-
Save bitmvr/dd8de481f8c6a2d1452c7da503f23783 to your computer and use it in GitHub Desktop.
Get the duration for all GOT episodes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
WIKIPEDIA_ENDPOINT='https://en.wikipedia.org/' | |
getEpisodes(){ | |
local route='/wiki/List_of_Game_of_Thrones_episodes' | |
curl -sL "${WIKIPEDIA_ENDPOINT}${route}" | pup '.wikiepisodetable tr > td:nth-of-type(2) a attr{href}' | |
} | |
getRuntime(){ | |
local route="$1" | |
curl -sL "${WIKIPEDIA_ENDPOINT}${route}" | pup ':parent-of(:contains("Running time")) > td text{}' | head -1 | |
} | |
urldecode(){ | |
sed 's/+/ /g;s/%\(..\)/\\x\1/g;' | |
} | |
num=0 | |
for episode in $(getEpisodes); do | |
runtime="$(getRuntime "$episode" | sed "s/ minutes//g")" | |
echo "$(echo "${episode##/wiki/}" | sed s/_/' '/g | urldecode): ${runtime} minutes" | |
num=$(( num + runtime )) | |
done | |
echo "Total Minutes: $num" | |
echo "Total Hours: $(( num / 60 ))" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment