<# .SYNOPSIS NL: Toon actuele KNMI weergegevens EN: Show live Dutch weather data from the Dutch KNMI weather institute .DESCRIPTION NL: Dit script toont actuele KNMI weergegevens m.b.v. de Weerlive API. De Weerlive API stelt elke 10 minuten actuele weergegevens beschikbaar. Alle opgehaalde gegevens worden door dit script in het console venster weergegeven. Daarnaast wordt de afgeronde waarde van de actuele temperatuur in een pictogram in de "System Tray" getoond. Door te klikken op dit pictogram, wordt het console venster verborgen of juist weer hersteld. Om van de Weerlive API gebruik te mogen maken, hebt u een API key nodig (gratis voor persoonlijk en educatief gebruik), die u bij Weerlive.nl kunt aanvragen (zie link). Deze API key en de lokatie waarvoor de gegevens worden opgevraagd, dient u op te geven op de commandoregel of in te vullen bij na starten van het script of op te slaan in een tekstbestand "weerlive.cfg" dat zich in de zelfde map moet bevinden als dit script. Het bestand "weerlive.cfg" bevat 2 regels tekst: key=uw_persoonlijke_api_key loc=gewenste_lokatie Het script kan netjes afgesloten worden door een willekeurige toetsaanslag in het console venster. EN: This script shows live Dutch weather data from the Dutch KNMI weather institute, using the Weerlive live weather API. This API makes live weather data available once every 10 minutes. All data will be displayed in this script's console window. The rounded actual temperature will also be shown in the System Tray a.k.a. Notification Area. By clicking the icon in the Notification Area, this script's console window will be hidden or restored again. Use of the Weerlive API requires an API key (free for personal or educational use), which you can request at Weerlive.nl (see link). This API key and the location for which the data will be fetched, must either be specified on the command line or entered in a popup window when the script is started or be saved in a plain text file named "weerlive.cfg", located in the script's parent folder. The file "weerlive,cfg" contains only 2 lines of text: key=your_personal_api_key loc=your_location The script can be terminated gracefully by pressing any key in the console window. Note that a basic knowledge of the Dutch language is required to get this script working with your own API key. .PARAMETER Location NL: De plaatsnaam voor de weersgegevens. Indien zowel op de commandoregel als in een configuratiebestand een lokatie wordt opgegeven, prevaleert de commandoregel. Indien er geen plaatsnaam is opgegeven op de commandoregel en ook niet in een configuratiebestand, dan wordt een invulscherm geopend om deze alsnog in te voeren. Als APIKey en Location beide op de opdrachtregel worden meegegeven, en het configuratiebestand weerlive.cfg bestaat nog niet, dan wordt dit bestand aangemaakt. EN: De location used for the weather query. If the location is specified both on the command line sa well as in a configuration file, the command line prevails. If no location is specified on the command line and neither in a configuration file, a popup window will appear where the locatien can be specified. If both APIKey and Location are specified on the command line, and the configuration file weerlive.cfg does not exist, it will be created.. .PARAMETER APIKey NL: De API key voor het opvragen van de weersgegevens. Indien zowel op de commandoregel als in een configuratiebestand een API key wordt opgegeven, prevaleert de commandoregel. Indien er geen API key is opgegeven op de commandoregel en ook niet in een configuratiebestand, dan wordt een invulscherm geopend om deze alsnog in te voeren. Als APIKey en Location beide op de opdrachtregel worden meegegeven, en het configuratiebestand weerlive.cfg bestaat nog niet, dan wordt dit bestand aangemaakt. EN: De API key required for the weather query. If an API key is specified both on the command line as well as in a configuration file, the command line prevails. If no API key is specified on the command line and neither in a configuration file, a popup window will appear where an API key can be specified. If both APIKey and Location are specified on the command line, and the configuration file weerlive.cfg does not exist, it will be created. .PARAMETER NoSave NL: Voorkomt dat de waarden van APIKey en Location die op de opdrachtregel worden meegegeven, bij opslaan een bestaand configuratiebestand overschrijven. EN: Prevent APIKey and Location values on the command line from overwriting an existing configuration file. .PARAMETER Edit NL: Opent het invulvenster voor API key en plaatsnaam bij opstarten van het script. Dit invulvenster verschijnt ook als API key of plaatsnaam niet opgegeven zijn. EN: Opens the configuration window to enter an API key and location at startup of this script. This window will also be opened if API key or location aren't specified. .PARAMETER Hide NL: Verberg het console venster direct na opstarten van het script. Klik op het icoon in de "System Tray" om het console venster te herstellen. EN: Hide this script's console immediately after starting the script. Clicking the icon in the Notification area will restore the console again. .PARAMETER Help NL: Toon deze uitleg. EN: Show this help text. .PARAMETER Version NL: Toon de versie van dit script. Gecombineerd met de -Verbose parameter worden daarnaast ook het volledige pad en de laatste wijzigings- of publikatiedatum van het script getoond. EN: Show this script's version. If combined with the -Verbose switch, the script's full path and last modified or release date will be shown as well. .PARAMETER Verbose NL: Toon uitgebreidere versie-informatie bij gebruik van de -Version parameter. EN: Show verbose version information when using the -Version switch. .LINK NL: EN: .LINK Script geschreven door Rob van der Woude: Script written by Rob van der Woude: https://www.robvanderwoude.com/ https://www.robvanderwoude.com/ .LINK KNMI Weergegevens via Weerlive.nl API: Dutch KNMI weather data by Weerlive.nl API: http://weerlive.nl/delen.php http://weerlive.nl/delen.php .LINK Weerlive API key aanvragen: Request Weerlive API key: http://weerlive.nl/api/toegang/index.php http://weerlive.nl/api/toegang/index.php .LINK Tabel met alle geldige plaatsnamen: Table of valid location names: http://weerlive.nl/plaatsnamen.php http://weerlive.nl/plaatsnamen.php #> param ( [string]$Location, [string]$APIKey, [switch]$NoSave, [switch]$Edit, [switch]$Hide, [switch]$Help, [switch]$Version, [switch]$Verbose ) $progver = "1.00" Add-Type -AssemblyName System.Drawing Add-Type -AssemblyName System.Text.RegularExpressions Add-Type -AssemblyName System.Windows.Forms Clear-Host if ( $Version ) { if ( $Verbose ) { $lastmod = ( [System.IO.File]::GetLastWriteTime( $PSCommandPath ) ) if ( $lastmod.ToString( "h.mm" ) -eq $progver ) { "`"{0}`", Version {1}, release date {2}" -f $PSCommandPath, $progver, $lastmod.ToString( "yyyy-MM-dd" ) } else { # if last modified time is not equal to program version, the script has been tampered with "`"{0}`", Version {1}, last modified date {2}" -f $PSCommandPath, $progver, $lastmod.ToString( "yyyy-MM-dd" ) } } else { $progver } exit 0 } if ( $Help -or ( [System.Environment]::CommandLine -match "[/\?]" ) ) { Get-Help $PSCommandPath -Full exit 1 } $configfile = ( Join-Path $PSScriptRoot 'weerlive.cfg' ) $cachefile = ( Join-Path $PSScriptRoot 'weerlive.dat' ) if ( ![string]::IsNullOrWhiteSpace( $APIKey ) -and ![string]::IsNullOrWhiteSpace( $Location ) ) { Remove-Item -Path $cachefile -Force # Write command line APIKey and Location values to configuration file if that does not yet exist, unless NoSave switch was used if ( !$NoSave -and !( Test-Path -Path $configfile -PathType Leaf ) ) { ( "key={0}`nloc={1}" -f $APIKey, $Location ) | Out-File -FilePath $configfile -Force -Encoding 'ASCII' } } function Get-Locations( ) { $url = "http://weerlive.nl/plaatsnamen.php" $ProgressPreference = 'SilentlyContinue' $html = ( Invoke-WebRequest -Uri $url -TimeoutSec 10 ).Content $ProgressPreference = 'Continue' $pattern = '