Weather from terminal

I want to find the current weather of a particular city or my location from terminal. Is there any command-line weather app?

15 Answers

Simply enter the following in a terminal:

curl wttr.in

And will get your location from /etc/timezone. Otherwise curl . For example, for Tehran:

curl 

Which gives you:

Sample output

You can also compare two cities:

diff -Naur <(curl -s ) <(curl -s )

Source code of developer is available on Github.

7

Search for your city at and replace the URL in the following script with the URL for your city:

#!/bin/sh
URL='
wget -q -O- "$URL" | awk -F\' '/acm_RecentLocationsCarousel\.push/{print $2": "$16", "$12"°" }'| head -1

Sample output:

Berlin, Germany: Foggy, 1°
4

Here's a great semi-graphical command line utility written in Go:

You'll need to install Go and setup some API stuff, but the instructions are there. Here's a sample pic:

enter image description here

4

I have got one more way .

Open your .bashrc file and then paste this code at the bottom

weather(){ curl -s ""|perl -ne '/<title>([^<]+)/&&printf "%s: ",$1;/<fcttext>([^<]+)/&&print $1,"\n"';}

Then save & close your .bashrc file.

now type bash to update the file.

then type

weather <location name>

for example

august@august-OEM:~$ weather guntur
December 14, 2013: Clear. High 31&amp;deg;C (87&amp;deg;F). Winds 0 kph North
December 15, 2013: Clear. High 29&amp;deg;C (84&amp;deg;F). Winds 10 kph NNW
December 16, 2013: Clear. High 31&amp;deg;C (87&amp;deg;F). Winds 10 kph North
December 17, 2013: Clear. High 29&amp;deg;C (84&amp;deg;F). Winds 7 kph ENE
December 18, 2013: Scattered Clouds. High 29&amp;deg;C (84&amp;deg;F). Winds 3 kph ENE
December 19, 2013: Scattered Clouds. High 29&amp;deg;C (84&amp;deg;F). Winds 3 kph ENE
7

ansiweather

AnsiWeather is a Shell script for displaying the current weather conditions in your terminal, with support for ANSI colors and Unicode symbols. Weather data comes from the OpenWeatherMap free weather API.

sudo apt-get install ansiweather
ansiweather -l London,GB -f 3
London forecast => Sat Jan 13: 7/2 °C ☔ - Sun Jan 14: 4/1 °C ☔ - Mon Jan 15: 9/6 °C ☔

First you need to install the weather-util package, to do that just press Ctrl+Alt+T on your keyboard to open Terminal. When it opens, run the command(s) below:

sudo apt-get install weather-util

You’ll need your local weather code.

After installation you can run weather -i <code>. The code you get from the link above. For a list of available options, you can run weatherWeather info

6

Try using

telnet rainmaker.wunderground.com
2

also a program that comes pre-installed with ubuntu called inxi will give you all types of stats on your computer and it does a weather output.

command: inxi --help

command: inxi -w

 Conditions: 82 F (28 C) - Clear Time: May 13, 10:52 AM CDT

command: inxi -wxxx

 Conditions: 82 F (28 C) - Clear Wind: From the SW at 13 MPH Humidity: 60% Pressure: 29.99 in (1016 mb) Heat Index: 84 F (29 C) Location: city (USA) Altitude: 185 m Time: May 13, 10:52 AM CDT (America/Chicago) Observation Time: May 13, 9:54 AM CDT
2

You can compare cities using:

diff -Naur <(curl -s ) <(curl -s )

as illustrated in the top-voted answer. wttr.in also makes a great "splash" screen every time you open the terminal. Do this by adding it to your ~/.bashrc file. I've done that to include Weather, Date, Time and Distribution information as detailed in this answer: How can I get this terminal splash screen?

Bash Splash in Windows 10.png

Sorry I was in Ubuntu in Windows 10 WSL for Spring 2018 updates when I captured this image. Promise I'll boot back into Ubuntu in Linux soon.

For even shorter weather output provides weather data from Yahoo! in text and xml format.

The filds from the XML can then be obtained with a XML parser like xmllint i.e..

I wrote a q&d weather-fetch script, wich gets the current temperature and description of weather, then stores a unicode symbol corresponding to the description and outputs it like

☂ 6°C

I regularly update via cronjob and then use the output in my tray status.

Get your ID at yahoocom/news/weather. Change location to your desired location and look for ID in URL (i.e. if URL is yahoocom/news/weather/germany/north-rhine-westphalia/bielefeld-20066057 the ID is 20066057).

The XML contains further fields, i.e. forecast data, wind etc. – you can parse them, too, if you want.

Unfortunatly some weather symbols are not represented in the Ubuntufont… feel free to adjust.

Here's my script (replace 20066057 with your ID if you don't live in Bielefeld) - depends on bash, curl and xmllint.

#!/bin/sh
#☁☂☔❄❅❆☃ ☀☁☂⚡⚐☼
# write xml to variable
w_xml=$(curl -Ls "");
# get fields from xml via xmllint | xargs for trimming
# weather description
w_txt=$(xmllint --xpath "string(//current_text)" - <<<"$w_xml" | xargs);
# temperature | remove spaces from text (&#176;C prepended by space)
w_tpc=$(xmllint --xpath "string(//current_temp)" - <<<"$w_xml" | xargs); w_tpc=${w_tpc//[[:blank:]]/};
# further fields not used atm
# w_tph=$(xmllint --xpath "string(//current_temp_high)" - <<<"$w_xml" | xargs);
# w_tpl=$(xmllint --xpath "string(//current_temp_low)" - <<<"$w_xml" | xargs);
# set $w_sym according to $w_txt
if [ "$w_txt" == "Sunny" ]; then w_sym="☼";
elif [ "$w_txt" == "Mostly Sunny" ]; then w_sym="☼";
elif [ "$w_txt" == "Showers" ]; then w_sym="☂";
elif [ "$w_txt" == "Clear" ]; then w_sym="☾";
elif [ "$w_txt" == "Thunderstorms" ]; then w_sym="⚡";
elif [ "$w_txt" == "Scattered Thunderstorms" ]; then w_sym="☔";
elif [ "$w_txt" == "Isolated Thundershovers" ]; then w_sym="☔";
elif [ "$w_txt" == "Cloudy" ]; then w_sym="☁";
elif [ "$w_txt" == "Mostly Cloudy" ]; then w_sym="☁";
elif [ "$w_txt" == "Partly Cloudy" ]; then w_sym="☼☁";
elif [ "$w_txt" == "Breezy" ]; then w_sym="⚐";
# if unknown text, set text instead of symbol
else w_sym=$w_txt;
fi
# output <symbol><space><temp-in-°C>
echo "$w_sym"" ""$w_tpc";
3

I have got one more way .

Open your .bashrc file and then paste this code at the bottom

test -f ~/.wttr.in || curl -sk wttr.in -o ~/.wttr.in
find ~ -maxdepth 1 -name .wttr.in -cmin +5 -exec curl -sk wttr.in -o ~/.wttr.in \;
head -7 ~/.wttr.in | tail -5
W(){ find ~ -maxdepth 1 -name .wttr.in -cmin +5 -exec curl -sk wttr.in -o ~/.wttr.in \;; head -27 ~/.wttr.in; }

Save & close your .bashrc file and run the following command to update bash:

. .bashrc 

then type W upper case

3

Meteogram of all mayor cities in the world

finger

$ finger -= Meteogram for germany/north_rhine-westphalia/cologne =- 'C Rain 16 15 ^^^ 14 ======^^^ ^^^ 13 === ^^^===^^^=== 12 ========= 11 === ====-- 10 ====== --- 9=====| --- 3 mm 8 | | 2 mm 7 | | | | | | | | | | | | | | 1 mm _08_09_10_11_12_13_14_15_16_17_18 19 20 21 22 23 00 01 02 03 04 05 Hour SE SE SE SE SE SW SW W W W W SW W W W W W NW NW NW N N Wind dir. 5 5 5 5 4 4 5 6 6 6 5 5 5 4 4 5 5 5 4 3 3 3 Wind(mps)
Legend left axis: - Sunny ^ Scattered = Clouded =V= Thunder # Fog
Legend right axis: | Rain ! Sleet * Snow
[Weather forecast from yr.no, delivered by the Norwegian Meteorological Institute and the NRK.]

Here is how to use it:

$ finger
yr.no is having technical problems, or you specified an unknown location.
Usage: * finger <city name>@graph.no (world weather forecast, no spaces) Example: finger Advanced usage: * finger o:<city name>@graph.no (a one-line forecast) Example: finger o: * finger ^<city name>@graph.no (Imperial units) Example: finger ^ * finger <city name> (forecast from 5 hrs ahead in time (max:26)) Example: finger * finger <city name>~ (set screen width) Example: finger southpole~ * finger <city name> (forecast for every second hour [Norway]) Example: finger * finger <post code>@graph.no (norwegian weather forecast) Example: finger Other: * finger (latest headlines from NRK) * finger (server local time) * finger (server local date) * finger (contact information)
International names comes from 

The story behind this from the developer.

I've just made a quick endpoint that returns the weather, along with some more metrics:

curl 

Note that it currently only displays the weather for London (UK). Here's the Github repo in case you'd like to clone or open issues:

If you are familiar with ICAO station names and METAR weather information from an airport.

sudo apt install metar

and check your preferable airport to get the data from Example for Tokyo International airport/ Haneda = RJTT

metar -d rjtt

Sample output

RJTT 302000Z 34009KT 9999 FEW030 BKN050 14/08 Q1025 NOSIG
Station : RJTT
Day : 30
Time : 20:00 UTC
Wind direction: 440 (NNE)
Wind speed : 9 KT
Wind gust : 9 KT
Visibility : 9999 M
Temperature : 14 C
Dewpoint : 8 C
Pressure : 1025 hPa
Clouds : FEW at 3000 ft BRK at 5000 ft
Phenomena : 

Unlike weather command, this doesn't understand name of cities or countries. Instead of that feature, this can load quicker and multiple places at once.

Although accuweather curl solution is pretty good I needed something more informational, so I created simple bash script that pulls info for next 4 hrs from weather.com website. As in previous example you have to modify link for your location.

Example output:
$ ./getWeather.sh
Temperature for 1 AM : 65&deg;F and outside should be: Partly - Cloudy FEELS LIKE: 65&deg;
Temperature for 2 AM : 65deg;F and outside should be: Partly - Cloudy FEELS LIKE: 65deg;
Temperature for 3 AM : 63deg; and outside should be: Partly - Cloudy FEELS LIKE: 63deg;
Temperature for 4 AM : 62deg; and should be: Mostly - Clear FEELS LIKE: 62deg;

Full script is located at:

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like