ターミナルからの天気


66

ターミナルから特定の都市の現在の天気や現在地を見つけたい。コマンドラインの天気アプリはありますか?

回答:


135

ターミナルに次のように入力するだけです:

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 )

開発者のソースコードはGithubで入手できます。


2
はるかに良い方法!
ザカリーダーハン

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°

しかし、どのように私も摂氏に変更しない
DAT tutbrus

ソース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日、列?
ティモ

私のせい、awkセパレータは'です。APIは2つの番号を使用しpostleitzahlます。最初の番号はまたはzipcodeです。第二は、APIコード番号と思わ
ティモ

1
動作しなくなりました。AccuweatherAPIは変更されましたか?
ティモ

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

これは機能しなくなり、最後の日付は2015年5月からです(少なくとも南アフリカのケープタウン)。xml出力を詳細に調べると、2015年5月以降、txt_forecast親が更新されていない一方で、simpleforecast要素には最新のデータが含まれているようです。
ザヒルJ

私は私の答えを更新します
rɑːdʒɑ

あなたは天気<場所名>は仕事をしたい場合は$ 1をYOUZIPORLOCATIONを交換
エド・ネヴィル

(ワシントンDC郵便番号)に置き換え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
ブラッターマン

14

Goで書かれた素晴らしい半グラフィカルなコマンドラインユーティリティを次に示します。

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

Goをインストールし、いくつかのAPIをセットアップする必要がありますが、手順はそこにあります。サンプル写真は次のとおりです。

ここに画像の説明を入力してください


5
これは現在、パブリックにホストされています-地域マッピングへのIPアドレス。試してください:curl -4 wttr.in
jschrab

2
@jschrab:実際に-4は必要ありません。curl wttr.in十分です
イゴールチュビン

:メートル単位はそうのように、公にホストされたバージョンでも利用可能ですcurl wttr.in/Helsinki?m
Villeの


5

まず、weather-utilパッケージをインストールする必要があります。これを行うには、キーボードのCtrl+ Alt+ Tを押してターミナルを開きます。開いたら、以下のコマンドを実行します:

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)現在の天気を知る方法がないことを示しています。
アビナッシュラジ

現在の情報である可能性がある場所に応じて。
ミッチ

1
私はこれを試してみましたが、今では使いやすいことがわかりました。weather YOURLOCATIONNAMEそれはそのときあなたの場所を検索し、おそらく複数の結果を提供します。これらから、気象情報を取得するための引数として使用できるステーション識別子を読み取ることができます
Nicolas

依存しているサービスが廃止されたようです。バージョン2.0をインストールしたばかりで、weather LAX(ロサンゼルス国際空港の天気が表示されるはずです)weather.noaa.gov/pub/data/observations/metar/decoded/KNKX.TXTの
キーストンプソン

1
その特定のデータファイルは、ここからここに移動しまし。それぞれの出現変更、データ・ファイルを更新することが可能であるべきhttp://weather.noaa.gov/pub/dataとしますhttp://tgftp.nws.noaa.gov/data。更新:バージョン2.1ですでに修正されているようです。プロジェクトサイトから入手できます。
キーストンプソン

5

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 ☔

https://github.com/fcambus/ansiweather


2

また、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

inxiは10.04の時点ではubuntuの一部ではないようですが、次のコマンドでインストールできます。sudo apt install inxi
Starbuck

はい、inxi使用できますが、最初にユニバースリポジトリを有効にする必要があります。
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

この画像をキャプチャしたとき、2018年春のアップデート用のWindows 10 WSLのUbuntuでごめんなさい。約束私はすぐにLinuxでUbuntuを起動します。


2

さらに短い天気出力の場合、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 (&#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";

リダイレクトの予期しないエラー
フィリップカークブライド

#!/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ソリューションはかなり優れていますが、もっと情報が必要なため、weather.com Webサイトから次の4時間の情報を取得する単純なbashスクリプトを作成しました。前の例のように、場所のリンクを変更する必要があります。

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.

この背後にある物語開発者から。

弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.