码头天气


Answers:


133

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

curl wttr.in

并从获取您的位置/etc/timezone。否则curl wttr.in/your_location。例如,对于德黑兰:

curl wttr.in/tehran

这给你:

样品输出

您还可以比较两个城市:

diff -Naur <(curl -s http://wttr.in/london ) <(curl -s http://wttr.in/new-york )

开发人员的源代码可以在Github上找到


2
方式好多了!
Zachary Dahan

2
github.com/schachmat/wegodevs我们之间的关系还不错
Timo

像这样,但是这次却抛出了一个错误:抱歉,目前我们对气象服务的查询用完了。我们将尽快收到新的查询。
Doyousketch2

17

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

样本输出:

Berlin, Germany: Foggy, 1°

但是我如何将其更改为
Celcius

在源html中,我看到了acm_RecentLocationsCarousel.push({name:"Berlin, Germany", daypart:'day', href:'/en/de/berlin/10178/weather-forecast/178087', icon:'i-6-l', bg:'c', temp:'0', realfeel:'-6', text:"Mostly cloudy"});。使用您的代码,awk字段分隔符为''(空格)。是$12(温度)第12栏?
Timo

我的错,awk分隔符是'。api使用2个数字,第一个是postleitzahl或邮政编码。第二似乎是一个API代码数
蒂莫

1
不再起作用,Accuweather API是否已更改?
蒂莫

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"';}

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

现在键入bash以更新文件。

然后输入

weather <location name>

例如

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

1
天气预报很好。向我+1。
souravc 2013年

此功能不再有效,它显示的最后日期是2015年5月(至少适用于南非开普敦)。仔细检查xml输出,发现txt_forecast父级自2015年5月以来未进行更新,而simpleforecast元素似乎具有最新数据。
Zahir J

我会更新我的答案
rɑːdʒɑ

如果您希望天气<位置名称>工作,请用$ 1替换YOUZIPORLOCATION
Ed Neville

当我更换YOUZIPORLOCATION使用$1,并通过20001(华盛顿邮政编码),我得到的是看起来像格式化线Today: Mostly sunny and breezy. Highs in the upper 30s. Northwest winds 20 to 25 mph with gusts up to 45 mph.当我使用"washington.dc",我得到表输出May 4, 2015: Clear. High 32&amp;deg;C (89&amp;deg;F). Winds 43 kph East。知道为什么会有区别吗?
Blalterman

14

这是一个用Go语言编写的出色的半图形命令行实用程序:

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

您需要安装Go并设置一些API东西,但是其中的指示信息已经存在。这是一个示例图片:

在此处输入图片说明


5
这是目前公开托管的-IP地址到区域的映射。试试:curl -4 wttr.in
jschrab

2
@jschrab:而且您实际上不需要-4。curl wttr.in够了
Igor Chubin

公制版本也提供公制单位,例如:curl wttr.in/Helsinki?m
Ville


5

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

sudo apt-get install weather-util

您需要当地的天气代码

安装后即可运行weather -i <code>。您从上面的链接获得的代码。有关可用选项的列表,您可以运行weather天气信息


1
它显示了。Last updated Dec 11, 2013 - 07:00 AM EST / 2013.12.11 1200 UTC Temperature: 86 F (30 C)没有办法知道当前的天气。
Avinash Raj

根据您所在的位置,可能是当前可用的信息。
米奇

1
我只是尝试了一下,发现现在更容易使用:weather YOURLOCATIONNAME它先搜索您的位置,然后可能会提供多个结果。从这些中,您可以读取站标识符,您可以将其用作自变量,以从
Nicolas

它所依赖的服务似乎已终止。我刚装了2.0版本,以及weather LAX(这应该显示了洛杉矶国际机场的天气)显示404错误weather.noaa.gov/pub/data/observations/metar/decoded/KNKX.TXT
基思·汤普森

1
那个特定的数据文件已经从这里移到了这里。应该可以更新数据文件,将的每次出现更改http://weather.noaa.gov/pub/datahttp://tgftp.nws.noaa.gov/data。更新:看来他们已经在版本2.1中对其进行了修复,可以从项目站点获得版本。
基思·汤普森

5

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 ☔

https://github.com/fcambus/ansiweather


2

此外,预装了ubuntu的名为inxi的程序还将为您提供计算机上的所有类型的统计信息,并进行天气输出。

命令:inxi --help

命令:inxi -w

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

命令: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

从10.04开始,inxi似乎不是ubuntu的一部分,但可以与sudo apt install inxi
Starbuck

是,inxi可用,但是您需要首先启用Universe资源库。
mchid

2

您可以使用以下方法比较城市:

diff -Naur <(curl -s http://wttr.in/london ) <(curl -s http://wttr.in/new-york )

如最受好评的答案所示。wttr.in每次您打开终端时,也会显示一个很棒的“启动”屏幕。为此,请将其添加到~/.bashrc文件中。我这样做是为了包括天气,日期,时间和分布信息,如以下答案中所述:如何获得此终端启动屏幕?

Windows 10.png中的Bash Splash

抱歉,当我捕获此映像时,我在Windows 10 WSL的Ubuntu 2018年春季更新中。保证我很快会重新启动Linux下的Ubuntu。


2

对于更短的天气输出,http://weather.tuxnet24.de提供了Yahoo!的天气数据。以文本和xml格式。

然后可以使用XMLlin解析器(如xmllint ie)来获取XML的内容。

我编写了一个q&d Weather-Fetch脚本,该脚本获取当前温度和天气描述,然后存储与该描述对应的Unicode符号,并将其输出为

☂6°摄氏度

我定期通过cronjob更新,然后在托盘状态下使用输出。

在yahoocom / news / weather上获取您的ID。将位置更改为所需位置,然后在URL中查找ID(即,如果URL为yahoocom / news / weather / germany / north-rhine-westphalia / bielefeld-20066057,则ID为20066057)。

XML包含其他字段,即预报数据,风等。如果需要,您也可以解析它们。

不幸的是,Ubuntufont中未显示某些天气符号……随时进行调整。

这是我的脚本(如果您不住在比勒费尔德,用您的ID替换20066057)-取决于bash,curl和xmllint。

#!/bin/sh
#☁☂☔❄❅❆☃ ☀☁☂⚡⚐☼

# write xml to variable
w_xml=$(curl -Ls "http://weather.tuxnet24.de/?id=20066057&mode=xml");
# 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";

重定向意外错误
Philip Kirkbride

将Shebang切换为#!/usr/bin/env bash固定版本,Ubuntu 18.04
Philip Kirkbride,

2

我还有另外一种方法。

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

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; }

保存并关闭.bashrc文件,然后运行以下命令来更新bash:

. .bashrc 

然后输入W大写


bash:W:找不到命令

编辑.bashrc重新登录后
sergkog

如果您“获得” .bashrc文件,则无需重新登录。您可以运行:source .bashrc或者您可以运行它:. .bashrc
mchid

0

尽管AccuWeather curl解决方案非常好,但我需要更多信息,因此我创建了简单的bash脚本,该脚本可从weather.com网站获取接下来4个小时的信息。与前面的示例一样,您必须修改位置的链接。

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;

完整脚本位于:https : //sites.google.com/site/wozoopalinux/home/wzbash001/get-weather-information-from-command-line-for-next-4-hrs


0

世界所有市长的气象图

finger city_name@graph.no

$ finger cologne@graph.no

           -= 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.]

使用方法如下:

$ finger help@graph.no

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 newyork@graph.no 

 Advanced usage:

 * finger o:<city name>@graph.no (a one-line forecast)
   Example: finger o:newyork@graph.no 

 * finger ^<city name>@graph.no (Imperial units)
   Example: finger ^newyork@graph.no 

 * finger <city name>+5@graph.no (forecast from 5 hrs ahead in time (max:26))
   Example: finger northpole+5@graph.no 

 * finger <city name>~160@graph.no (set screen width)
   Example: finger southpole~160@graph.no 

 * finger <city name>%2@graph.no (forecast for every second hour [Norway])
   Example: finger oslo%2@graph.no 

 * finger <post code>@graph.no (norwegian weather forecast)
   Example: finger 0458@graph.no 

 Other: 

 * finger news@graph.no (latest headlines from NRK)
 * finger time@graph.no (server local time)
 * finger date@graph.no (server local date)
 * finger about@graph.no (contact information)

International names comes from http://fil.nrk.no/yr/viktigestader/verda.txt.

开发人员背后故事

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.