mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-06-30 20:50:02 +02:00
Added locate-zip-code.ps1
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
#!/snap/bin/powershell
|
||||
|
||||
# Syntax: ./locate-city.ps1 [<city>]
|
||||
# Description: prints the lat/long coordinates of the given city
|
||||
# Description: prints the geographic location of the given city
|
||||
# Author: Markus Fleschutz
|
||||
# Source: github.com/fleschutz/PowerShell
|
||||
# License: CC0
|
||||
|
@ -1,7 +1,7 @@
|
||||
#!/snap/bin/powershell
|
||||
|
||||
# Syntax: ./locate-ipaddress.ps1 [<IPaddress>]
|
||||
# Description: locates the geographic position of the given IP address
|
||||
# Description: prints the geographic location of the given IP address
|
||||
# Author: Markus Fleschutz
|
||||
# Source: github.com/fleschutz/PowerShell
|
||||
# License: CC0
|
||||
|
44
Scripts/locate-zip-code.ps1
Executable file
44
Scripts/locate-zip-code.ps1
Executable file
@ -0,0 +1,44 @@
|
||||
#!/snap/bin/powershell
|
||||
|
||||
# Syntax: ./locate-zip-code.ps1 [<country-code>] [<zip-code>]
|
||||
# Description: prints the geographic location of the given zip-code
|
||||
# Author: Markus Fleschutz
|
||||
# Source: github.com/fleschutz/PowerShell
|
||||
# License: CC0
|
||||
|
||||
param([string]$CountryCode, [string]$ZipCode)
|
||||
if ($CountryCode -eq "" ) {
|
||||
$CountryCode = read-host "Enter the country code"
|
||||
}
|
||||
if ($ZipCode -eq "" ) {
|
||||
$ZipCode = read-host "Enter the zip code"
|
||||
}
|
||||
|
||||
try {
|
||||
write-progress "Reading zip-codes.csv..."
|
||||
$PathToData=(get-item $MyInvocation.MyCommand.Path).directory
|
||||
$PathToData="$PathToData/../Data"
|
||||
$Table = import-csv "$PathToData/zip-codes.csv"
|
||||
|
||||
$FoundOne = 0
|
||||
foreach($Row in $Table) {
|
||||
if ($Row.country -eq $CountryCode) {
|
||||
if ($Row.postal_code -eq $ZipCode) {
|
||||
$City = $Row.city
|
||||
$Lat = $Row.latitude
|
||||
$Lon = $Row.longitude
|
||||
write-host "* $City is at $Lat°N, $Lon°W"
|
||||
$FoundOne = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($FoundOne) {
|
||||
exit 0
|
||||
}
|
||||
write-error "Zip-code $ZipCode in country $CountryCode not found"
|
||||
exit 1
|
||||
} catch {
|
||||
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
Reference in New Issue
Block a user