blitzortung.org Daily Position Cron

As you probably know from my blog, I have a number of Arduino’s around the house for monitoring household and weather metrics and I’m always looking for ways to add more devices and data sets.

My dad happened to find a map one summer on blitzortung.org to view live lightning strikes and we decided to sign up for a lightning detector in December 2015 (I think!).  When you register you use your email address and can see where you are in the list of people who want a device by going back to en.blitzortung.org/cover_your_area.php and filling in your email + the other boxes.

After one year on the waiting list, our position in the queue had moved a bit, but it became tedious checking the list once a week, so I wrote a script that I’ve now made generic enough for anyone.  Simply add it to crontab and take the pain out of checking every week 🙂

GitHub gist: https://gist.github.com/vls29/aac9d3efaf265734dfc1b64c46482160#file-blitzortung-position-sh

#!/bin/bash

email=$1

epc=$(date +%s)
echo $epc

# Country does not seem to be important
res=$(curl --data "info_time=$epc&info_email=$email&info_country=United+Kingdom&info_text=TSqrb" http://en.blitzortung.org/cover_your_area.php)
#echo "-----------------------------"
#echo "HTML Response"
#echo $res
#echo "-----------------------------"

html=$(echo "$res" | grep $email)
#echo "-----------------------------"
#echo "Position Text"
#echo $html
#echo "-----------------------------"

textpositionstart=411+${#email}+1
echo "textpositionstart: $textpositionstart"

position=${html:$textpositionstart:6}
position=$(echo $position | sed 's@^[^0-9]*\([0-9]\+\).*@\1@')
echo "position: $position"

lastpositionfilename=blitzortung-last-position.txt
lastposition=$(cat $lastpositionfilename)
catresult=$?
echo "catresult $catresult"
if [ "$catresult" -eq "1" ]; then
    echo "didn't find last position file"
    lastposition=100000
else
    echo "found last position file"
fi
echo "lastposition: $lastposition"

if [ "$position" -lt "$lastposition" ]; then
    echo $position | mail -s "blitzortung.org position" $email
    echo $position > $lastpositionfilename
else
    echo "position not less than $lastposition: $position"
fi

exit

The only input to the script is the email address you’ve used on the waiting list (assuming you haven’t hardcoded it in the script like I have).  You don’t need country as that doesn’t appear to be used by the site to verify the email address.