2021-02-09 19:30:45 +01:00
|
|
|
#!/bin/powershell
|
2020-12-29 15:14:21 +01:00
|
|
|
<#
|
|
|
|
.SYNTAX ./locate-city.ps1 [<city>]
|
|
|
|
.DESCRIPTION prints the geographic location of the given city
|
|
|
|
.LINK https://github.com/fleschutz/PowerShell
|
|
|
|
.NOTES Author: Markus Fleschutz / License: CC0
|
|
|
|
#>
|
2020-11-01 12:11:15 +01:00
|
|
|
|
2021-02-18 20:17:55 +01:00
|
|
|
param($City = "")
|
|
|
|
|
2020-11-06 15:30:14 +01:00
|
|
|
if ($City -eq "" ) {
|
2021-02-18 20:17:55 +01:00
|
|
|
$City = read-host "Enter the city name"
|
2020-11-06 15:30:14 +01:00
|
|
|
}
|
2021-02-18 20:17:55 +01:00
|
|
|
|
2021-01-02 11:08:59 +01:00
|
|
|
$PathToRepo = "$PSScriptRoot/.."
|
2020-11-01 12:11:15 +01:00
|
|
|
|
|
|
|
try {
|
2020-11-06 15:30:14 +01:00
|
|
|
write-progress "Reading worldcities.csv..."
|
2020-12-25 11:30:43 +01:00
|
|
|
$Table = import-csv "$PathToRepo/Data/worldcities.csv"
|
|
|
|
|
2020-11-01 12:11:15 +01:00
|
|
|
$FoundOne = 0
|
|
|
|
foreach($Row in $Table) {
|
|
|
|
if ($Row.city -eq $City) {
|
|
|
|
$FoundOne = 1
|
|
|
|
$Country = $Row.country
|
|
|
|
$Region = $Row.admin_name
|
|
|
|
$Lat = $Row.lat
|
|
|
|
$Long = $Row.lng
|
|
|
|
$Population = $Row.population
|
2020-11-22 10:36:46 +01:00
|
|
|
write-host "* $City ($Country, $Region, population $Population) is at $Lat°N, $Long°W"
|
2020-11-01 12:11:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($FoundOne) {
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
write-error "City $City not found"
|
|
|
|
exit 1
|
2020-12-09 10:30:55 +01:00
|
|
|
} catch {
|
2021-02-16 10:03:20 +01:00
|
|
|
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
2020-12-09 10:30:55 +01:00
|
|
|
exit 1
|
|
|
|
}
|