Last active
August 2, 2019 01:22
-
-
Save 0xCourtney/495ef8e4ffdf17b5636c0555ba3ad14a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const spawnedProcess = spawn('python3', ['./python/pdfConverter.py']) | |
spawnedProcess.stderr | |
.on('data', (data) => { | |
console.log(`error:${data}`); | |
res.sendStatus(500) | |
}) | |
.on('close', () => { | |
try { | |
createInterface({ | |
input: createReadStream('./python/voterfiles/canvass.csv', 'utf8'), | |
crlfDelay: Infinity | |
}) | |
.on('line', (line) => { | |
var { turfs } = referenceJson | |
const parsedLine = line.split(','), | |
voter = { | |
'name': parsedLine[0], | |
'id': parsedLine[1], | |
'firstName': parsedLine[3].replace('\'', '').trimLeft(), | |
'lastName': parsedLine[2].replace('\'', ''), | |
'address': parsedLine[4], | |
'lat': null, | |
'lng': null | |
} | |
turfs.push(voter) | |
}) | |
.on('close', () => { | |
var { turfs } = referenceJson | |
const startTime = Date.now() | |
const promisedTurfs = turfs.map(turf => { | |
return convertAddressToCoordinates(turf.address) | |
.then(coordinates => { | |
turf.lat = coordinates[0].latitude | |
turf.lng = coordinates[0].longitude | |
return turf | |
}).catch(err => console.error(err)) | |
}) | |
Promise.all(promisedTurfs).then((updatedTurfs) => { | |
console.log(`w/ out Cluster / Elapsed Time: ${Date.now() - startTime}`) | |
res.sendStatus(200) | |
}) | |
}) | |
} catch (err) { | |
console.log(err) | |
res.sendStatus(500) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment