added first API training with NASAs Neo Feed
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
*.env
|
||||||
56
NASA-API.ps1
Normal file
56
NASA-API.ps1
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
Get-Content .env | ForEach-Object {
|
||||||
|
if ($_ -match "^\s*([^#][^=]+)=(.*)$") {
|
||||||
|
$name = $matches[1].Trim()
|
||||||
|
$value = $matches[2].Trim()
|
||||||
|
|
||||||
|
[System.Environment]::SetEnvironmentVariable($name, $value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiKey = $env:API_KEY
|
||||||
|
$startDate = "2026-01-01"
|
||||||
|
$endDate = "2026-01-01"
|
||||||
|
|
||||||
|
try {
|
||||||
|
$response = Invoke-RestMethod -Uri "https://api.nasa.gov/neo/rest/v1/feed?start_date=$($startDate)&end_date=$($endDate)&api_key=$($apiKey)" -ResponseHeadersVariable headers
|
||||||
|
#$response = Invoke-WebRequest -Uri "https://api.nasa.gov/neo/rest/v1/feed?start_date=$($startDate)&end_date=$($endDate)&api_key=$($apiKey)"
|
||||||
|
|
||||||
|
#$response | ConvertTo-Json -Depth 10
|
||||||
|
$limit = $headers["X-RateLimit-Limit"]
|
||||||
|
$remaining = $headers["X-RateLimit-Remaining"]
|
||||||
|
|
||||||
|
Write-Host "-------------"
|
||||||
|
Write-Host "Rate Limit: $limit"
|
||||||
|
Write-Host "Remaining : $remaining"
|
||||||
|
Write-Host "-------------"
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Host "Fehler: $($_.Exception.Message)"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#$response | ConvertTo-Json -Depth 10 | Out-File ".\NeoFeed.json"
|
||||||
|
|
||||||
|
$limit = 0
|
||||||
|
|
||||||
|
$response.near_earth_objects.PSObject.Properties | ForEach-Object {
|
||||||
|
$date = $_.Name
|
||||||
|
$asteroids = $_.Value
|
||||||
|
|
||||||
|
Write-Host "Datum: $date"
|
||||||
|
Write-Host "-------------------"
|
||||||
|
|
||||||
|
foreach ($asteroid in $asteroids) {
|
||||||
|
if($asteroid.is_potentially_hazardous_asteroid){
|
||||||
|
Write-Host "| Name: $($asteroid.name) --- Hazardous: $($asteroid.is_potentially_hazardous_asteroid)" -ForegroundColor Red
|
||||||
|
}else {
|
||||||
|
Write-Host "| Name: $($asteroid.name) --- Hazardous: $($asteroid.is_potentially_hazardous_asteroid)" -ForegroundColor Green
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "| Miss-Distance(in KM): $($asteroid.close_approach_data.miss_distance.kilometers)"
|
||||||
|
Write-Host "---------------------"
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
6992
NeoFeed.json
Normal file
6992
NeoFeed.json
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user