How to Get Weather Details of a Location from Linux Command Line Using WTTR.IN

How to Get Weather Details of a Location From Linux Command Line Using WTTR.IN

We’ve already discussed a utility called weather that lets you check weather information of any location from the Linux command line. While the application delivers what it promises, its output is nothing but a bunch of text that demands careful reading, and more importantly, you have to first install the tool on your system to get things working.

What if I said it’s possible to get weather information on terminal without actually installing any utility? Yes, that’s possible and WTTR.IN makes it possible. In this article we will discuss how to use this utility and some of the key features it provides.

So what exactly is wttr.in? It’s a web front end for a tool named Wego, a command line utility to get weather information. So given that wttr.in is a web-based utility, you don’t necessarily have to install it locally, as you can simply access it using cURL. And since it uses Wego at the back-end, the output produced is as though it was produced by a command line utility.

Like I said, there’s no need to install the wttr.in utility. However, you have to make sure that cURL is installed on your system. If it isn’t, you can install it by running the following command:

That’s it. You can now use wttr.in to check weather information.

In its most basic form, you can use the wttr.in utility by running the following command:

The above command will get the information for your current location based on your IP address. When I tried this command I got the following output.

wttr-no-location-new

So, as you can see, wttr.in gives you well-formatted, detailed weather information for three days, breaking each day into four parts: Morning, Noon, Evening, and Night.

If you observe closely, the utility was not able to find my location (Chandigarh, India), so it displayed the weather information of Oymyakon in Russia, which is presumably the default location it uses in cases like this. I tried this command multiple times but remained out of luck.

If you encounter a similar situation, there are several alternative ways to get weather information for your location, such as by specifying the location name. As I am based in Chandigarh in India, this is how I passed on my location information to wttr.in:

wttr-location

Note: If the location name contains spaces – like New York – it’s advisable to use quotes around the name. I use it all the time, as it’s a good practice in general.

Moving on, it’s also possible to get weather information for airports, something which you can do by using their 3-letter IATA codes. For example, the following command will get you weather information for John F. Kennedy International Airport:

wttr-airport

For a complete list of airports by IATA codes, head here.

Next up, you can also use domain names as a location specifier. For example, the following command will get you the weather information of the city that hosts the MTE server:

wttr_domain

What’s more, you can even use ZIP codes to get weather-related information. Here’s an example where I used a San Jose zip code:

wttr-zipcode

By default, output produced by wttr.in is in SI (metric) units. However, If you’re in the US, where USCS is used by default, you can change the metric by adding a ‘?u’ at the end of the command. Here’s an example:

wttr-uscs-metric

You can see that all the Celsius values were changed into values based on the Fahrenheit temperature scale.

The first – and obvious – advantage of wttr.in is that it’s web-based, meaning you don’t have to install it to use it. Secondly, the output it produces is comprehensive as well as visually appealing – like a GUI-based utility produced it. Thirdly, and most importantly, both command line pros as well as newbies can use it easily. This all adds up to plenty of reasons to give wttr.in a try.

3 comments

  1. On mobile now but can’t wait to give this a try later on. Slowly but surely, I’m building a nice (fun) and useful collection of linux terminal goodness.

    • Update: Worked perfectly. Really nice find, Himanshu!

      Interesting… my default location was: Matawan, Papua New Guinea with USCS used (I’m in the US). I typed in: curl wttr.in/”zipCode” and it worked perfectly (accidentally used the quote marks but still retrieved the correct location).

      I piped the results to a text file to see what I’d get. As expected, you’ll see lots of escape sequences using ‘less’. Tried NFO Viewer without success (didn’t expect any because of the color coding). It did work using a perl script I found a while back that handles color ANSI named ‘slowcat.pl’ – invocation (in case anyone is interested):

      perl ./dirName/slowcat.pl savedPipedFile.txt

      PS: As an old-time DOS user, still looking for other ANSI and ColorANSI terminal viewers. slowcat.pl is great, in that it handles animations pretty well but lacks the ability of displaying single pages with scrolling (something like ‘less’ but with ANSI (vt101?) support).

Comments are closed.

Sponsored Stories