Category Archives: dev

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!

Google Maps API x Joomla x More

To start playing with Google Maps API I began with Using PHP/MySQL with Google Maps – Google Maps API – Google Code to create a location map for my high school reunion website.  For the reunion website map I used the Googlemaps plugin on on Joomla Extension Directory.  It was easy to get going, just follow the Google Code walk through, create a db file and the generate kml.  Once kml is generated place url into the Googlemaps plugin and your map is ready. For the reunion websites map, I created a form for registration.   When someone registers or submits their contact information they are added to the db and the kml data for the map is pulled and displayed via the Joomla plugin.

So I tried this tutorial again and decided to modify the map a bit more then I did previously. This time I wasnt using on Joomla and just getting some more experience with kml and modifying maps.

[iframe http://mkahn.com/dev/gmaps/index5.html 520 350]
The few properties I modified

[code lang=”html”]
map.setMapType(G_HYBRID_MAP);
map.addControl(new GLargeMapControl3D());
map.setCenter(new GLatLng(28.540519, -81.378864), 2);[/code]

Thats really it, nothing major

Few links that helped-

Geocoding resources
Batch conversion of addresses to lat lng
Map icons
Map Basics
Map Reference
Google Maps API Tutorial

Next I plan to play with polygons, draggable markers, and use xml to display infoWindow information.  I’ll update this post after I make more progress.

Email to SMS and MMS

Most cell phone carriers have SMS gateways which take email messages and deliver to cell phones via SMS and MMS.  The carriers email address (ex:  10digitnumber@txt.att.net) determines the destination so if you do not know the correct email, the message will not reach the phone. If you are unsure of the carrier you are delivering to there are teleco databases that allow you to input the area code and prefix or exchange to find the provider.
TelecoData.us
FoneFinder

Once you know the users number and their cell phone provider you can then deliver a SMS/MMS message via email to their device.  Sending email to SMS/MMS can be useful for notification scripts and specialized software modules or if you simply need to send a quick note to someone without a your phone.  SMS notifications are a great way to ping someone since many people keep their cell phone on their hip or next to their bed stand.

Below is a list of carriers and their respective cell phone email addresses.  Most of these are unverified so if you experience any trouble or know of any changes please leave a comment.

Major Carriers:

Alltel
[10-digit phone number]@message.alltel.com?SMS/MMS: 1234567890@message.alltel.com

AT&T
[10-digit phone number]@txt.att.net
SMS: 1112223333@txt.att.net
MMS:  1112223333@mms.att.net
1112223333@mms.mycingular.com

Boost Mobile
[10-digit phone number]@myboostmobile.com
SMS/MMS: SMS/MMS:  1112223333@myboostmobile.com

Centennial Wireless
[10-digit phone number]@myblue.com
SMS/MMS:  1112223333@myblue.com

Nextel
[10-digit telephone number]@messaging.nextel.com?SMS/MMS: SMS/MMS:  1112223333@messaging.nextel.com

Sprint PCS
[10-digit phone number]@messaging.sprintpcs.com?SMS/MMS: SMS/MMS:  1112223333@messaging.sprintpcs.com
ALT:  1112223333@pm.sprint.com

T-Mobile
[10-digit phone number]@tmomail.net
SMS/MMS:  1112223333@tmomail.net

US Cellular
SMS/MMS:  1112224444@mms.uscc.net

Verizon
[10-digit phone number]@vtext.com
SMS: 1112223333@vtext.com
MMS:  1112223333@vzwpix.com

Virgin Mobile USA
[10-digit phone number]@vmobl.com
SMS/MMS:  1112223333@vmobl.com

Additional carriers here (117 addresses)

Via SMS411 and modmyi

How to change the color and format of your bash prompt

I was recently asked how to change the color on the bash prompt so I put together this article

Here is your bash prompt in all its glory

root@server1 [~]#

# is for root access
$ is for user access

Display the current environment variable (PS1)

root@server1 [~]# echo $PS1
\u@\h [\w]#

PS1 is our bash shell environment variable

By default the command prompt above is set to \u@\h [\W]# This will vary on different distros of Linux

\u : Display the username
\h : Display the hostname
[\W] : Print the current working directory in [ ]’s

Variable list
\a The ASCII bell character (you can also type \007)
\d Date in “Wed Sep 06” format \e ASCII escape character (you can also type \033)
\h First part of hostname (such as “mybox”)
\H Full hostname (such as “mybox.mydomain.com”)
\l The name of the shell’s terminal device (such as “ttyp4”)
\j The number of processes you’ve suspended in this shell by hitting ^Z
\n Newline \r Carriage return \s The name of the shell executable (such as “bash”)
\t Time in 24-hour format (such as “23:01:01”)
\T Time in 12-hour format (such as “11:01:01”)
\@ Time in 12-hour format with am/pm
\u Your username
\v Version of bash (such as 2.04)
\V Bash version, including patchlevel
\w Current working directory (such as “/home/user”)
\W The “basename” of the current working directory (such as “mkahn”)
\! Current command’s position in the history buffer
\# Command number (this will count up at each prompt, as long as you type something)
\\$ If you are not root, inserts a “$”; if you are root, you get a “#”
\xxx Inserts an ASCII character based on three-digit number xxx (replace unused digits with zeros, such as “\007”)
\\ A backslash
\[ This sequence should appear before a sequence of characters that don’t move the cursor (like color escape sequences). This allows bash to calculate word wrapping correctly.
\] This sequence should appear after a sequence of non-printing characters.

Add colors to the prompt
Colors are selected by adding special sequences to PS1 — basically sandwiching numeric values between a “\e[” (escape open-bracket) and an “m”. If we specify more than one numeric code, we separate each code with a semicolon.
\e0;31m – red non bold
\e1;31m – red bold

\e[0m – reset the colors to default values (black and white)

Color codes
Black 0;30 Dark Gray 1;30
Blue 0;34 Light Blue 1;34
Green 0;32 Light Green 1;32
Cyan 0;36 Light Cyan 1;36
Red 0;31 Light Red 1;31
Purple 0;35 Light Purple 1;35
Brown 0;33 Yellow 1;33
Light Gray 0;37 White 1;37
Replace digit 0 with a 1 to get a bold version

Replace 0 digit with 40 (black), 41 (red), 42, (green), 43 (yellow), 44 (blue), 45 (purple), 46 (cyan), 47 (light gray) background color (highlight).

Red color prompt
export PS1="\e[0;31m[\u@\h \w]\\$ \e[0m"

Green color prompt
export PS1="\e[0;32m[\u@\h \w]\\$ \e[0m"


Modify the current bash prompt to display user@full hostname and working directory with time

Setup a new shell prompt:
root@server1 [~]# export PS1="\u@\H [\w] \T \$ "
root@server.mybox.com [/home/myfolder] 01:07:57 $

Explained
PS1 : Current bash prompt
\u : Display the username
@ : @ sign after username
\H : Display the full hostname
[\w] : Display the current working directory in [ ]’s
\T : Display the time in 12 hr format
\$ : display hash


Making it stick

The command ran before were just for that session, when you login it will be lost. If you would like to make this BASH shell modification permanent add the export command to your .bash_profile or .bashrc file

vi .bashrc

.bash_profile (osx) and .bashrc (Linux)
use pico or nano if you do not know how to use vi

Add export line before fi
export PS1="\e[0;31m[\u@\h \w]\\$ \e[0m"

Save and close the file
Now you have a cool modified bash shell prompt


Examples

xmas bash prompt1
export PS1="\e[1;32m[\u@\h \e[1;31m\\w\e[1;32m]\$ \e[m"

xmasprompt1
xmas bash prompt 2
export PS1="\e[42;31m[\u@\h \w]\$ \e[m"

xmasprompt2

hanukkah bash prompt
export PS1="\e[0;34m[\u\e[0;34m@\h[\e[0;33m\w\e[0m\e[0m\e[0;34m]#\e[0m "

hanukkahprompt

the matrix
export PS1="\e[0;32m\u@\h [\w]# "

matrix

personal
export PS1="\e[0;32m\u\e[0m\e[0;36m@\e[0m\e[0;34m\h \e[0m\e[0;36m\w \e[0m# "

personalprompt

sources: http://www.pantz.org/software/shell/enhancingshellprompt.html