Ich bin Programmierer
...dafür bist Du aber ziemlich unbeholfen. Als Programmierer weiß man wie man Suchmaschinen benutzt.
also wo man halt so mal brauch wenn man gern programmiert
...sehr zielführende Definition, dessen was du brauchst...🤔😁
API bedeutet einfach Schnittstelle zum Datenaustausch.
Wenn Du nicht präzisieren kannst, auf welche Art von Daten Du zugreifen möchtest, ist Dir nicht zu helfen...
Es gibt Millionen solcher Schnittstellen.
Nur mal die API für Windows-Desktop : https://learn.microsoft.com/de-de/dotnet/api/?view=windowsdesktop-10.0
oder
OpenStreetmap: https://nominatim.org/release-docs/develop/api/Overview/
oder
Wetter: https://open-meteo.com/
...alles kostenlos... (manchmal muss man nur ein wenig suchen)
Hier mal ein kleines völlig simples Beispiel, wie man mit den Online-APIs von OpenStreetmap und OpenMeteo Wetterdaten für einen Platz abfragt.
getWeather.ps1
$ProgressPreference = 'SilentlyContinue' # Consolefortschrittsbalken aus
#WMO weather interpretation code descriptions (& images)
#full description: https://www.nodc.noaa.gov/archive/arc0021/0002199/1.1/data/0-data/HTML/WMO-CODE/WMO4677.HTM
#https://github.com/roe-dl/weathericons?tab=readme-ov-file#wmo-symbole--wmo-symbols
#https://www.meteopool.org/en/encyclopedia-wmo-ww-wx-code-id2
#https://artefacts.ceda.ac.uk/badc_datadocs/surface/code.html (Present weather (from manned (code 4677) and automatic (4680) stations))
#versuch eines "sparsamen" Definitionsobjects, Nicht alle 4677/4680-Codes werden von OpenMeteo verwendet!
$WMODev_Json = '{
"0":{
"day":{
"description":"Sunny",
"image":"http://openweathermap.org/img/wn/01d@2x.png"
},
"night":{
"description":"Clear",
"image":"http://openweathermap.org/img/wn/01n@2x.png"
}
},
"1":{
"day":{
"description":"Mainly Sunny",
"image":"http://openweathermap.org/img/wn/01d@2x.png"
},
"night":{
"description":"Mainly Clear",
"image":"http://openweathermap.org/img/wn/01n@2x.png"
}
},
"2":{
"day":{
"description":"Partly Cloudy",
"image":"http://openweathermap.org/img/wn/02d@2x.png"
},
"night":{
"description":"Partly Cloudy",
"image":"http://openweathermap.org/img/wn/02n@2x.png"
}
},
"3":{
"day":{
"description":"Cloudy",
"image":"http://openweathermap.org/img/wn/03d@2x.png"
},
"night":{
"description":"Cloudy",
"image":"http://openweathermap.org/img/wn/03n@2x.png"
}
},
"45":{
"day":{
"description":"Foggy",
"image":"http://openweathermap.org/img/wn/50d@2x.png"
},
"night":{
"description":"Foggy",
"image":"http://openweathermap.org/img/wn/50n@2x.png"
}
},
"48":{
"day":{
"description":"Rime Fog",
"image":"http://openweathermap.org/img/wn/50d@2x.png"
},
"night":{
"description":"Rime Fog",
"image":"http://openweathermap.org/img/wn/50n@2x.png"
}
},
"51":{
"day":{
"description":"Light Drizzle",
"image":"http://openweathermap.org/img/wn/09d@2x.png"
},
"night":{
"description":"Light Drizzle",
"image":"http://openweathermap.org/img/wn/09n@2x.png"
}
},
"53":{
"day":{
"description":"Drizzle",
"image":"http://openweathermap.org/img/wn/09d@2x.png"
},
"night":{
"description":"Drizzle",
"image":"http://openweathermap.org/img/wn/09n@2x.png"
}
},
"55":{
"day":{
"description":"Heavy Drizzle",
"image":"http://openweathermap.org/img/wn/09d@2x.png"
},
"night":{
"description":"Heavy Drizzle",
"image":"http://openweathermap.org/img/wn/09n@2x.png"
}
},
"56":{
"day":{
"description":"Light Freezing Drizzle",
"image":"http://openweathermap.org/img/wn/09d@2x.png"
},
"night":{
"description":"Light Freezing Drizzle",
"image":"http://openweathermap.org/img/wn/09n@2x.png"
}
},
"57":{
"day":{
"description":"Freezing Drizzle",
"image":"http://openweathermap.org/img/wn/09d@2x.png"
},
"night":{
"description":"Freezing Drizzle",
"image":"http://openweathermap.org/img/wn/09n@2x.png"
}
},
"61":{
"day":{
"description":"Light Rain",
"image":"http://openweathermap.org/img/wn/10d@2x.png"
},
"night":{
"description":"Light Rain",
"image":"http://openweathermap.org/img/wn/10n@2x.png"
}
},
"63":{
"day":{
"description":"Rain",
"image":"http://openweathermap.org/img/wn/10d@2x.png"
},
"night":{
"description":"Rain",
"image":"http://openweathermap.org/img/wn/10n@2x.png"
}
},
"65":{
"day":{
"description":"Heavy Rain",
"image":"http://openweathermap.org/img/wn/10d@2x.png"
},
"night":{
"description":"Heavy Rain",
"image":"http://openweathermap.org/img/wn/10n@2x.png"
}
},
"66":{
"day":{
"description":"Light Freezing Rain",
"image":"http://openweathermap.org/img/wn/10d@2x.png"
},
"night":{
"description":"Light Freezing Rain",
"image":"http://openweathermap.org/img/wn/10n@2x.png"
}
},
"67":{
"day":{
"description":"Freezing Rain",
"image":"http://openweathermap.org/img/wn/10d@2x.png"
},
"night":{
"description":"Freezing Rain",
"image":"http://openweathermap.org/img/wn/10n@2x.png"
}
},
"71":{
"day":{
"description":"Light Snow",
"image":"http://openweathermap.org/img/wn/13d@2x.png"
},
"night":{
"description":"Light Snow",
"image":"http://openweathermap.org/img/wn/13n@2x.png"
}
},
"73":{
"day":{
"description":"Snow",
"image":"http://openweathermap.org/img/wn/13d@2x.png"
},
"night":{
"description":"Snow",
"image":"http://openweathermap.org/img/wn/13n@2x.png"
}
},
"75":{
"day":{
"description":"Heavy Snow",
"image":"http://openweathermap.org/img/wn/13d@2x.png"
},
"night":{
"description":"Heavy Snow",
"image":"http://openweathermap.org/img/wn/13n@2x.png"
}
},
"77":{
"day":{
"description":"Snow Grains",
"image":"http://openweathermap.org/img/wn/13d@2x.png"
},
"night":{
"description":"Snow Grains",
"image":"http://openweathermap.org/img/wn/13n@2x.png"
}
},
"80":{
"day":{
"description":"Light Showers",
"image":"http://openweathermap.org/img/wn/09d@2x.png"
},
"night":{
"description":"Light Showers",
"image":"http://openweathermap.org/img/wn/09n@2x.png"
}
},
"81":{
"day":{
"description":"Showers",
"image":"http://openweathermap.org/img/wn/09d@2x.png"
},
"night":{
"description":"Showers",
"image":"http://openweathermap.org/img/wn/09n@2x.png"
}
},
"82":{
"day":{
"description":"Heavy Showers",
"image":"http://openweathermap.org/img/wn/09d@2x.png"
},
"night":{
"description":"Heavy Showers",
"image":"http://openweathermap.org/img/wn/09n@2x.png"
}
},
"85":{
"day":{
"description":"Light Snow Showers",
"image":"http://openweathermap.org/img/wn/13d@2x.png"
},
"night":{
"description":"Light Snow Showers",
"image":"http://openweathermap.org/img/wn/13n@2x.png"
}
},
"86":{
"day":{
"description":"Snow Showers",
"image":"http://openweathermap.org/img/wn/13d@2x.png"
},
"night":{
"description":"Snow Showers",
"image":"http://openweathermap.org/img/wn/13n@2x.png"
}
},
"95":{
"day":{
"description":"Thunderstorm",
"image":"http://openweathermap.org/img/wn/11d@2x.png"
},
"night":{
"description":"Thunderstorm",
"image":"http://openweathermap.org/img/wn/11n@2x.png"
}
},
"96":{
"day":{
"description":"Light Thunderstorms With Hail",
"image":"http://openweathermap.org/img/wn/11d@2x.png"
},
"night":{
"description":"Light Thunderstorms With Hail",
"image":"http://openweathermap.org/img/wn/11n@2x.png"
}
},
"99":{
"day":{
"description":"Thunderstorm With Hail",
"image":"http://openweathermap.org/img/wn/11d@2x.png"
},
"night":{
"description":"Thunderstorm With Hail",
"image":"http://openweathermap.org/img/wn/11n@2x.png"
}
}
}'
$WMODev_Object = $WMODev_Json|ConvertFrom-Json
#openMeteo arbeitet mit Geokoordinaten, ergo Länge und Breite für einen Orts/Adresse abfragen
#Geokoordinaten für einen Ort ermitteln
#Was immer an Adressdaten verfügbar ist
$SearchStrings = @(
'Leipzig'
'Zentrum'
'Petersbogen'
)
$queryStrings = $SearchStrings|%{[uri]::EscapeDataString($_)}
$Query = $queryStrings -join '+'
Write-Host " Coords - QueryString: $Query" -fo green
#geodaten für "Adresse" abfragen (kann mehrere Ergebnisse liefern), deshalb als Array of Objects behandeln
$GeoCoords = @()
$GeoCoords += ( Invoke-WebRequest "https://nominatim.openstreetmap.org/search?q=$Query&format=json&addressdetails=0").content | ConvertFrom-Json
$GeoCoords #mal anshauen
#https://open-meteo.com/
#querystring für Wetterapi basteln
#$GeoCoords[0] ist hier stumpf der erstbeste Eintrag
$WeatherQuery=@(
'latitude={0}'-f $GeoCoords[0].lat
'longitude={0}'-f $GeoCoords[0].lon
'current=temperature_2m,relative_humidity_2m,precipitation,rain,showers,snowfall,weather_code,cloud_cover,wind_speed_10m,wind_direction_10m'
'hourly=temperature_2m,relative_humidity_2m,weather_code'
#'models = icon' #"icon" = nur Deuschland (DWD) ,ohne Angabe des Wettermodels werden automatisch die zutreffensten werte verwendet!
)-join '&'
Write-Host "OpenMeteo - QueryString: $WeatherQuery" -fo yellow
#Wetterdaten für ermittelten Geo-Tag abrufen
$html = Invoke-WebRequest "https://api.open-meteo.com/v1/forecast?$WeatherQuery"
$Weatherobject = $html.Content|ConvertFrom-Json
#$Weatherobject #mal angucken
Write-Host "aktuelles Wetter:" -fo green
$Weatherobject.Current
#$Weatherobject.hourly
Write-Host "7 Tage Wetter" -fo green
#die Wetterdaten werden als mehrere flache Arrays geliefer!
#in zu Objekten bündeln...
$Weatherobject.hourly.time|%{$cnt=0}{
$WeatherCode = $Weatherobject.hourly.weather_code[$cnt]
$LocalTime=(get-date $_).ToLocalTime()
$CurrentHour = $LocalTime.Hour
#Tag/Nacht: einfach 6..18 Uhr = Tag, sonst Nacht
if ($CurrentHour -gt 5 -and $CurrentHour -lt 18) {
$DayNight = 'day'
} else {
$DayNight = 'night'
}
[PSCustomObject]@{
GMT_DateTime = $_
Local_DateTime =$LocalTime
Temperature_2m = $Weatherobject.hourly.temperature_2m[$cnt]
RelativeHumidity_2m = $Weatherobject.hourly.relative_humidity_2m[$cnt]
WeatherCode = $WeatherCode
WeatherDescription = $WMODev_Object.$WeatherCode.$DayNight.Description
}
$cnt++
}|ft *
pause