頭OpenWeather過來,並讓自己的API關鍵。
This URL有一個所有城市的列表。有多個條目。我發現谷歌搜索和打這個URL舊金山(5391959):
http://openweathermap.org/city/5391959?utm_source=openweathermap&utm_medium=widget&utm_campaign=html_old
...我從中提取的5391959
城市ID。
武裝你的API密鑰和城市的ID,您可以使用以下兩條命令,讓您的天氣JSON格式:
$weather = Invoke-WebRequest -Uri 'api.openweathermap.org/data/2.5/weather?id=5391959&APPID=YOUR_API_KEY_HERE'
$weatherObject = $weather.Content | ConvertFrom-Json
$weatherObject # display to console
...它會給你一個對象,像這樣:
coord : @{lon=-122.42; lat=37.77}
weather : {@{id=804; main=Clouds; description=overcast clouds; icon=04n}}
base : stations
main : @{temp=285.91; pressure=1017; humidity=93; temp_min=283.15; temp_max=288.15}
visibility : 16093
wind : @{speed=4.6; deg=240}
clouds : @{all=90}
dt : 1489134900
sys : @{type=1; id=226; message=0.1525; country=US; sunrise=1489156026; sunset=1489198372}
id : 5391959
name : San Francisco
cod : 200
OpenWeatherAPI呢?看到這裏例如:http://www.powershelladmin.com/wiki/Get-Weather_cmdlet_for_PowerShell,_using_the_OpenWeatherMap_API –
謝謝。我知道這個網站,但我想使用內置功能。 – LaPhi