w3wconverter
Advanced tools
Comparing version 2.0.0 to 2.1.0
{ | ||
"name": "w3wconverter", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Coverts postcodes to lat-long coordinates via Google Places API, then into What3Words addresses.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -19,2 +19,3 @@ # What3Words Converter | ||
config['fileToWrite'] = <filename without extension>; | ||
config['postcode'] = <supplied single postcode from JSON>; | ||
const w3wconverter = new W3WConverter(config); | ||
@@ -21,0 +22,0 @@ |
@@ -31,9 +31,14 @@ /**** W3WConverter turns a postcode into a set of lat-long coordinates via the Google Places API | ||
#fileToWrite = ''; | ||
#postcode = ''; | ||
constructor(config) { | ||
this.#fileToConvert = config['fileToConvert']; | ||
this.#fileToWrite = config['fileToWrite']; | ||
this.#fileToConvert = config['fileToConvert'] ? config['fileToConvert'] : ''; | ||
this.#fileToWrite = config['fileToWrite'] ? config['fileToWrite'] : ''; | ||
this.#postcode = config['postcode'] ? config['postcode'] : ''; | ||
} | ||
getPostcodes() { | ||
if(this.#postcode.length > 0) { | ||
return [{'postcode': this.#postcode}]; | ||
} | ||
return new ReadCsvFile(this.#fileToConvert).readFile(); | ||
@@ -80,9 +85,14 @@ }; | ||
const postcodes = await this.getPostcodes(); | ||
const numberOfRows = this.countRows(postcodes); | ||
const informationArr = []; | ||
informationArr['rows'] = numberOfRows; | ||
const response = this.webResponseV2(informationArr); | ||
let response = {}; | ||
if(postcodes.length > 1) { | ||
const numberOfRows = this.countRows(postcodes); | ||
const informationArr = []; | ||
informationArr['rows'] = numberOfRows; | ||
response = this.webResponseV2(informationArr); | ||
} | ||
console.log('postcodes:',postcodes); | ||
for(let i = 0; i < postcodes.length; i++) { | ||
for(let i = 0; i < postcodes.length; i++) { | ||
this.#latLong[i] = await this.getLatLongCoords(postcodes[i].postcode); | ||
console.log(this.#latLong[i]); | ||
} | ||
@@ -93,22 +103,27 @@ | ||
temp = await (await this.getW3WAddress(this.#latLong[i].lat,this.#latLong[i].lng)).data.words; | ||
console.log('temp:',temp); | ||
this.#words[i] = temp; | ||
} | ||
if(postcodes.length > 1) { | ||
this.#words.forEach((w,key) => { | ||
const lat = this.#latLong[key].lat; | ||
const lng = this.#latLong[key].lng; | ||
this.#words.forEach((w,key) => { | ||
const lat = this.#latLong[key].lat; | ||
const lng = this.#latLong[key].lng; | ||
this.#records.push({ | ||
address_number: `${postcodes[key].address_number}`, | ||
postcode: `${postcodes[key].postcode}`, | ||
coords: `${lat},${lng}`, | ||
w3w: `${w}` | ||
}); | ||
}) | ||
this.#records.push({ | ||
address_number: `${postcodes[key].address_number}`, | ||
postcode: `${postcodes[key].postcode}`, | ||
coords: `${lat},${lng}`, | ||
w3w: `${w}` | ||
}); | ||
}) | ||
this.writeNewCsvFile(); | ||
//return this.giveWebResponse(); | ||
this.writeNewCsvFile(); | ||
return response; | ||
} | ||
console.log(this.#words[0]); | ||
return { | ||
'w3waddress': this.#words[0] | ||
}; | ||
return response; | ||
@@ -115,0 +130,0 @@ } |
@@ -30,5 +30,5 @@ /**** W3WConverter turns a postcode into a set of lat-long coordinates via the Google Places API | ||
this.#resObject.push({ | ||
address_number: this.#records[key].address_number, | ||
//address_number: this.#records[key].address_number, | ||
postcode: this.#records[key].postcode, | ||
coords: this.#records[key].coords, | ||
//coords: this.#records[key].coords, | ||
w3w: this.#records[key].w3w | ||
@@ -35,0 +35,0 @@ }); |
49197
339
27