made a basic bb script output with a 1 minute rotating display and unicode characters
This commit is contained in:
parent
3027153951
commit
0b9c8429b8
@ -5,9 +5,22 @@ timeout=120 # in seconds
|
|||||||
refresh_rate=10 # display each station for 10 seconds
|
refresh_rate=10 # display each station for 10 seconds
|
||||||
WORKINGDIR="$HOME/.dotfiles/bin/bluebikes"
|
WORKINGDIR="$HOME/.dotfiles/bin/bluebikes"
|
||||||
|
|
||||||
|
if [[ ! -d "$WORKINGDIR/data" ]] ; then
|
||||||
|
mkdir -p "$WORKINGDIR/data"
|
||||||
|
fi
|
||||||
|
|
||||||
# getting time and existing information
|
# getting time and existing information
|
||||||
TIME=$(date +%s)
|
TIME=$(date +%s)
|
||||||
OLD_EXPIRATION=$(ls "$WORKINGDIR/data/" | cut -d '.' -f 1 2>/dev/null) # removes .json extension
|
OLD_EXPIRATION=$(ls "$WORKINGDIR/data" | cut -d '.' -f 1 2>/dev/null) # removes .json extension
|
||||||
|
|
||||||
|
get_station_info() {
|
||||||
|
# cleans data folder and leaves only most recent copy
|
||||||
|
rm "$WORKINGDIR/data/"*.json 2>/dev/null
|
||||||
|
BB_STATUS=$(curl --silent -fL https://gbfs.bluebikes.com/gbfs/en/station_status.json)
|
||||||
|
EXPIRATION=$(($TIME + 120)) # sets expiration to be in 120 seconds
|
||||||
|
echo "$BB_STATUS" > "$WORKINGDIR/data/$EXPIRATION.json"
|
||||||
|
#echo $EXPIRATION
|
||||||
|
}
|
||||||
|
|
||||||
update_stations() {
|
update_stations() {
|
||||||
# checks to see if we are out of date and sets $output to be station info
|
# checks to see if we are out of date and sets $output to be station info
|
||||||
@ -17,26 +30,27 @@ update_stations() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
STATIONS=$(cat "$WORKINGDIR/conf.json" | gojq '.stations') # stations we care about from config file
|
STATIONS=$(cat "$WORKINGDIR/conf.json" | gojq '.stations') # stations we care about from config file
|
||||||
STATION_INFO=$(cat "$WORKINGDIR/"data/*.json) # all station information
|
STATION_INFO=$(cat "$WORKINGDIR/"data/*.json 2>/dev/null) # all station information
|
||||||
|
|
||||||
# all associated data for the specific ids
|
# all associated data for the specific ids
|
||||||
info=$(echo "$STATION_INFO" | gojq --argjson js "$STATIONS" '[.data.stations[] | select( .station_id as $id | $js.[].station_id | tostring | . == $id )]')
|
info=$(echo "$STATION_INFO" | gojq --argjson js "$STATIONS" '[.data.stations[] | select( .station_id as $id | $js.[].station_id | tostring | . == $id )]')
|
||||||
# only available bikes/docks for the required ids
|
# only available bikes/docks for the required ids
|
||||||
output=$(echo "$info" | gojq --argjson names "$STATIONS" '.[] | .station_id as $id | [{ id: $id, bikes: .num_bikes_available, docks: .num_docks_available, station: $names.[] | select( .station_id | tostring | . == $id ) | .name }]')
|
output=$(echo "$info" | gojq --argjson names "$STATIONS" '[ .[] | .station_id as $id | { bikes: .num_bikes_available, docks: .num_docks_available, station: $names.[] | select( .station_id | tostring | . == $id ) | .name }]')
|
||||||
|
|
||||||
# echo "$output"
|
# echo "$output"
|
||||||
}
|
}
|
||||||
|
|
||||||
get_station_info() {
|
|
||||||
# cleans data folder and leaves only most recent copy
|
|
||||||
rm "$WORKINGDIR/data/"*.json 2>/dev/null
|
|
||||||
BB_STATUS=$(curl --silent -fL https://gbfs.bluebikes.com/gbfs/en/station_status.json)
|
|
||||||
EXPIRATION=$(($TIME + 120)) # sets expiration to be in 120 seconds
|
|
||||||
echo $EXPIRATION
|
|
||||||
}
|
|
||||||
|
|
||||||
output_status() {
|
output_status() {
|
||||||
# reads $OUTPUT and the Index value
|
# reads $OUTPUT and the Index value
|
||||||
|
minute=$(date +%M | tr -d '0')
|
||||||
|
tot=$(echo "$STATIONS" | gojq '. | length') # display one per minute
|
||||||
|
index=$(( $minute % $tot ))
|
||||||
|
bikes=$(echo "$output" | gojq --arg indx $index '.[$indx | tonumber ].bikes')
|
||||||
|
docks=$(echo "$output" | gojq --arg indx $index '.[$indx | tonumber ].docks')
|
||||||
|
station=$(echo "$output" | gojq --arg indx $index '.[$indx | tonumber ].station' | tr -d '"')
|
||||||
|
printf '%d %d %s' "$docks" "$bikes" "$station"
|
||||||
|
}
|
||||||
|
|
||||||
update_stations # sets $output to be all the stations we are interested in
|
update_stations # sets $output to be all the stations we are interested in
|
||||||
output_status # echos correct station info based on index and time
|
output_status # echos correct station info based on index and time
|
||||||
|
@ -11,9 +11,9 @@ if [[ $CUR_TIMESTAMP -gt $EXPIRATION || -z $EXPIRATION ]] ; then
|
|||||||
WEATHER=$(curl --silent http://api.openweathermap.org/data/2.5/weather\?lat="$LAT"\&lon="$LON"\&appid="$API_KEY"\&units=imperial)
|
WEATHER=$(curl --silent http://api.openweathermap.org/data/2.5/weather\?lat="$LAT"\&lon="$LON"\&appid="$API_KEY"\&units=imperial)
|
||||||
|
|
||||||
echo $WEATHER
|
echo $WEATHER
|
||||||
TEMP=$(echo $WEATHER | jq -r '.main.temp')
|
TEMP=$(echo $WEATHER | gojq -r '.main.temp')
|
||||||
HUMIDITY=$(echo $WEATHER | jq -r '.main.humidity')
|
HUMIDITY=$(echo $WEATHER | gojq -r '.main.humidity')
|
||||||
ICON=$(echo $WEATHER | jq -r '.weather[0].icon')
|
ICON=$(echo $WEATHER | gojq -r '.weather[0].icon')
|
||||||
EXPIRATION=$(($CUR_TIMESTAMP+30))
|
EXPIRATION=$(($CUR_TIMESTAMP+30))
|
||||||
|
|
||||||
printf 'TEMP=%s\nHUMIDITY=%s\nICON=%s\nEXPIRATION=%s\n' "$TEMP" "$HUMIDITY" "$ICON" "$EXPIRATION" >"$HOME/.dotfiles/bin/weather/.env.weather"
|
printf 'TEMP=%s\nHUMIDITY=%s\nICON=%s\nEXPIRATION=%s\n' "$TEMP" "$HUMIDITY" "$ICON" "$EXPIRATION" >"$HOME/.dotfiles/bin/weather/.env.weather"
|
||||||
|
@ -25,8 +25,8 @@ set -g status-interval 5
|
|||||||
set -g status-style "bg=black, fg=white"
|
set -g status-style "bg=black, fg=white"
|
||||||
set -g status-right "#(~/.dotfiles/bin/docker.sh) | #(~/.tmux/plugins/tmux-mem-cpu-load/tmux-mem-cpu-load -p -i 1 -a 1)|#[default] %a %l:%M "
|
set -g status-right "#(~/.dotfiles/bin/docker.sh) | #(~/.tmux/plugins/tmux-mem-cpu-load/tmux-mem-cpu-load -p -i 1 -a 1)|#[default] %a %l:%M "
|
||||||
set -g status-right-length 100
|
set -g status-right-length 100
|
||||||
set -g status-left "#(~/.dotfiles/bin/weather/weather) | #(~/.dotfiles/bin/water/water.sh) |"
|
set -g status-left "#(~/.dotfiles/bin/weather/weather) | #(~/.dotfiles/bin/bluebikes/get_status.sh) | #(~/.dotfiles/bin/water/water.sh) |"
|
||||||
set -g status-left-length 40
|
set -g status-left-length 100
|
||||||
|
|
||||||
# tmux auto start
|
# tmux auto start
|
||||||
set -g @plugin 'tmux-plugins/tmux-resurrect'
|
set -g @plugin 'tmux-plugins/tmux-resurrect'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user