Created
June 28, 2017 03:27
-
-
Save sprice/62464049507d2690c0ffcaa7ed1333f6 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
foo | V5Y0A5 | |
---|---|---|
bar | L5G4L3 |
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
const fs = require('fs') | |
const parse = require('csv-parse') | |
const represent = require('represent') | |
const parser = parse({delimiter: ','}, (err, data) => { | |
data.forEach(item => { | |
const code = item[1] | |
represent.postalCode(code, (err, data) => { | |
const MP = data.representatives_centroid.filter(rep => rep.elected_office === 'MP')[0] | |
console.log(`The MP for the postal code ${code} is ${MP.first_name} ${MP.last_name}`) | |
}) | |
}) | |
}) | |
fs.createReadStream(__dirname+'/codes.csv').pipe(parser) |
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
{ | |
"name": "represent-demo", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "Shawn Price", | |
"license": "MIT", | |
"dependencies": { | |
"csv-parse": "^1.2.0", | |
"represent": "^0.2.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ok, this almost worked.. Well, it did work, but ran into a bunch of data glitches I could fix and some coding issues I couldn't.
The biggest problem is that I'd put in 25 names & postal codes and I'd get back 25 MP names (in a different order). The whole point of the exercise was to be able to avoid cutting & pasting from http://represent.opennorth.ca/demo/ - because they were returned in a random order I ended up doing just as much cutting & pasting.
I ran into some interesting errors I wasn't expecting. These could be overcome in code, but mostly it is stuff that should at least be documented as the error reports aren't very clear.
I'll want to do this in the future, so just trying to document this further.