Skip to content

Instantly share code, notes, and snippets.

@0xCourtney
Last active August 2, 2019 01:51
Show Gist options
  • Save 0xCourtney/8aca783873c14b6ce6394ac7eabc673c to your computer and use it in GitHub Desktop.
Save 0xCourtney/8aca783873c14b6ce6394ac7eabc673c to your computer and use it in GitHub Desktop.
const spawnedProcess = spawn('python3', ['./python/pdfConverter.py'])
var referenceJson = { turfs: [] }
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) => {
let { 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', () => {
let promisedTurfs = []
const { turfs } = referenceJson,
division = Math.ceil(turfs.length / numCPUs)
while (turfs.length > 0) {
promisedTurfs.push(
axios({
method: 'post',
url: 'http://localhost:3002/api/multiThread',
data: { turfs: turfs.splice(0, division) }
})
);
}
Promise.all(promisedTurfs).then((results) => {
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