Last active
July 20, 2023 14:18
-
-
Save pdaug/fe57941b8357f98b13ba6476b19bd7ba to your computer and use it in GitHub Desktop.
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
import axios from "axios"; | |
import POSITIONMOCK from "./POSITIONMOCK.js"; | |
// ECONNREFUSED - SERVICO DESLIGADO (CONEXAO RECUSADA) | |
// ERR_NETWORK - ERRO NA CONEXAO | |
// ECONNRESET - SERVICO CONEXAO RESETADA | |
// SSL ALERT NUMBER 40 - CLOUDFLARE BLOQUEIO | |
// ETIMEDOUT - CONEXAO PERDIDA POR TEMPO | |
const RequestAddressMultiple = async function() { | |
let counterIndicator = 0; | |
let counterAddress = 1; | |
let counterSlice = 500; | |
let counterAddressesFounded = 0; | |
let counterErrors = 0; | |
let counterLooping = Math.ceil(POSITIONMOCK.length / counterSlice); | |
for (let counter = 0; counter < counterLooping; counter++) { | |
const partial = POSITIONMOCK.slice(counterIndicator, counterIndicator + counterSlice); | |
const packageRequest = partial.map(function(history) { | |
const url = "http://00.00.000.000/street/near/geojson"; | |
const method = "GET"; | |
const params = { | |
lat: history.position[0], | |
lon: history.position[1], | |
dist: 0.0002, | |
}; | |
const request = axios({ url, method, params, timeout: 999999 }); | |
return request; | |
}); | |
try { | |
const responses = await axios.all(packageRequest); | |
for (let response of responses) { | |
const body = response.data; | |
const features = body.features; | |
if (features && features.length > 0) { | |
const properties = features[0].properties; | |
const address = properties.name; | |
console.log(`[Indice: ${ counterAddress } de ${ POSITIONMOCK.length } - Batida: ${ counter + 1 } de ${ counterLooping }] - `, address); | |
counterAddressesFounded += 1; | |
} | |
else { | |
console.warn(`[Indice: ${ counterAddress } de ${ POSITIONMOCK.length } - Batida: ${ counter + 1 } de ${ counterLooping }] - `, "Endereço não localizado"); | |
counterErrors += 1; | |
} | |
counterAddress += 1; | |
} | |
} | |
catch(error) { | |
console.error(error); | |
} | |
counterIndicator += counterSlice; | |
} | |
console.log("Quantidade de pacotes em requisição por ciclo: ", counterSlice); | |
console.log("Endereços encontrados: ", counterAddressesFounded, " - Endereços não encontrados: ", counterErrors); | |
}; | |
RequestAddressMultiple(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment