Skip to content

Instantly share code, notes, and snippets.

@sulhome
Created August 27, 2016 23:43
Show Gist options
  • Save sulhome/8f1cc1b5b80d375efbbe8b33f5c592e2 to your computer and use it in GitHub Desktop.
Save sulhome/8f1cc1b5b80d375efbbe8b33f5c592e2 to your computer and use it in GitHub Desktop.
display most read stories on bbc from bash
#!/usr/bin/env bash
function command_exists () {
type "$1" &> /dev/null ;
}
function print_error() {
printf "\e[31m Error \e[0m: %s \n" "$1"
}
# Check that required tools are installed
if ! command_exists lynx; then
print_error "you need lynx to run this program. please visit: http://lynx.browser.org/"
exit 1
fi
if ! command_exists hxnormalize || ! command_exists hxselect; then
print_error "you need html-xml-utils to run this program. please visit http://packages.ubuntu.com/trusty/text/html-xml-utils"
exit 1
fi
rawList=$(wget -O - -q "http://www.bbc.co.uk/news/popular/read" |
hxnormalize -x 2>/dev/null |
hxselect -i "ul.most-popular-page__list")
stringToMatch="href=\"\/"
stringToReplace="href=\"http://bbc.co.uk/"
if [[ $1 == "in-lynx" ]]; then
echo "${rawList//$stringToMatch/$stringToReplace}" | lynx -stdin
exit 0
fi
echo "${rawList//$stringToMatch/$stringToReplace}" | lynx -stdin -dump
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment