Added bluebikes status tracker for getting station information
This commit is contained in:
		
							parent
							
								
									6161842f72
								
							
						
					
					
						commit
						d36f93999b
					
				
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@ -5,3 +5,4 @@ bin/water/waterintake
 | 
				
			|||||||
bin/weather/.env*
 | 
					bin/weather/.env*
 | 
				
			||||||
*.swp
 | 
					*.swp
 | 
				
			||||||
bin/startup/*.json
 | 
					bin/startup/*.json
 | 
				
			||||||
 | 
					bin/bluebikes/data
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										24
									
								
								bin/bluebikes/conf.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								bin/bluebikes/conf.json
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,24 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					  "stations": [
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      "name": "Mass Ave / Amherst",
 | 
				
			||||||
 | 
					      "station_id": 67
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      "name": "Longfellow Elementary",
 | 
				
			||||||
 | 
					      "station_id": 413
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        "name": "BCI",
 | 
				
			||||||
 | 
					        "station_id": 80
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        "name": "Stata",
 | 
				
			||||||
 | 
					        "station_id": 107
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        "name": "Grad Housing",
 | 
				
			||||||
 | 
					        "station_id": 179
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  ]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										43
									
								
								bin/bluebikes/get_status.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										43
									
								
								bin/bluebikes/get_status.sh
									
									
									
									
									
										Executable file
									
								
							@ -0,0 +1,43 @@
 | 
				
			|||||||
 | 
					#!/usr/bin/env bash
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# constants
 | 
				
			||||||
 | 
					timeout=120 # in seconds
 | 
				
			||||||
 | 
					refresh_rate=10 # display each station for 10 seconds
 | 
				
			||||||
 | 
					WORKINGDIR="$HOME/.dotfiles/bin/bluebikes"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# getting time and existing information
 | 
				
			||||||
 | 
					TIME=$(date +%s)
 | 
				
			||||||
 | 
					OLD_EXPIRATION=$(ls "$WORKINGDIR/data/" | cut -d '.' -f 1 2>/dev/null) # removes .json extension
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					update_stations() {
 | 
				
			||||||
 | 
					    # checks to see if we are out of date and sets $output to be station info
 | 
				
			||||||
 | 
					    if [[ -z $OLD_EXPIRATION || $OLD_EXPIRATION -lt $EXPIRATION ]] ; then
 | 
				
			||||||
 | 
					        # file doesn't exist or is more than a minute old
 | 
				
			||||||
 | 
					        get_station_info
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    STATIONS=$(cat "$WORKINGDIR/conf.json" | gojq '.stations') # stations we care about from config file
 | 
				
			||||||
 | 
					    STATION_INFO=$(cat "$WORKINGDIR/"data/*.json) # all station information
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # 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 )]')
 | 
				
			||||||
 | 
					    # 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 }]')
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					#    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() {
 | 
				
			||||||
 | 
					    # reads $OUTPUT and the Index value
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					update_stations # sets $output to be all the stations we are interested in
 | 
				
			||||||
 | 
					output_status # echos correct station info based on index and time
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										7
									
								
								vimrc
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								vimrc
									
									
									
									
									
								
							@ -5,7 +5,7 @@ filetype plugin indent on
 | 
				
			|||||||
" set shiftwidth=4
 | 
					" set shiftwidth=4
 | 
				
			||||||
" set expandtab
 | 
					" set expandtab
 | 
				
			||||||
" set backspace=indent,eol,start
 | 
					" set backspace=indent,eol,start
 | 
				
			||||||
set ts=4 sts=4 sw=2 expandtab
 | 
					set ts=4 sts=4 sw=4 expandtab
 | 
				
			||||||
set backspace=indent,eol,start
 | 
					set backspace=indent,eol,start
 | 
				
			||||||
 | 
					
 | 
				
			||||||
" basics
 | 
					" basics
 | 
				
			||||||
@ -86,7 +86,7 @@ nnoremap <silent> fs :GFiles?<CR>
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
" tweaking timeout to quit instatnly via esc
 | 
					" tweaking timeout to quit instatnly via esc
 | 
				
			||||||
set ttimeout
 | 
					set ttimeout
 | 
				
			||||||
set ttimeoutlen=0
 | 
					set ttimeoutlen=100
 | 
				
			||||||
" time to learn vim
 | 
					" time to learn vim
 | 
				
			||||||
noremap <up> :echoerr "Umm, use k instead"<cr>
 | 
					noremap <up> :echoerr "Umm, use k instead"<cr>
 | 
				
			||||||
noremap <down>:echoerr "Umm,use j instead"<cr>
 | 
					noremap <down>:echoerr "Umm,use j instead"<cr>
 | 
				
			||||||
@ -96,3 +96,6 @@ inoremap <up> <NOP>
 | 
				
			|||||||
inoremap <down> <NOP>
 | 
					inoremap <down> <NOP>
 | 
				
			||||||
inoremap <left> <NOP>
 | 
					inoremap <left> <NOP>
 | 
				
			||||||
inoremap <right> <NOP>
 | 
					inoremap <right> <NOP>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					" jq formating
 | 
				
			||||||
 | 
					noremap <silent> gj :%!gojq .<cr>
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user