@ifvictr/

Votesmart Dataset Parser

Nodejs

No description

fork
loading
Files
  • index.js
  • data.json
  • package-lock.json
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const axios = require('axios')
const fs = require('fs')
axios('https://raw.githubusercontent.com/votesmart/political-id-match/master/id_matrix.csv').then(({ data }) => {
    const keys = [
        'votesmart_candidate_id',
        'crp_id',
        'fec_id',
        'nimsp_candidate_id',
        'nimsp_entity_id',
        'first_name',
        'nickname',
        'middle_name',
        'last_name',
        'suffix',
        'office_state_id',
        'election_state_id'
    ]
    const candidates = data.split('\n')
    const mappedData = candidates.map(candidate =>
        candidate
            .split(',')
            .reduce((acc, value, index) => ({
                ...acc,
                [keys[index]]: value
            }), {})
    )
    fs.writeFile('./data.json', JSON.stringify(mappedData), err => {
        if (!err) {
            console.log('done!')
        }
    })
    console.log(mappedData[0])
})
node v10.16.0