我想从终端找到一个特定城市或我的位置的当前 天气 。是否有任何命令行天气应用程序?
devs
是不错的 2021-05-31
时运行良好。 在 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°
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列吗? awk
的分隔符是 '
。api使用2个数字,第一个是 postleitzahl
或邮政编码。第二个似乎是api的代码号 curl wttr.in
就够了 curl wttr.in/Helsinki?m
curl wrrt.in/Helsinki\?m
或者像这样把URL放在单引号里 curl 'wttr.in/Helsinki?m'
我还有一个方法.
打开你的 .bashrc
文件,然后在底部粘贴这个代码
weather(){ curl -s " http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query= ${@:-<YOURZIPORLOCATION>}"|perl -ne '/<title> ([^<]+)/&& printf "%s: ",1美元;/<fcttext>([^<]+)/&&打印1美元,"/n"';}
然后保存&关闭你的 .bashrc
文件。
现在输入 bash
来更新文件。
然后输入
weather <location name>
例如
august@august-OEM:~$ weather guntur
December 14, 2013: Clear. High 31&deg;C (87&deg;F). Winds 0 kph North
December 15, 2013: Clear. High 29&deg;C (84&deg;F). Winds 10 kph NNW
December 16, 2013: Clear. High 31&deg;C (87&deg;F). Winds 10 kph North
December 17, 2013: Clear. High 29&deg;C (84&deg;F). Winds 7 kph ENE
December 18, 2013: Scattered Clouds. High 29&deg;C (84&deg;F). Winds 3 kph ENE
December 19, 2013: Scattered Clouds. High 29&deg;C (84&deg;F). Winds 3 kph ENE
$1
替换 YOUZIPORLOCATION
并通过 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&deg;C (89&deg;F). Winds 43 kph East
。知道为什么会有这种差别吗?
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 ☔
Last updated Dec 11, 2013 - 07:00 AM EST / 2013.12.11 1200 UTC Temperature: 86 F (30 C)
.是否没有办法知道当前的天气。 weather YOURLOCATIONNAME
它当时搜索你的位置,并提供可能是多个结果。从这些结果中你可以读出台站标识符,你可以用它作为参数从 http://weather.noaa.gov/pub/data
改为 http://tgftp.nws.noaa.gov/data
。更新:看起来他们已经在2.1版本中修复了这个问题,你可以从 项目网站 获得。 weather-util
的描述: "[......]为整个美国的地方和全球的一些特定地点提供数据[......]" 尝试使用
telnet rainmaker.wunderground.com
还有一个预装在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
sudo apt install inxi
inxi
是可用的,但你需要先启用宇宙库。 你可以用以下方法比较城市:
diff -Naur <(curl -s http://wttr.in/london ) <(curl -s http://wttr.in/new-york )
,如投票最高的答案中所说明的。 wttr.in
在你每次打开终端时,也会有一个很好的 "闪亮 "屏幕。通过将其添加到你的 ~/.bashrc
文件中来实现这一目的。我已经这样做了,包括天气、日期、时间和分布信息,详见本答案: 我怎样才能得到这个终端闪屏?
对不起,当我捕捉到这个图像时,我正在Ubuntu的Windows 10 WSL中进行2018年春季更新。保证我很快就会启动回到Linux中的Ubuntu。
对于更短的天气输出 http://weather.tuxnet24.de 提供雅虎的文本和xml格式的天气数据。
然后可以用xmllint这样的XML解析器获得XML中的文件,即。
我写了一个q&d weather-fetch脚本,它获得当前温度和天气描述,然后存储与描述相对应的unicode符号并输出,如
☂6℃
我定期通过cronjob更新,然后在我的托盘状态中使用输出。
在yahoocom/news/weather获得你的ID。将位置改为你想要的位置,并在URL中寻找ID(例如,如果URL是yahoocom/news/weather/germany/north-rhine-westphalia/bielefeld-200666057,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 (°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";
#!/usr/bin/env bash
为我修复,Ubuntu 18.04 我还有一个方法。
打开你的.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
大写
.bashrc
文件是 "源码",你就不必重新登录。你可以运行: source .bashrc
或者你可以运行这个来代替。 . .bashrc
finger city_name@graph.no
$指cologne@graph.no
-= 德国/北莱茵-西法利亚/科隆的气象图 =-
'C雨
16
15 ^^^
14 ======^^^ ^^^
12 =========
10 ====== ---
9=====| --- 3 mm
8 | | 2 mm
_08_09_10_11_12_13_14_15_16_17_18 19 20 21 22 23 00 01 02 03 04 05 小时
SE SE SE SE SW W W W W W W W W W W W 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 风(mps)
图例左轴: - 晴天 ^ 散乱 = 多云 =V= 雷霆 # 雾
图例右轴。 | 雨! 冰雹 * 雪
[天气预报来自yr.no,由挪威气象局和NRK提供] 。
以下是使用方法:
$指help@graph.no
yr.no有技术问题,或者你指定了一个未知的位置。
使用方法。
* finger <city name>@graph.no (世界天气预报,没有空格)
例如:finger newyork@graph.no
高级用法。
* finger o:<城市名称>@graph.no (单行预报)
例如:finger o:newyork@graph.no
* finger ^<城市名称>@graph.no (帝国单位)
例如:finger ^newyork@graph.no
* finger <city name>+5@graph.no (从时间上提前5小时的预测(max:26))
例如:finger northpole+5@graph.no
* finger <city name>~160@graph.no (设置屏幕宽度)
例子:finger southpole~160@graph.no
* finger <city name>%2@graph.no (每隔一小时的预报[挪威])
例如:finger oslo%2@graph.no
* finger <post code>@graph.no (挪威的天气预报)
例如:finger 0458@graph.no
其他。
* finger news@graph.no (NRK的最新头条新闻)
* finger time@graph.no (服务器当地时间)
* finger date@graph.no (服务器本地日期)
* finger about@graph.no (联系信息)
国际名称来自于 http://fil.nrk.no/yr/viktigestader/verda.txt 。
这背后的 s 故事 来自开发者。
我刚刚做了一个快速端点,可以返回天气,以及一些其他的指标:
curl https://curl-weather.herokuapp.com/
注意,它目前只显示伦敦(英国)的天气。这里是Github repo,如果你想克隆或打开问题: https://github.com/nkhil/weather-script
虽然accuweather curl解决方案非常好,但我需要更多的信息,所以我创建了简单的bash脚本,从weather.com网站提取未来4小时的信息。就像前面的例子一样,你必须为你的位置修改链接。
Example output:
$ ./getWeather.sh
Temperature for 1 AM : 65°F and outside should be: Partly - Cloudy FEELS LIKE: 65°
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;
如果你熟悉国际**组织的站名和机场的METAR天气信息。
sudo apt install metar
并检查你喜欢的机场,以获得数据 https://www.world-airport-codes.com/ 东京国际机场/羽田机场的例子 = RJTT
metar -d rjtt
输出样本
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 :
与 weather
命令不同,这个命令不理解城市或国家的名称。与其说是这个功能,不如说是这个功能能更快地一次加载多个地方。