API purpose: Weather Conditions
Comment: Feature rich and worldwide weather!
OK so day two of API month. Exciting, right? Yesterday it occured to me if I’m making a decision when debating my cycle vs tube debate it would also be good to see the near term forecast. So I did some reading and found weather underground. Its a system of weather stations around the world, with data provided by official and hobbyist sources. Their API is pretty good too!
Getting the Data
So I swung over and setup an account. Straight forward process. I want to pull relevant information from the API so I did a sample call for London to see what I would get.
Pretty straightforward. A slightly different system than citymapper but very usable. It returned this: ``
Wow… That is a lot more info than our last tutorial. This is great though, it gives me a chance to play with more information. Here’s what I wrote up.
Still pretty straightforward too!
Yesterday our JSON was super easy. It was one series of machine tag pairs inside a JSON object. We asked for our machine tag (estimated_time) in that array and we were good to go with the value associated with that. However in JSON, each variable in an array can have an array of machine tags nested inside it. Its actually quite elegant if you work through the logic but we don’t care about this, we just want the data, right?!!! So let’s take wind speed from above. We wanted to get the current_observation array and inside that get the wind_mph tag and its associated value. To do this we used the following syntax.
So What Next?
So that’s that for today. Another simple example with some useful tricks to get you going with weather APIs. So what shall I do tomorrow??? I like this work around my commute to work. I think I’m going to solve a final challenge tomorrow with a good one, I live a 4 minute walk from my local train to work. The train comes every 15 minutes. The arrival time of the next train dictates if I have breakfast each day. I check this every day on google maps so I want to write a script that checks the TFL API and displays the next train time for me so I can quickly glance and see how long I have!