终端天气

Avi*_*Raj 79 command-line

我想从终端找到特定城市的当前天气或我所在的位置。有没有命令行天气应用程序?

小智 169

只需在终端中输入以下内容:

curl wttr.in
Run Code Online (Sandbox Code Playgroud)

并将从/etc/timezone. 否则curl wttr.in/your_location。例如,对于德黑兰:

curl wttr.in/tehran
Run Code Online (Sandbox Code Playgroud)

这给了你:

样本输出

您还可以比较两个城市:

diff -Naur <(curl -s http://wttr.in/london ) <(curl -s http://wttr.in/new-york )
Run Code Online (Sandbox Code Playgroud)

Github上提供了开发人员的源代码。

  • 好多了! (2认同)
  • https://github.com/schachmat/wego 对我们之间的“开发者”来说还不错 (2认同)

Flo*_*sch 19

http://www.accuweather.com 上搜索您所在的城市,并将以下脚本中的 URL 替换为您所在城市的 URL:

#!/bin/sh

URL='http://www.accuweather.com/en/de/berlin/10178/weather-forecast/178087'

wget -q -O- "$URL" | awk -F\' '/acm_RecentLocationsCarousel\.push/{print $2": "$16", "$12"°" }'| head -1
Run Code Online (Sandbox Code Playgroud)

示例输出:

Berlin, Germany: Foggy, 1°
Run Code Online (Sandbox Code Playgroud)

  • 不再工作,Accuweather API 是否已更改? (2认同)

小智 15

这是一个用 Go 编写的很棒的半图形命令行实用程序:

https://github.com/schachmat/wego/

你需要安装 Go 并设置一些 API 的东西,但说明在那里。这是一个示例图片:

在此处输入图片说明

  • 这是现在公开托管 - 具有 IP 地址到区域映射。尝试: curl -4 http://wttr.in (5认同)
  • @jschrab:实际上您不需要 -4。`curl wttr.in` 就够了 (2认同)

rɑː*_*dʒɑ 14

我还有一个办法。

打开您的.bashrc文件,然后将此代码粘贴到底部

weather(){ curl -s "http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query=${@:-<YOURZIPORLOCATION>}"|perl -ne '/<title>([^<]+)/&&printf "%s: ",$1;/<fcttext>([^<]+)/&&print $1,"\n"';}
Run Code Online (Sandbox Code Playgroud)

然后保存并关闭您的.bashrc文件。

现在键入bash以更新文件。

然后输入

weather <location name>
Run Code Online (Sandbox Code Playgroud)

例如

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
Run Code Online (Sandbox Code Playgroud)


use*_*355 9

ansiweather

AnsiWeather 是一个 Shell 脚本,用于在终端中显示当前天气状况,支持 ANSI 颜色和 Unicode 符号。天气数据来自 OpenWeatherMap 免费天气 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 ?
Run Code Online (Sandbox Code Playgroud)

https://github.com/fcambus/ansiweather


Mit*_*tch 6

首先,您需要安装 weather-util 包,只需按键盘上的Ctrl+ Alt+T打开终端即可。当它打开时,运行以下命令:

sudo apt-get install weather-util
Run Code Online (Sandbox Code Playgroud)

您将需要当地的天气代码

安装后就可以运行了weather -i <code>。您从上面的链接获得的代码。有关可用选项的列表,您可以运行weatherWeather info


小智 6

尝试使用

telnet rainmaker.wunderground.com
Run Code Online (Sandbox Code Playgroud)


小智 5

还有一个预装在 ubuntu 中的名为 inxi 的程序将在您的计算机上为您提供所有类型的统计数据,并提供天气输出。

命令: inxi --help

命令:inxi -w

        Conditions: 82 F (28 C) - Clear Time: May 13, 10:52 AM CDT
Run Code Online (Sandbox Code Playgroud)

命令: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
Run Code Online (Sandbox Code Playgroud)