← Projects

Weather checker

Pulls the weekend forecast for a whole list of destinations at once, so planning a trip stops being an evening of filling in a spreadsheet.

  • C++
  • REST APIs
  • caching
  • 2022

This small project was inspired during weekend trip planning. I was looking where to go with my friends and ended up with 30 potential locations. One of the main factors was weather. I spent an evening filling a table with temperature and rain chance for every location and ended up with this (don't be scared, all temperatures are in °C):

Hand-filled weather comparison table

It was very useful data, but it took an unacceptable amount of manual work and time to fill it. Oh, and yeah, the "sweetest" part is that in a few weeks this data became outdated and you would need to redo all the work to refill the table for every trip. For every trip. For. Every. Trip.

So I decided to simplify my life and create a small program which will grab weather for all specified locations for me. I spent some time looking for an API which I could use and found a few good options. And ended up with the following flow:

  1. Get place name
  2. Convert provided place name to latitude/longitude coordinates
  3. Using place coords get weather office ID
  4. Using weather office ID get forecast for the next days
  5. Remove all data which does not match the desired travel date
  6. PROFIT!

After some testing I realized that I can improve the logic a little bit, so I baked in a few small features to improve final data, processing speed, etc. For example I don't need to include temperature/rain chance during deep night and early morning because I will sleep (hopefully inside) during this time and weather is irrelevant. I also realized that I can reduce the number of API calls from 3 to 1 by caching some data, so I added caching using SQLite which improved speed — on average the response from the API provider was way slower than SQLite.

So the new flow will be this:

  1. Get place name
  2. Is place cached? If so, then jump to step 5, otherwise continue
  3. Convert provided place name to latitude/longitude coordinates
  4. Using place coords get weather office ID
  5. Using weather office ID get forecast for the next days
  6. Remove all data which does not match the desired travel date
  7. Filter output data!
  8. PROFIT!

Output will have place name (in the current output it's an airport identifier, I want to hook it up to a plane tickets API in the future), temperature, rain chance and sky cover percentage for the next weekend, averaged between Saturday and Sunday. The program runs on this server and refreshes the data on its own, so the table below is its real current output.

Live output

Generated · refreshes every 2 hours · download CSV

Place Temp Rain Cloud
JFK 20.5°C 31% 63%
JFK 20.5°C 31% 63%
IAD 24.0°C 30% 64%
MCO 27.3°C 47% 56%
BOS 16.4°C 29% 62%
ATL 29.1°C 24% 38%
ORD 21.2°C 59% 84%
DFW 33.3°C 8% 21%
DEN 19.7°C 55% 61%
CLT 27.0°C 23% 50%
MIA 27.8°C 62% 63%
PHX 34.3°C 1% 11%
EWR 20.6°C 32% 63%
IAH 31.2°C 9% 17%
FLL 27.8°C 66% 63%
LGA 20.6°C 31% 62%
JAX 27.5°C 30% 57%
SAV 27.9°C 27% 50%
RSW 27.9°C 53% 48%
MSP 16.8°C 11% 85%
DTW 18.2°C 53% 84%
SLC 19.4°C 6% 19%
PHL 22.3°C 31% 62%
BWI 23.9°C 31% 62%
TPA 28.1°C 45% 55%
MDW 22.2°C 58% 79%