2017-03-09 2 views
0

PowerShell을 사용하여 웹 서비스를 쿼리하고시 (Hamburg, Germany)의 데모를위한 날씨를 요청하고 싶습니다.PowerShell - Weather WebService

2011 년부터 다음 URL과 스크립트를 발견했습니다. 그러나이 웹 서비스는 더 이상 작동하지 않습니다.

이 문제를 해결하기위한 아이디어는 무엇입니까? 응답

$a = New-WebServiceProxy 'http://www.webservicex.net/globalweather.asmx?WSDL' 
$a.GetWeather('San Francisco','United States') 

https://learn-powershell.net/2011/02/15/retrieving-weather-information-from-a-web-service-provider/

: 없음 데이터

+2

OpenWeatherAPI는 어떻습니까? 예를 들어 여기를 참조하십시오 : http://www.powershelladmin.com/wiki/Get-Weather_cmdlet_for_PowerShell,_using_the_OpenWeatherMap_API –

+0

감사. 이 사이트를 알고 있지만 기본 기능을 사용하고 싶습니다. – LaPhi

답변

0

헤드 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