Last active
December 17, 2015 22:02
-
-
Save englehardt/cb0855b5a29e026f0f81 to your computer and use it in GitHub Desktop.
Prints the next few Lawrence/Lakeside buses departure times from the Princeton CS department.
This file contains hidden or 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
#!/bin/bash | |
# Bus times last updated 2015-11-04 | |
# Steven Englehardt (github.com/englehardt) | |
bus_times=('7:16' '7:46' '8:16' '8:26' '8:36' '8:46' '8:56' '9:06' '9:16' '9:26' '9:36' '9:46' '9:56' '10:06' '10:16' '10:26' '10:36' '10:46' '10:56' '11:06' '11:16' '11:46' '12:16' '12:46' '13:16' '13:46' '14:16' '14:46' '15:16' '15:46' '16:16' '16:46' '17:16' '17:46' '18:16' '18:31' '18:46' '19:01' '19:16' '19:31' '19:46' '20:19' '21:04' '21:49' '22:34' '23:19') | |
on_demand=('22:00' '3:00') | |
limit=4 | |
if [ $# -eq 1 ]; then | |
limit=$1 | |
fi | |
printed=0 | |
printf '\n Next bus departure times from the Friend Center \n' | |
for i in ${bus_times[@]}; do | |
diff=$(((`date --date=$i +%s` -`date +%s`)/60)) | |
if [ $diff -gt 0 ]; then | |
echo ' --' `date --date=$i +%I:%M%p` ' (' $diff ' minutes)' | |
((printed++)) | |
fi | |
if [ $printed -ge $limit ]; then | |
break | |
fi | |
done | |
if [ $(date +%s) -gt $(date --date=${on_demand[0]} +%s) ] || \ | |
[ $(date +%s) -lt $(date --date=${on_demand[1]} +%s) ]; then | |
diff=$(((`date --date=${on_demand[1]} +%s` -`date +%s`)/60)) | |
if [ $diff -lt 0 ]; then | |
diff=$(($diff + 1440)) | |
fi | |
end_time=`date --date=${on_demand[1]} +%I:%M%p` | |
echo ' -- On-demand bus until' $end_time '('$diff 'minutes) - 609.258.7433' | |
fi | |
printf '\n' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment