UNPKG

@golemio/energetics

Version:
33 lines (27 loc) 1.05 kB
import * as fs from "fs"; // seznam adres, co adresa to nový řádek const rawInput = fs.readFileSync("addresses.txt").toString("utf-8"); const addresses = rawInput.split("\r\n"); // výstup v csv adresa;longitude;latitude const outputFile = "addressesOutput.txt"; const endpointCheck = "https://photon-test.ipt.oict.cz/api/?q="; const apiKey = "TOKEN_HERE"; (async () => { for (let index = 0; index < addresses.length; index++) { const element = addresses[index]; const result = await fetch(endpointCheck + element, { headers: { "x-access-token": apiKey, }, }); const data = await result.json(); if (data.features.length > 0) { const coordinates = data.features[0].geometry.coordinates; const output = `"${element}";"${coordinates[0]}";"${coordinates[1]}"\r\n`; fs.appendFileSync(outputFile, output); } else { // seznam nenalezených adres console.log(`${element}`); } } })();