-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
automate the last manual part of the process
- Loading branch information
Showing
9 changed files
with
9,730 additions
and
9,531 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Request LINZ Export | ||
|
||
on: | ||
schedule: | ||
- cron: "6 16 * * 3" # at 04:06am on Wednesday NZST | ||
workflow_dispatch: | ||
|
||
jobs: | ||
changelog: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [20.x] | ||
|
||
steps: | ||
- name: ⏬ Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: 🔢 Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
|
||
- name: ⏬ Install | ||
run: | | ||
yarn | ||
- name: 0️⃣ Request data export from LDS | ||
run: | | ||
yarn 0 | ||
env: | ||
REACT_APP_LDS_KEY: ${{ secrets.REACT_APP_LDS_KEY }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
name: Weekly Sync | ||
|
||
on: | ||
schedule: | ||
- cron: "6 18 * * 3" | ||
# at 06:06am on Wednesday NZST. This is 2 hours | ||
# after we requested an export from LINZ. | ||
workflow_dispatch: | ||
|
||
jobs: | ||
changelog: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [20.x] | ||
|
||
steps: | ||
- name: ⏬ Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: 🔢 Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
|
||
- name: ⏬ Install | ||
run: | | ||
yarn | ||
- name: 0️⃣.5️⃣ Download LINZ Export | ||
run: | | ||
yarn 0.5 | ||
- name: 1️⃣ Download OSM Planet file | ||
run: | | ||
yarn 1 | ||
- name: 2️⃣ Preprocess LINZ and OSM data | ||
run: | | ||
yarn 2 | ||
- name: 3️⃣ Conflate LINZ and OSM data | ||
run: | | ||
yarn 3 | ||
- name: 4️⃣ Upload result to CDN | ||
run: | | ||
yarn 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { promises as fs } from "node:fs"; | ||
import { parse } from "node:path"; | ||
import Unzip from "adm-zip"; | ||
import { api } from "./util/api"; | ||
import { linzRawFile } from "./util"; | ||
import { LINZ_LAYER_NAME_SUBSTR } from "../src/util"; | ||
|
||
async function main() { | ||
const allExports = await api.listExports(); | ||
const recentExports = allExports | ||
.filter( | ||
(item) => | ||
item.created_at && | ||
item.state !== "gone" && | ||
item.state !== "cancelled" && | ||
item.name.includes(LINZ_LAYER_NAME_SUBSTR) | ||
) | ||
.sort((a, b) => +new Date(b.created_at!) - +new Date(a.created_at!)); | ||
|
||
const mostRecent = recentExports[0]; | ||
if (!mostRecent) { | ||
throw new Error("No recent exports found."); | ||
} | ||
|
||
console.log( | ||
`Most recent export is #${mostRecent.id}, created at ${mostRecent.created_at}` | ||
); | ||
|
||
if (!mostRecent.download_url) { | ||
throw new Error("Export has no download_url yet"); | ||
} | ||
|
||
console.log(`Downloading from ${mostRecent.download_url} …`); | ||
|
||
const tempFilePath = await api.downloadExport(mostRecent.download_url); | ||
console.log(`Saved to ${tempFilePath}`); | ||
|
||
const zip = new Unzip(tempFilePath); | ||
const zipEntries = zip.getEntries(); | ||
|
||
const csvFile = zipEntries.find((file) => file.entryName.endsWith(".csv")); | ||
|
||
if (!csvFile) { | ||
throw new Error("No csv file in zip"); | ||
} | ||
|
||
console.log(`Extracting ${csvFile.entryName}…`); | ||
|
||
zip.extractEntryTo( | ||
csvFile.entryName, | ||
parse(linzRawFile).dir, | ||
/* maintainEntryPath */ false, | ||
/* overwrite */ true, | ||
/* keepOriginalPermission */ undefined, | ||
parse(linzRawFile).base | ||
); | ||
|
||
console.log("Deleting temp file…"); | ||
await fs.rm(tempFilePath, { force: true }); | ||
|
||
console.log("Done!"); | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { LINZ_LAYER } from "../src/util"; | ||
import { api } from "./util/api"; | ||
|
||
async function main() { | ||
const response = await api.generateExport(LINZ_LAYER); | ||
console.log(`Requested export #${response.id}`); | ||
} | ||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { join } from "node:path"; | ||
import { config as dotenv } from "dotenv"; | ||
import { Koordinates } from "koordinates-api"; | ||
|
||
dotenv({ path: join(__dirname, "../../.env.local") }); | ||
|
||
export const api = new Koordinates({ | ||
host: "https://data.linz.govt.nz", | ||
apiKey: process.env.REACT_APP_LDS_KEY!, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export const LINZ_LAYER = 53382; | ||
export const LINZ_LAYER_NAME_SUBSTR = "roads-addressing"; |
Oops, something went wrong.