Skip to content

Instantly share code, notes, and snippets.

@colinmahns
Last active April 19, 2017 15:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colinmahns/003c3e9c958911d742c58180bc70f2bb to your computer and use it in GitHub Desktop.
Save colinmahns/003c3e9c958911d742c58180bc70f2bb to your computer and use it in GitHub Desktop.
Quick, not optimized bash script to run in a cronjob at the end of the day. This will print the number of available bikes near a hard coded location and how many bike racks are available near New York's scenic Port Authority Bus Terminal.
#!/bin/bash
## Quick script to mention how many bikes are available near $EMPLOYER
## Will also show how many bike racks are available near PABT
## relies on curl and jq
## curl: https://curl.haxx.se/
## jq: https://stedolan.github.io/jq/
URL="https://feeds.citibikenyc.com/stations/stations.json"
JSON="/tmp/citibike.json"
## specify starting point (bike) and destination (racks)
BIKES="stripped for workplace privacy"
RACKS="\"W 42 St & Dyer Ave\",\"W 42 St & 8 Ave\",\"W 41 St & 8 Ave\",\"W 39 St & 9 Ave\",\"W 38 St & 8 Ave\""
## setting up the full path aliases, to deal with cron's fuckery
CURL="$(which curl) -s"
ECHO="$(which echo)"
JQ="$(which jq)"
AWK="$(which awk)"
SED="$(which sed)"
CAT="$(which cat)"
## this will download the most recent json from citibike and will put it in /tmp, because I'm bad at readlines
$CURL $URL > $JSON
$ECHO "Station🚏 Bikes🚲"
## grab the station names for the three racks near $EMPLOYER along with number of available bikes for rental
$CAT $JSON | $JQ ".stationBeanList | .[] | select(.stationName | contains($BIKES)) | .stationName,.availableBikes" | $AWK 'NR%2{printf "%s ",$0;next;}1' | $SED 's/\"//g'
$ECHO "Station🚏 Docks🔓"
## grab the station names near pabt along with number of available bike docks
$CAT $JSON | $JQ ".stationBeanList | .[] | select(.stationName | contains($RACKS)) | .stationName,.availableDocks" | $AWK 'NR%2{printf "%s ",$0;next;}1' | $SED 's/\"//g'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment