by Paul Arnote (parnote)
One thing I LOVE about Linux is that there are so many ways to do things.
When I used to run a KDE/Plasma desktop, one of my "must-have" widgets was one that displayed the weather forecast on my desktop. When I switched to the Xfce desktop, one of the first panel plugins I installed was the weather plugin for the Xfce panel. It's still that way today, anytime I install or reinstall Xfce.
I'm not obsessed with the weather, but I do like to know what's coming on my next day off, when I'm usually trying to plan something that I'll be doing with my wife and kids.
Well, there is a great way to get a weather forecast while you work in a terminal session, too. That means you don't have to leave your command line environment to check on the weather forecast.
I don't even remember how I stumbled across this, because it was in a post on the DietPi forum site, in the tutorial section. I don't even have a Raspberry Pi, so I don't tend to visit these types of forums.
Step One: Prep The Command To Make Things Easier
Enter the following command (all on one line):
echo -e "\nfunction weather()\n{\nif [ \$COLUMNS -lt 125 ]\nthen\n curl wttr.in/\$@?2n\nelse\n curl wttr.in/\$@\nfi\n}" >> ~/.bashrc && source ~/.bashrc
It will define the command as the function "weather" and place it in your hidden .bashrc file. Then, all you will have to do is enter "weather" at the command line to see the weather forecast for your location, as defined by your IP address.
You can safely ignore the "Warning" window that pops up when you attempt to paste the command into your terminal window. Just click on the "Paste" button, which on my computer, shows up at the upper right corner.
Press the "Enter" key at the end of the command after pasting it into your terminal window.
Step Two: Execute The Command
Now, just type "weather" at the command line prompt, and press the "Enter" key.
So, just entering "weather" on the command line, in my case, displays the weather forecast for Houston, TX. That is because my IP address points to Houston, since I'm connected to my VPN's Houston, TX server.
That's great and all, if I lived in Houston, TX. But, because I live in Independence, MO, I'm more interested in my local weather forecast than I am interested in the weather forecast for Texstar's backyard. (Sorry Tex!)
So, let's alter the command slightly so that it gives me the weather forecast for the location that means more to me making my plans. Fortunately, there are a couple of super simple ways to do this.
One way is to supply the city (and possibly state) of the location you want the weather forecast. If you live in a BIG city, you will most likely get away with just providing the name of the city. So, if you supply "weather Atlanta", you will get the weather forecast for Atlanta, GA. That works great, just so long as you live in a major city around the globe, or if you want the weather forecast for a major city you plan to visit. This works for Moscow, London, Paris, Rome, Berlin, etc. Notice how I capitalize the name of the city. If the name of the city has a space in it (e.g., New York, San Francisco, Kansas City), omit the space between the words (i.e., weather SanFrancisco).
If you live in a smaller city (I'm at my job in Richmond, MO as I write this, with a population of about 8,800), it's helpful to specify the state in the command. So, to see the weather forecast for Richmond, MO, I need to enter the command as "weather Richmond,MO" to get the correct Richmond. Otherwise, I get the weather forecast for Richmond, VA, which is quite some distance from me. Notice there is no space between the comma and the state designation in the command.
Now, maximize the terminal window, and then reissue your previously used "weather" command..
Notice how the weather forecast has expanded from just "Noon" and "Night," to now include "Morning," "Noon," "Evening," and "Night." So, just by maximizing your window (and reissuing the weather command), you obtain a much more detailed weather forecast.
Instead of specifying the city name (and possibly the state name), you can also specify the postal zip code for the area you are wanting to obtain a weather forecast for as a parameter for the "weather" command. So, the command "weather 64085" will also retrieve and display the weather forecast for Richmond, MO, just as if you had specified the command as "weather Richmond,MO". At least, it works that way for U.S. postal zip codes.
Summary
So, the next time you're working at the command line and want to know the weather, either for your area, or for some area you're thinking about visiting, you can retrieve the weather forecast for that area with a simple command.
See? There are many ways to achieve the same end result under Linux. I really love that versatility and flexibility.
|