Meteo dal terminal


66

Voglio trovare il tempo corrente di una determinata città o la mia posizione dal terminal. Esiste un'app meteo a riga di comando?

Risposte:


135

Basta inserire quanto segue in un terminale:

curl wttr.in

E otterrà la tua posizione da /etc/timezone. In caso contrario curl wttr.in/your_location. Ad esempio, per Teheran:

curl wttr.in/tehran

Che ti dà:

Uscita campione

Puoi anche confrontare due città:

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

Il codice sorgente dello sviluppatore è disponibile su Github .


2
Molto meglio!
Zachary Dahan,

2
github.com/schachmat/wego non è male per devsnoi due
Timo

piace, ma questa volta ha generato un errore: Siamo spiacenti, al momento stiamo esaurendo le query per il servizio meteo. Riceveremo nuove query il prima possibile.
Doyousketch2,

17

Cerca la tua città su http://www.accuweather.com e sostituisci l'URL nel seguente script con l'URL della tua città:

#!/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

Uscita campione:

Berlin, Germany: Foggy, 1°

Ma come posso cambiarlo in
Celcius

Nel codice sorgente HTML, vedo 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"});. Usando il tuo codice, il awkseparatore di campo è '' (spazio). Is $12(temperatura) la colonna 12 °?
Timo,

Colpa mia, è il awkseparatore '. L'API utilizza 2 numeri, il primo è il postleitzahlcodice postale o. Il secondo sembra essere un numero di codice api
Timo

1
Non funziona più, l'API Accuweather è cambiata?
Timo,

14

Ho un altro modo.

Apri il tuo .bashrcfile e quindi incolla questo codice in fondo

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

Quindi salva e chiudi il tuo .bashrcfile.

ora digita bashper aggiornare il file.

quindi digitare

weather <location name>

per esempio

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
Bello con le previsioni del tempo. +1 da me.
souravc,

Questo non funziona più, le ultime date che mostra sono di maggio 2015 (almeno per Città del Capo, Sudafrica). Un esame più attento dell'output XML rivela che il genitore txt_forecast non è stato aggiornato da maggio 2015 mentre l'elemento simpleforecast sembra avere gli ultimi dati.
Zahir J,

Aggiornerò la mia risposta
rʒɑdʒɑ

Sostituisci YOUZIPORLOCATION con $ 1 se vuoi che il tempo <nome della località> funzioni
Ed Neville,

Se si sostituisce YOUZIPORLOCATIONcon $1e passo 20001(Washington, DC codice postale), ottengo le linee che sembrano non formattato come Today: Mostly sunny and breezy. Highs in the upper 30s. Northwest winds 20 to 25 mph with gusts up to 45 mph.Quando uso "washington.dc", ottengo uscita tavolo May 4, 2015: Clear. High 32&amp;deg;C (89&amp;deg;F). Winds 43 kph East. Qualche idea sul perché la differenza?
Blalterman,

14

Ecco una grande utility semi-grafica da riga di comando scritta in Go:

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

Dovrai installare Go e configurare alcune cose API, ma ci sono le istruzioni. Ecco una foto di esempio:

inserisci qui la descrizione dell'immagine


5
Questo è attualmente ospitato pubblicamente - con indirizzo IP per la mappatura della regione. Prova: curl -4 wttr.in
jschrab

2
@jschrab: E in realtà non hai bisogno di -4. curl wttr.inè abbastanza
Igor Chubin,

Le unità metriche sono disponibili anche nella versione ospitata pubblicamente, in questo modo:curl wttr.in/Helsinki?m
Ville

6

Prova a usare

telnet rainmaker.wunderground.com

1
Questo sembra essere solo negli Stati Uniti?
Vladimir Panteleev,

5

Per prima cosa devi installare il pacchetto weather-util, per farlo basta premere Ctrl+ Alt+ Tsulla tastiera per aprire Terminale. Quando si apre, esegui i seguenti comandi:

sudo apt-get install weather-util

Avrai bisogno del tuo codice meteo locale .

Dopo l'installazione è possibile eseguire weather -i <code>. Il codice che ottieni dal link sopra. Per un elenco di opzioni disponibili, è possibile eseguire weatherInformazioni meteo


1
mostra che Last updated Dec 11, 2013 - 07:00 AM EST / 2013.12.11 1200 UTC Temperature: 86 F (30 C)non c'è modo di conoscere il tempo corrente.
Avinash Raj,

A seconda della posizione, potrebbero essere le informazioni correnti disponibili.
Mitch

1
Ho appena provato questo e ho scoperto che ora è più facile da usare: weather YOURLOCATIONNAMEcerca quindi la tua posizione e fornisce probabilmente più risultati. Da questi puoi leggere l'identificatore di stazione che puoi usare come argomento per recuperare le tue informazioni meteo da
Nicolas

Sembra che il servizio da cui dipende sia stato sospeso. Ho appena installato la versione 2.0 e weather LAX(che dovrebbe mostrare il tempo per l'aeroporto internazionale di Los Angeles) mostra un errore 404 per weather.noaa.gov/pub/data/observations/metar/decoded/KNKX.TXT
Keith Thompson

1
Quel particolare file di dati si è spostato da qui a qui . Dovrebbe essere possibile aggiornare i file di dati, modificando ciascuna occorrenza di http://weather.noaa.gov/pub/dataa http://tgftp.nws.noaa.gov/data. AGGIORNAMENTO: sembra che l'abbiano già risolto nella versione 2.1, che puoi ottenere dal sito del progetto .
Keith Thompson,

5

ansiweather

AnsiWeather è uno script Shell per la visualizzazione delle condizioni meteorologiche attuali nel terminale, con supporto per i colori ANSI e i simboli Unicode. I dati meteorologici provengono dall'API meteo gratuita di OpenWeatherMap.

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

anche un programma preinstallato con Ubuntu chiamato inxi ti darà tutti i tipi di statistiche sul tuo computer e produce un output meteorologico.

comando: inxi --help

comando: inxi -w

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

comando: 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

Sembra che inxi non faccia parte di Ubuntu, a partire dal 10.04, ma possa essere installato consudo apt install inxi
Starbuck,

Sì, inxiè disponibile ma devi prima abilitare il repository dell'universo.
mchid

2

Puoi confrontare le città usando:

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

come illustrato nella risposta più votata. wttr.increa anche un ottimo schermo "splash" ogni volta che apri il terminale. Fallo aggiungendolo al tuo ~/.bashrcfile. L'ho fatto per includere informazioni su Meteo, Data, Ora e Distribuzione come dettagliato in questa risposta: Come posso ottenere questa schermata iniziale del terminale?

Bash Splash in Windows 10.png

Mi dispiace che mi trovassi su Ubuntu in Windows 10 WSL per gli aggiornamenti della primavera 2018 quando ho catturato questa immagine. Prometto che riavvio presto in Ubuntu in Linux.


2

Per una produzione meteorologica ancora più breve http://weather.tuxnet24.de fornisce dati meteo da Yahoo! in formato testo e xml.

I fild dall'XML possono quindi essere ottenuti con un parser XML come xmllint ie.

Ho scritto uno script q & d weather-fetch, che ottiene la temperatura e la descrizione attuali del tempo, quindi memorizza un simbolo unicode corrispondente alla descrizione e lo emette come

☂ 6 ° C

Mi aggiorno regolarmente tramite cronjob e quindi utilizzo l'output nel mio stato del vassoio.

Ottieni il tuo ID su yahoocom / notizie / meteo. Cambia la posizione nella posizione desiderata e cerca l'ID nell'URL (ovvero se l'URL è yahoocom / notizie / meteo / germania / nord-reno-westfalia / bielefeld-20066057 l'ID è 20066057).

L'XML contiene ulteriori campi, ovvero dati di previsione, vento, ecc. Puoi anche analizzarli, se lo desideri.

Sfortunatamente alcuni simboli meteorologici non sono rappresentati nell'Ubuntufont ... sentiti libero di aggiustare.

Ecco la mia sceneggiatura (sostituisci 20066057 con il tuo ID se non vivi a Bielefeld) - dipende da bash, curl e 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";

errore di reindirizzamento imprevisto
Philip Kirkbride,

Cambiando shebang in #!/usr/bin/env bashfixed per me, Ubuntu 18.04
Philip Kirkbride,

2

Ho un altro modo.

Apri il tuo file .bashrc e quindi incolla questo codice in fondo

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

Salvare e chiudere il .bashrcfile ed eseguire il comando seguente per aggiornare bash:

. .bashrc 

quindi digitare Wlettere maiuscole


bash: W: comando non trovato

Dopo la modifica .bashrc relogin
sergkog

Non è necessario eseguire nuovamente il login se si "sorgente" il .bashrcfile. È possibile eseguire: source .bashrcoppure è possibile eseguire questo invece:. .bashrc
mchid

0

Sebbene la soluzione accuweather curl sia abbastanza buona, avevo bisogno di qualcosa di più informativo, quindi ho creato un semplice script bash che estrae informazioni per le prossime 4 ore dal sito Web weather.com. Come nell'esempio precedente, è necessario modificare il collegamento per la propria posizione.

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;

Lo script completo è disponibile all'indirizzo: https://sites.google.com/site/wozoopalinux/home/wzbash001/get-weather-information-from-command-line-for-next-4-hrs


0

Meteogramma di tutte le principali città del mondo

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

Ecco come usarlo:

$ 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.

La storia dietro questo dallo sviluppatore.

Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.