Skip to content

Instantly share code, notes, and snippets.

@bitmvr
Created June 19, 2019 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bitmvr/dd8de481f8c6a2d1452c7da503f23783 to your computer and use it in GitHub Desktop.
Save bitmvr/dd8de481f8c6a2d1452c7da503f23783 to your computer and use it in GitHub Desktop.
Get the duration for all GOT episodes.
#!/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