Consuming a weather API and presenting the data in a sanitised form


I'm quite interested in the weather. I find the weather apps on my phone to be somewhat - even very - inaccurate, so I wondered if there was a better way to see what I could expect in the forecast. A little research led me to an organisation which provides various weather APIs, mostly with a charge, but free to single-handed developers like me.

I had better not mention the name of the organisation as I'm not here to advertise, but I find their feeds to be highly accurate, so I set about turning the mass of data emanating from their feeds into a simple sanitised display, which shows all the information I needed in an hourly forecast.

Here is an example of the frst few hours of a day's forecast from the raw data:

name,datetime,temp,feelslike,dew,humidity,precip,precipprob,preciptype,snow,snowdepth,windgust,windspeed,winddir,sealevelpressure,cloudcover,visibility,solarradiation,solarenergy,uvindex,severerisk,conditions,icon,stations
"Newbury, England, United Kingdom",2022-08-15T00:00:00,20.5,20.5,11.2,55.23,0,0,,0,0,16.9,6.9,163,1003.7,63.8,10,0,,0,10,Partially cloudy,partly-cloudy-night,"EGVO,EGDM,EGVP,EGLF,EGVA,EGUB"
"Newbury, England, United Kingdom",2022-08-15T01:00:00,19.5,19.5,11.3,59.16,0,0,,0,0,10.4,4.8,1,1003.1,52.6,10,0,,0,10,Partially cloudy,partly-cloudy-night,"EGVO,EGDM,EGVP,EGLF,EGVA,EGUB"
"Newbury, England, United Kingdom",2022-08-15T02:00:00,17.9,17.9,11,64.06,0,0,,0,0,9.7,6,349,1002.9,40.5,10,0,,0,10,Partially cloudy,partly-cloudy-night,"EGVO,EGDM,EGVP,EGLF,EGVA,EGUB"
"Newbury, England, United Kingdom",2022-08-15T03:00:00,17.1,17.1,11.1,67.68,0,0,,0,0,10.8,8.1,171,1002.6,25,10,0,,0,10,Partially cloudy,partly-cloudy-night,"EGVO,EGDM,EGVP,EGLF,EGVA,EGUB"
"Newbury, England, United Kingdom",2022-08-15T04:00:00,16.8,16.8,12,73.44,0,0,,0,0,11.5,6.5,189.3,1002.5,55.2,8.7,0,,0,10,Partially cloudy,partly-cloudy-night,"EGVO,EGDM,EGVP,EGLF,EGVA,EGUB"
"Newbury, England, United Kingdom",2022-08-15T05:00:00,16.4,16.4,11.7,73.85,0,0,,0,0,10.4,9.1,185,1001.9,42.1,8.1,0,,0,10,Partially cloudy,partly-cloudy-night,"EGVO,EGDM,EGVP,EGLF,EGVA,EGUB"
"Newbury, England, United Kingdom",2022-08-15T06:00:00,16.3,16.3,13,80.8,0,0,,0,0,11.9,8,196,1001.6,75.9,6.7,5,0,0,10,Partially cloudy,partly-cloudy-day,"EGVO,EGDM,EGVP,EGLF,E8174,EGVA,EGUB"
"Newbury, England, United Kingdom",2022-08-15T07:00:00,16.1,16.1,13.9,87.12,0,0,,0,0,15.1,9.8,192,1001.6,88,7.4,25,0.1,0,10,Partially cloudy,partly-cloudy-day,"EGVO,EGDM,EGVP,EGLF,E8174,EGVA,EGUB"
"Newbury, England, United Kingdom",2022-08-15T08:00:00,17.9,17.9,15,82.96,0,0,,0,0,20.2,12.1,202,1002.1,78.4,7.3,89,0.3,1,10,Partially cloudy,partly-cloudy-day,"EGVO,EGDM,EGVP,EGLF,E8174,EGVA,EGUB"
"Newbury, England, United Kingdom",2022-08-15T09:00:00,21.1,21.1,15.3,69.47,0,0,,0,0,22,12.6,199.6,1003,79.8,24.1,311,1.1,3,3,Partially cloudy,partly-cloudy-day,
"Newbury, England, United Kingdom",2022-08-15T10:00:00,23.3,23.3,14.8,58.84,0,0,,0,0,23,12.6,216.5,1003,100,24.1,397,1.4,4,10,Overcast,cloudy,
"Newbury, England, United Kingdom",2022-08-15T11:00:00,24.7,24.7,13.4,49.4,0,0,,0,0,23,13,247.9,1003,100,24.1,397,1.4,4,10,Overcast,cloudy,
"Newbury, England, United Kingdom",2022-08-15T12:00:00,26.3,26.3,12.4,42.07,0,0,,0,0,24.1,13.7,272.5,1003,91.5,24.1,327,1.2,3,10,Overcast,cloudy,


That's a lot of data, and I didn't want a lot of it.

I used Python to collect this raw data and to output the necessary values, for collection by a XOJO program. This is what the Python program delivers to XOJO:

2022-08-15T00:00:00,20.5,20.5,55.23,0,0,16.9,6.9,63.8,Partially cloudy
2022-08-15T01:00:00,19.5,19.5,59.16,0,0,10.4,4.8,52.6,Partially cloudy
2022-08-15T02:00:00,17.9,17.9,64.06,0,0,9.7,6,40.5,Partially cloudy
2022-08-15T03:00:00,17.1,17.1,67.68,0,0,10.8,8.1,25,Partially cloudy
2022-08-15T04:00:00,16.8,16.8,73.44,0,0,11.5,6.5,55.2,Partially cloudy


A separate Python function gets and sends similar data for tomorrow.


Then over to XOJO. Having designed the look and feel of the application it was a simple matter to display the data in a simply understood and logical manner. This is how today's weather forecast looks:


A separate Python call to another API feed from the same organisation grabs the times of sunrise and sunset, which XOJO stores in a database table. The data is displayed as shown, and the daily progression of sunrise and sunset is displayed. It reveals that the total difference between sunrise and sunset is accelerating. Right now we're losing 3.55 hours of sunlight per day, which is more than yesterday, which was 3.50 hours.

A button, not visible above, displays the expectations for tomorrow:



(There's a technical reason why today starts at 2am instead of midnight, which I needn't go into)

All in all, an interesting exercise, which I enjoyed putting together, and I can see that I'll need my umbrella tomorow.