Skip to content

Instantly share code, notes, and snippets.

@zacharyvoase
Forked from hmarr/bbikes.sh
Created November 24, 2011 14:02
Show Gist options
  • Save zacharyvoase/1391419 to your computer and use it in GitHub Desktop.
Save zacharyvoase/1391419 to your computer and use it in GitHub Desktop.
Determine Barclays Bike availability via the command line
function bbikes {
location=${1:-$DEFAULT_BBIKE_LOCATION}
if [ -z $location ]; then
echo "usage: bbikes <location>"
echo "(you can also set a default location with DEFAULT_BBIKE_LOCATION)"
return 1
fi
url='https://web.barclayscyclehire.tfl.gov.uk/maps'
user_agent='Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US)'
curl -sA "$user_agent" "$url" | grep ShowInfoB | grep -i "$location" | while read line; do
name=$(echo $line | sed 's/.*name:"\([^"]*\)".*/\1/')
echo $name
num_bikes=$(echo $line | sed 's/.*nbBikes:"\([0-9]*\)".*/\1/')
num_spaces=$(echo $line | sed 's/.*nbEmptyDocks:"\([0-9]*\)".*/\1/')
echo "$num_bikes bikes available"
echo "$num_spaces spaces available"
echo
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment