For me, getting to many of the activities I enjoy, involves crossing a river.

Normally, this is about 35-40 minutes on bike, but if the crossing is flooded, I have to take a ~20 minute detour. What’s more, it’s dark, and this often involves me suddenly getting very wet feet.

Thankfully, it’s the 21st century, and I can do something about this!

Flood sensors

The UK Environment Agency, thanks in a large part to the wonderful work being done by the Data.gov.uk, has made the data for their network of flood sensors available on the internet.

I can tell, by visiting a webpage, more or less whether I need to take the short or long way round.

This wasn’t enough for me, because I’m lazy, and I want to be able to either ask the question “Is sandford flooded?” in a console window, or have my computer send me an alert if I need to allow extra time to get in. Unfortunately, there’s no feed of this data immediately available, but this was nothing a bit of Script-Fu wasn’t able to sort out!

The first step was getting the current levels. Looking at the markup, you can see that the current level is a nice two digit number between two <strong> tags, so this was pretty easy to regex for.

The second was to get a value for what the environment agency considers “flooding” for this sensor. This was a little bit more tricky, but it’s marked on the graph, and it would seem that the source for this is a JSON blob in the html, so again, relatively straightforward.

Putting this together, I was able to build a nice little script that, when given a sensor’s webpage, compares these two values and gives you a simple yes or no as to whether it’s flooded. For bonus points, and because the surrounding low areas may flood before the sensor does, I took a 90% value for a given sensor and use it to return an “Almost” if reached… kindof a “proceed with caution”.

This was pretty much to scratch my own itch, but since the flood sensor network is nation-wide, I figured it might be useful to someone else out there!

» Visit the project on Github...

I am not a big fan of Facebook’s Pavlovification of life, and I try and spend as little time as possible on it. This, unfortunately, has lead to me missing invites to things.

I was shooting the shit with a mate of mine recently, who is even more anti-Facebook, and here’s what I came up with.

iCal Feeds

One of the hidden features Facebook has is that it’s feed of events you’re going to or have been invited to, is made available via an iCal feed you can subscribe to. I had already added this to my Google calendar (add another calendar by URL), so I get a list of upcoming events appearing in my calendar, and you can even tell Google calendar to send you a notification email when new stuff is added.

However, Google has its own problems, so I thought it’d be nice to get a weekly email digest of upcoming things.

Python lists

So, using the python-icalendar module, I wrote a very quick bit of python program that you an point at an ical feed, and get a summary list of upcoming events printed to the console in a nice list. It uses the summary text of the event, together with the start and end times, and, if available, the location and URL link (handy for Facebook events).

It automatically removes events that have already ended, and by default only lists events that start within the next 7 days.

Use it as follows:

python parse_cal.py -u 'https://url.of.feed/ical' -d *numberofdays*

Which outputs something like:

 * Church Of The Heavy presents ECHO4FOUR...VIOLENCE IS GOLDEN...NO DICE GRANDMA...INFURIOUS
     2016-02-24 19:30 - 2016-02-24 22:30
     Wheatsheaf Oxford
     http://www.facebook.com/events/468321193354736/
 * THE HIP DROP!
     2016-02-25 20:00 - 2016-02-26 01:00
     The Bullingdon  (Oxford)
     http://www.facebook.com/events/141392559560311/

Which are two awesome events I’m heading to in the next few weeks (two very different styles of music!)

Now the email

Getting a weekly digest then is just a matter of a bit of cron and mailer goodness, edit your crontab thus:

@weekly /usr/bin/python /path/to/parse_cal.py -u 'https://feed.example.com/calendar.ics' -d 7 | mail -E -s "This week's upcoming events" you@example.com

The program only outputs something if it finds things, so the -E tells mailx to not send anything if there’s no message body.

And you’re done!

I’ve found this pretty handy for a few other calendar feeds (my work joblist for example). Enjoy!

» Visit the project on Github...

PHP 7 is now out, and Travis-CI supports it as part of their standard configuration (rather than forcing you to use the PHP nightly build). Last night I submitted a pull request to add PHP 7 support to the Known Travis build, which was a little bit problematic.

Known uses Apache + PHP-FPM, rather than the Travis default nginx setup, and while there are guides for getting this working on the Travis site, it seems that they’re not quite there for the PHP 7 build.

The PHP 7 build was running into this error:

[15-Feb-2016 23:14:58] WARNING: Nothing matches the include pattern '/home/travis/.phpenv/versions/7.0.3/etc/php-fpm.d/*.conf' from /home/travis/.phpenv/versions/7.0.3/etc/php-fpm.conf at line 125.
[15-Feb-2016 23:14:58] ERROR: No pool defined. at least one pool section must be specified in config file
[15-Feb-2016 23:14:58] ERROR: failed to post process the configuration
[15-Feb-2016 23:14:58] ERROR: FPM initialization failed
/home/travis/build.sh: line 45: 25862 Segmentation fault      (core dumped) ~/.phpenv/versions/$(phpenv version-name)/sbin/php-fpm

This took a little while to diagnose, but in the end the fix was pretty simple. Basically it looks like the Travis PHP7 build of PHP-FPM expects, but can not find, a pool definition. You don’t need to customise it, just put a default one into PHP-FPM’s config directory.

So, I packaged a default template with the Known patch, and in my .travis.yml added the following to before_script:

- if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.0" ]]; then sudo cp Tests/build/www.conf ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.d/; fi

I also modified the Apache vhost example and added ServerName localhost to the definition (although this might not be needed).

After this, the build completes successfully.

PHP7 is new, so I suspect Travis will fix this shortly. However, hopefully this will prevent some hair-pulling in the mean time!