Created
November 24, 2011 13:52
-
-
Save hmarr/1391393 to your computer and use it in GitHub Desktop.
Determine Barclays Bike availability via the command line
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
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)' | |
data=$(curl -sA "$user_agent" "$url" | grep ShowInfoB | grep -i "$location") | |
echo $data | 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