MacOS – One line weather output from terminal

command linemacos

Anyone knows a way to get a one line weather output in the terminal window with specified location?

So far I'm using curl wttr.in/city but I would like a one output like City, Sunny 0'.

I've found something like this (first answer):
https://askubuntu.com/questions/390329/weather-from-terminal

Unfortunately it does not work. I've installed wget command with brew and tried running those three lines from .sh file.

Best Answer

Simplest solution is ansiweather which you can install with brew. The result looks like ansiweather result.

If you want to write you own command/function it's not that difficult. If the output from the online location is in json, or something similar. You can use jq to parse json, and only print what you need.

curl -s http://ip-api.com/json | jq -Cr .

Read the manual page of jq to learn how to use it.

I tried the API you're using above, that's not gonna help your case. Find some other one that replies in JSON. For example:

curl -s 'api.openweathermap.org/data/2.5/weather?q={CITY,COUNTRY_CODE}&APPID={GET_YOUR_API_KEY}' | jq -C '.name? .weather?.main?'

I haven't tested it personally, because you have to make an account to make a call, but you get the idea.

Comment if you get lost.