Get Weather Forecast in Terminal with Wego
Wego is a command-line tool that can be used to get weather information on your location or any area in the world. In this tutorial, we’ll look at how to install and use Wego on Ubuntu 16.04 LTS.
Install Wego on Ubuntu 16.04
Wego is written in Go language and hosted on Github so we first need to install Go language and then download Wego from Github.
Install go language
sudo apt install golang-go
Then set the $GOPATH environment variable. The following command sets $HOME/go
as the GOPATH. The Wego binary will be installed in $HOME/go/bin
directory.
export GOPATH=$HOME/go
Next, add $GOPATH/bin to the user’s path.
export PATH=$PATH:$GOPATH/bin
We can also put the above two command at the end of .bashrc
file so they will be automatically executed every time we open up a terminal.
nano .bashrc
Now let’s download Wego from Github.
sudo apt install git go get -u github.com/schachmat/wego
After that, you need to set up your location. Wego supports two weather services: forecast.io and WorldWeatherOnline.com. As the latter no longer gives out free API, so this tutorial will demonstrate how to set up Wego with forecast.io.
Set up forecast.io Account
Create your account at https://developer.forecast.io/register. You will get an API key after registration.
Then create a .wegorc configuration file under your home directory.
nano ~/.wegorc
Paste the following lines in the file.
backend=forecast.io location=40.748,-73.985 forecast-api-key=your-forecast.io-api-key
The location is identified by latitude and longitude. You can easily get your coordinates from Google Maps. Simply click your area and your latitude and longitude is shown in the address bar.
Save and close the file. Now you can type wego
command in the terminal to get weather forecast. It can show temperature, wind speed and direction, viewing distance, precipitation and probability.
wego
By default, it shows forecast for the following 3 days. If you open up the .wegorc config file again, you will see wego has added other options.
You can change the value of days to 1~7. Other options can be changed as well.
Limitations
- Wego v2.0 depends on ingo and therefore a go 1.5+ environment.
- A free forecast.io account can call the API 1000 times per day.
- forecast.io only supports latitude and longitude now. You can’t use city name to specify location.
wttr.in
There’s a similar tool named wttr.in which is very easy to use. All you have to do is to install curl
on your system.
sudo apt install curl
Then get weather information for your location, for example, New York.
curl wttr.in/"New York"
or Paris
curl wttr.in/Paris
Even the weather of a domain name and IP address.
curl wttr.in/@linuxbabe.com curl wttr.in/@74.125.128.103
Check help information.
curl wttr.in/:help
wttr.in is in fact a front end of Wego.
Comments, questions and suggestions are always welcome. If you find this post useful, please subscribe to our free newsletter or follow us on Google+, Twitter or like our Facebook page.