WeatherCrab
Check out WeatherCrab
In the span of just 24 hours, I embarked on a coding adventure that led to the birth of WeatherCrab, a lightweight GUI weather app crafted entirely in Rust, leveraging the local weather data from the NOAA.
Daily projects are a good way of learning for me, I tent to swap my focus around quite a bit so doing everything all in one go is best. I’ve been wanting to create a gui program that leveraged the use of some api, figuring that weather would be the simplest. Thankfully finding a free api that provided a service for me to use was not all to difficult thanks to NOAA’s api.
Challenges
Off the bat the first issue I had to figure out a way around is actually getting the users location to give to the NOAA api. NOAA requires a latitude and longitude with the request. Thankfully theres a very simple crate that resolves this. The geolocation crate is a pretty simple crate that when taking a look under the hood just makes a request and parses some json.
The JSON sent in the response contains a lot of data, one of which is the short forecast. The short forecast gives a string description of what the current weather is like(e.g. sunny, cloudy). Because there are only so many possible combinations of what the weather could be its best to use an enum here. The difficulty of which was converting the string to an enum. In order to do so the FromStr
trait had to be implemented to the enum. FromStr
has a required associated function from_str
that will match the string to the matching enum variants.
Future Enhancements
There are more then a few updates that I would like to put into WeatherCrab if it gets attention. In detail a list of what I would like to implement
- Since WeatherCrab was designed in the spring time I only got to see a few possible variants for the short forecast. In the future I expect the program to have issues whenever the weather changes or someone runs the program in another part of the world with different weather.
- Currently I am using two different http request crates(three if you count the geolocation crate) because of a bug I ran into and this was the quickest way to resolve it. considering both requests into one crate would be ideal and reduce the overall size of the binary.
- The geolocation crate makes a rather simple http request and builds the response into the location struct where we get our latitude and longitude. Copying the code(if permitted by their license) we can simplify the struct and remove the call to the crate.
- Overall the program isn’t very pretty, I would like to spend a few hours learning how to make it a bit better looking and to have it sync to the computers current theme(day/night mode).
- I would of liked to take the time to use WeatherCrab as an excuse to implement some tests but I ran out of time to do so. I think implementing a few tests on several cities would be a good starter test.