Search notes:

WebAPI: openweathermap

Query openweathermap data with PowerShell

The following PowerShell script allows to query the openweathermap Web API.
In order to run, the variable $openweathermapAPIkey must be set to a valid API key.
The script is invoked with latitude, longitude, for example like so:
PS C:\> openweathermap.ps1 47.509 8.6431
param (
   [float] $lat,
   [float] $lon
);

set-strictMode -version 3

$url = "https://api.openweathermap.org/data/2.5/weather?appid=$openweathermapAPIkey&lat=$lat&lon=$lon"

$res = convertFrom-json ((invoke-webRequest $url).content)

"Name:        $($res.name)"
"Weather:     $($res.weather.main) / $($res.weather.description)"
"Temperature: $($res.main.temp - 271.15), feels like $($res.main.feels_like - 271.15) (min/max: $($res.main.temp_min - 271.15)/$($res.main.temp_max - 271.15)"
"Pressure:    $($res.main.pressure)"
"Humidity:    $($res.main.Humidity)"
"Visibility:  $($res.Visibility)"
"Wind:        $($res.wind.speed) @ $($res.wind.deg)"
"Rain:        $($res.rain.'1h')"
"Clouds:      $($res.clouds.'all')"

See also

Web APIs

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758206646, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/web/APIs/openweathermap(68): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78