Speed Camera Check

Tell us about your projects. Update us regularly.
Post Reply
parkview
Guru Maker
Posts: 603
Joined: Tue Jun 24, 2014 8:25 pm
Location: Busselton
Contact:

Speed Camera Check

Post by parkview » Mon Jan 26, 2015 9:54 am

Hi,

I drive from Busselton to Bunbury and back every day. It's not very often a Speed camera is present along the route, but I thought it would be nifty to be notified if there was one present on my drive.

If there is one present during the week, the script will email me a copy of the PDF file.

Yes, it could be writing in Python, but I wrote a few test bits in FreeBSD shell script, so I decided to continue on and finish it off as a shell script.

Note: you most probably will have to change the file locations, as this was written to run on a FreeBSD server, not Linux, or a RPi. You can use the 'whereis' cmd to find a file location, ie: on a RPi I get:

# whereis wget
wget: /usr/bin/wget /usr/bin/X11/wget /usr/share/man/man1/wget.1.gz

---------------------------------------------------------
# cat check_weekly_spdcamera.sh
#!/bin/sh
#
# this shell script will download the Police speed camera home page, find the current PDF listing speed camera locations, download it
# convert the PDF file to text. It then searches the text file for any occurrences of town and road names. If found, it emails the
# PDF file to the nominated email address
#
# Requirements:
# * wget - you could also use FreeBSD 'fetch' or curl'
# * pdftotext on FreeBSD, it is part of the xpdf package
# * uuencode - might already be on the unix OS?
#
# Parkview 2015-01-26
#

# Local Variables
HPURL="http://www.police.wa.gov.au/Traffic/CamerasCutCrashes/Camerasworkwhy/Speedcameralocations/tabid/1775/Default.aspx"
LINKURL="http://www.police.wa.gov.au"
OUTFILE="speedcamera-homepage.html"
PDFILE="cameralocations.pdf"
TEXTFILE="cameralocations.txt"
LOCATIONS="Busselton|Dunsborough|Bunbury|Vasse|Capel"
EMAILADDRESS="user@example.org.au"

# go download a copy of the speed camera home page
/usr/local/bin/wget $HPURL -O $OUTFILE

# extract the current link to the PDF
LINK=`/usr/bin/grep "LinkClick" $OUTFILE | head -1 | cut -d'"' -f 4`

# download the current PDF file
/usr/local/bin/wget $LINKURL$LINK -O $PDFILE

# convert the PDF file to a text file
/usr/local/libexec/xpdf/pdftotext $PDFILE $TEXTFILE

# now check the PDF file for various roads and locations
/usr/bin/egrep $LOCATIONS $TEXTFILE
if [ $? -eq 0 ]
then
(cat email-msg.txt; /usr/bin/uuencode $PDFILE $PDFILE ) | /usr/bin/mail -s "Speed camera found!" $EMAILADDRESS
echo "Speed Camera Found!"
else
echo "Nothing found!"
fi

-----------------------------------------------------------

You can then add it to a crontab so that it checks the new file early on Monday each week:

# crontab -e

MAILTO="root"
########################################################################
#min hour mday month wday command
5 6 * * 1 /path/to/script/check_weekly_spdcamera.sh
########################################################################

User avatar
Jubbp
Master Maker
Posts: 209
Joined: Sun Jun 22, 2014 8:15 pm
Location: Bunbury WA
Contact:

Re: Speed Camera Check

Post by Jubbp » Tue Feb 17, 2015 9:45 am

Now all i need is a personal tracer for Constable Page so I know where she is and stear clear...

Post Reply