Get Weather App

By: Marcus Schuff

Thursday, December 30, 2021, 8:33 PM

Today I wrote my first cross platform .NET Core console application. It started out as all first apps do, with a hello world, or in this case, Hola Mundo. 

And it worked flawlessly on Windows, Linux, and Mac! 

Ok, but that's boring! 

What I had to do next was come up with an idea for a simple application that would be usefull on any operating system. Since it has been raining here all week, I thought, why not a weather app? What's more exciting than weather? ;-) 

So I started working....

The "GetCoordinates" method below takes the user input as an argument, and sends the user input to Microsoft's Bing Maps API. The response from the server includes the GPS coordinates of the location requested. 

and working.....

The "GetGridPoints" method takes the coordinates produced from Bing Maps, and sends a web request to the US National Weather Service. The server response includes the weather station and grid points of the GPS coordinates provided. Here I wrap that resposne in a class called, "GridPoints". The method returns the GridPoints object so we can request the forecast of that grid point. 

and working....

The "GetForecast" method takes the GridPoints object that was created using the "GetGridPoints" method and sends a request asking for the forecast to the US National Weather Service. The response from the server includes the 10+ day forecast for the requested grid points. 

Until it was just right! 

The GetWeather method shown below is the primary function of the program. All three of the above described methods are called from the GetWeather method. 

First, we ask the user to enter a city, state, or zip code to get the weather report for that location. We URL encode the user input in order to specify our request in the URL. Using the user input, we send off a request to Bing Maps and ask it to send us back the GPS coordinates of our requested location. Next, we take those cooridinates, and send them to the National Weather Service and ask them to send us back the grid points that correspond to the GPS coordinates we sent them. Finally, we ask the National Weather Service to pretty please send us the forecast for those gird points, and print out the forecast for the user to read. 

The Main method below is the entry point of the program. GetWeather is a recursive functions that will continue to loop until the user exits the program via the escape key.

I published the GetWeather app to three different folders. GetWeather_Linux, GetWeather_MacOS, and GetWeather_Win for each of the corresponding operating systems (Linux, Macintosh OS, and Windows). 

You can download the GetWeather program here (current release version 4):

To make sure you downloaded the right file, you can use CheckSum. Here is the SHA256 Hash for the zip file: 6804733BE862F52F8AE076E852C4AB26451C7B52A4A75B46289536D9A84B1E3E

Download the zip folder to your computer. Once you have download the program, extract the contents to a convenient location on your computer. 

To run the program, open a command terminal or console window on your computer of choice, and change the directory to the location where you extracted the contents of the folder, and run the GetWeather program. 

For example, on Linux, in a terminal window use the command: "cd /dir/where/you/saved/GetWeather_Linux"

Alternatively, in most Linux GUIs you can right-click on the folder, the click on "Open in Terminal" to open a terminal to that directory.  

You will likely have to change the permissions of the "GetWeather" program file in order to run it. To do so, type: "sudo chmod 777 ./GetWeather"

Then type: "./GetWeather" 

The process should be similar on an Apple Macintosh computer. You can also double-click on the "GetWeather" file in the "GetWeather_MacOS" folder that you extracted to your computer. 

On Windows, you can double-click on the GetWeather.exe file in the "GetWeather_Win" folder that you extracted to your desired location.

Alternatively, on Windows you would use a similar command: "cd C:\users\<your_username>\desktop\GetWeather_Win" 

Then run the executable by typing: "GetWeather.exe"

Then follow the isntructions on the screen. 

That's it! Let me know what you think! Happy new year!