Automate Florida Lottery Number Checking With This Bash Script

So I’m helping my dad with some automation to get him to do things differently. Once thing he does is regularly is check lottery numbers twice a week every week for the past 40+ years. To me its too routine and something that can be automated easily. I’m going to complete this task in 2 steps. First step which is done below is the application that sets up the environment and scrapes data. Second step is a cron that can be setup through the application and installed to validate saved numbers against winning published numbers. This way instead of manually matching his numbers with winning numbers he’ll get an email twice a week and the script will determine if his regular numbers had any luck.

Screen Shot 2015-06-14 at 1.23.30 PM


#!/bin/bash
# Florida Lottery number checker
# mkahnucf@gmail.com
# ver 1.0
# Requires perl and lynx
# Menu source http://bash.cyberciti.biz/guide/Menu_driven_scripts
RED='\033[0;41;30m'
STD='\033[0;0;39m'

pause(){
read -p "Press [Enter] key to continue..." fackEnterKey
}

one(){
read -p "Enter date in mm dd yy format " NUMBER1 NUMBER2 NUMBER3
echo "Ok, lets check for $NUMBER1/"$NUMBER2/$NUMBER3
lynx -dump http://flalottery.com/exptkt/l6.htm | grep "$NUMBER1"/"$NUMBER2"/"$NUMBER3" | cut -b 4-41
pause
}

two(){
YESTERDAY=$(perl -e 'use POSIX;print strftime "%m/%d/%y",localtime time-86400;')
echo "Ok, lets check numbers for" $YESTERDAY
RESULTS="$(lynx -dump http://flalottery.com/exptkt/l6.htm | grep "$YESTERDAY")"
if [ "$RESULTS" == "" ]; then
echo "There was no lottery yesterday $YESTERDAY !"
else
lynx -dump http://flalottery.com/exptkt/l6.htm | grep "$YESTERDAY" | cut -b 4-41
fi
pause
}

three(){
#Store numbers
read -p "Enter numbers in xx xx xx xx xx xx format " NUM1 NUM2 NUM3 NUM4 NUM5 NUM6
echo $NUM1 $NUM2 $NUM3 $NUM5 $NUM6 >> saved-numbers.txt
echo "Ok, i've saved your numbers $NUM1 $NUM2 $NUM3 $NUM5 $NUM6"
pause
}

four(){
SAVEDNUM=$( saved-numbers.txt
echo "Ok ive cleared your saved numbers"
pause
}

show_menus() {
clear
echo "~~~~~~~~~~~~~~~~~~~~~"
echo "Florida Lottery Number Checker"
echo "~~~~~~~~~~~~~~~~~~~~~"
echo "1. Check numbers from a specific date in the past"
echo "2. Check numbers from yesterday"
echo "3. Store numbers for auto-checking"
echo "4. List numbers saved for auto-checking"
echo "5. Clear stored numbers for auto-checking"
echo "6. Exit"
}
read_options(){
local choice
read -p "Enter choice [1 - 6] " choice
case $choice in
1) one ;;
2) two ;;
3) three ;;
4) four ;;
5) five ;;
6) exit 0;;
*) echo -e "${RED}Error...${STD}" && sleep 2
esac
}

trap '' SIGINT SIGQUIT SIGTSTP

while true
do

show_menus
read_options
done

I’ll update this post once the second half is done!