Added locate-zip-code.ps1

This commit is contained in:
Markus Fleschutz 2020-12-16 11:03:47 +00:00
parent 0594220187
commit d80ef764d7
5 changed files with 1129950 additions and 4 deletions

1129901
Data/zip-codes.csv Normal file

File diff suppressed because it is too large Load Diff

View File

@ -20,8 +20,9 @@ The following PowerShell scripts can be found in the [Scripts/](Scripts/) subfol
* [list-modules.ps1](Scripts/list-modules.ps1) - lists the PowerShell modules
* [list-passwords.ps1](Scripts/list-passwords.ps1) - generates and prints a list of new passwords
* [list-processes.ps1](Scripts/list-processes.ps1) - lists the local computer processes
* [locate-city.ps1](Scripts/locate-city.ps1) - prints the lat/long coordinates of the given city
* [locate-ipaddress.ps1](Scripts/locate-ipaddress.ps1) - locates the geographic position of the given IP address
* [locate-city.ps1](Scripts/locate-city.ps1) - prints the geographic location of the given city
* [locate-ipaddress.ps1](Scripts/locate-ipaddress.ps1) - prints the geographic location of the given IP address
* [locate-zipcode.ps1](Scripts/locate-zip-code.ps1) - prints the geographic location of the given zip-code
* [MD5.ps1](Scripts/MD5.ps1) - prints the MD5 checksum of the given file
* [make-install.ps1](Scripts/make-install.ps1) - installs built executables and libs to the installation directory
* [moon.ps1](Scripts/moon.ps1) - prints the current moon phase

View File

@ -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

View File

@ -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
View 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
}