回答:
ターミナルに次のように入力するだけです:
curl wttr.in
からあなたの場所を取得します/etc/timezone
。そうでなければcurl wttr.in/your_location
。たとえば、テヘランの場合:
curl wttr.in/tehran
それはあなたに与えます:
2つの都市を比較することもできます。
diff -Naur <(curl -s http://wttr.in/london ) <(curl -s http://wttr.in/new-york )
devs
私たちの間では悪くありません
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
ます。最初の番号はまたはzipcodeです。第二は、APIコード番号と思わ
もう一つ方法があります。
.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&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
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&deg;C (89&deg;F). Winds 43 kph East
Goで書かれた素晴らしい半グラフィカルなコマンドラインユーティリティを次に示します。
https://github.com/schachmat/wego/
Goをインストールし、いくつかのAPIをセットアップする必要がありますが、手順はそこにあります。サンプル写真は次のとおりです。
curl wttr.in
十分です
curl wttr.in/Helsinki?m
まず、weather-utilパッケージをインストールする必要があります。これを行うには、キーボードのCtrl+ Alt+ Tを押してターミナルを開きます。開いたら、以下のコマンドを実行します:
sudo apt-get install weather-util
インストール後、実行できますweather -i <code>
。上記のリンクから取得したコード。利用可能なオプションのリストについては、天気情報を実行できますweather
Last updated Dec 11, 2013 - 07:00 AM EST / 2013.12.11 1200 UTC Temperature: 86 F (30 C)
現在の天気を知る方法がないことを示しています。
weather YOURLOCATIONNAME
それはそのときあなたの場所を検索し、おそらく複数の結果を提供します。これらから、気象情報を取得するための引数として使用できるステーション識別子を読み取ることができます
weather LAX
(ロサンゼルス国際空港の天気が表示されるはずです)weather.noaa.gov/pub/data/observations/metar/decoded/KNKX.TXTの
ansiweather
AnsiWeatherは、端末の現在の気象状態を表示するためのシェルスクリプトであり、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 ☔
また、inxiと呼ばれるubuntuがプリインストールされているプログラムは、コンピューター上のすべてのタイプの統計情報を提供し、天気予報を出力します。
コマンド: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
ファイルに追加してこれを行います。この回答で詳しく説明されているように、天気、日付、時刻、および分布情報を含めるためにこれを実行しました。この端末のスプラッシュ画面を取得するにはどうすればよいですか?
この画像をキャプチャしたとき、2018年春のアップデート用のWindows 10 WSLのUbuntuでごめんなさい。約束私はすぐにLinuxでUbuntuを起動します。
さらに短い天気出力の場合、http://weather.tuxnet24.deはYahoo!からの天気データを提供します。テキストおよびxml形式。
XMLからのフィールドは、xmllint ieなどのXMLパーサーで取得できます。
Q&Dウェザーフェッチスクリプトを作成し、現在の気温と天気の説明を取得し、その説明に対応するUnicodeシンボルを保存し、次のように出力します。
☂6°C
cronjobで定期的に更新してから、トレイステータスの出力を使用しています。
yahoocom / news / weatherでIDを取得します。場所を目的の場所に変更し、URLでIDを探します(URLがyahoocom / news / weather / germany / north-rhine-westphalia / bielefeld-20066057の場合、IDは20066057です)。
XMLには、予測データ、風などの追加フィールドが含まれています。必要に応じて、それらを解析することもできます。
残念ながら、一部の天気記号はUbuntufontに表示されません…お気軽に調整してください。
ここに私のスクリプトがあります(ビーレフェルトに住んでいない場合は、20066057をIDに置き換えてください)-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
accuweather curlソリューションはかなり優れていますが、もっと情報が必要なため、weather.com Webサイトから次の4時間の情報を取得する単純なbashスクリプトを作成しました。前の例のように、場所のリンクを変更する必要があります。
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;
完全なスクリプトは次の場所にあります:https : //sites.google.com/site/wozoopalinux/home/wzbash001/get-weather-information-from-command-line-for-next-4-hrs
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.
この背後にある物語開発者から。