Many Pies

Many Pies

Wednesday, February 05, 2014

Should I cycle to work or not?

With the @wycombeweather twitter bot and the UK Weather Little Printer publication that I've created you may detect that I have an interest in the weather. Now because I'm a wimpy cyclist I've created something that will tell me whether the weather is suitable for cycling.

It scrapes the BBC weather page looking for the weather conditions and temperature at two times of day (going to work and coming back) and sees if they fit my wimpy criteria for weather that I will cycle in. It then tells me whether to cycle or not. The idea is that I somehow get this information when I get up in the morning and use it to decide what to dress in. Maybe I could get a Raspberry Pi to turn on an LED based on what it tells me. In practise I'm probably going to look at the whole forecast for the day, as it it's been showery, even if the prediction at 5pm is that it isn't going to rain, there's a chance that it will and so I won't cycle. Still, it's fun to create it.

"It" at the moment is currently one web page which is in partial debug mode in that it tells me the conditions at the two times so I can see what the decision is for each of those conditions.


It's not just for me though - you can use it! By supplying query parameters to the URL you can specify your own postcode (UK only), times of day, min and max temperatures and the acceptable types of weather that you're prepared to cycle in. Here are the names of the parameters:

  • postcode - just the first bit, e.g. HP14
  • mintemp - a number
  • maxtemp - a number
  • firsthour - a number, e.g. 6 for 6am, 17 for 5pm
  • secondhour - as firsthour
  • goodweather - a comma separated list of words with %20 instead of space
For those words, as I had the @wycombeweather twitterbot running for a number of years I could mine the archives and get a definitive list of words the BBC have used for the weather. When I started work on this though I discovered that sometimes words were used for an hour slot that weren't used for a summary of a day. So this is all the words I know about:
  • clear sky
  • cloudy
  • drizzle
  • fog
  • foggy
  • grey cloud
  • heavy rain
  • heavy rain shower
  • heavy showers
  • heavy snow
  • light cloud
  • light rain
  • light rain shower
  • light showers
  • light snow
  • light snow shower
  • light snow showers
  • mist
  • misty
  • partly cloudy
  • sleet
  • sleet showers
  • sunny
  • sunny intervals
  • thick cloud
  • thunder storm
  • thundery shower
  • white cloud
So for example, if you live in Birmingham and you'll only cycle when it's sunny and warm you could use this URL:
http://paulmorriss.com/bikeornot/bikeornot.php?postcode=B1&mintemp=15&maxtemp=99&firsthour=9&secondhour=16&goodweather=sunny,sunny%20intervals
If you run this after 9am you'll get a "(not found)" for the first hour slot.

All the code for this is on github. You can see the work I've yet to do on the readme there. At the time of writing the next thing is to make it easier to specify your own preferences without creating a big URL, and then to store those in a cookie.
Post a Comment