diff --git a/streets.ps1 b/streets.ps1
index af383a2..6934121 100644
--- a/streets.ps1
+++ b/streets.ps1
@@ -4,6 +4,47 @@ param (
$DataSource = './Gesamtergebnis-Gemeinderatswahl-2019_stripped.csv'
)
+function Get-OverpassStreet {
+ param (
+ [string]
+ $Name
+ )
+
+ if (!$cache.$Name) {
+ $query = @'
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+'@ -f $Name
+
+ $overpassSplat = @{
+ Method = 'Post'
+ Uri = 'https://overpass-api.de/api/interpreter'
+ Body = $query
+ }
+ $cache.$Name = Invoke-RestMethod @overpassSplat
+ }
+
+ $cache.$Name
+}
+
+if (Test-Path ./cache.xml) {
+ $cache = Import-Clixml ./cache.xml
+} else {
+ $cache = @{}
+}
+
$data = Import-Csv $DataSource
@@ -81,29 +122,7 @@ $featureList = Import-Csv ./polling_stations.csv
$description += "`n`n"
$description += $electionResultString
- $query = @'
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-'@ -f $street
-
- $overpassSplat = @{
- Method = 'Post'
- Uri = 'https://overpass-api.de/api/interpreter'
- Body = $query
- }
- $overpassResult = Invoke-RestMethod @overpassSplat
+ $overpassResult = Get-OverpassStreet -Name $street
if (!$overpassResult.osm.way.nd) {
Write-Error ('way "{0}" for polling station "{1}" probably not found' -f $street,$pollingStation.name)
@@ -141,3 +160,5 @@ $output = [PSCustomObject]@{
}
$output | ConvertTo-Json -Depth 99 | Out-File output.geojson
+
+$cache | Export-Clixml ./cache.xml