-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
702088b
commit a74109c
Showing
4 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,3 +26,5 @@ node_modules | |
|
||
# Users Environment Variables | ||
.lock-wscript | ||
|
||
codes-postaux.json |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
var _ = require('lodash'); | ||
var data = require('./codes-postaux.json'); | ||
var index = _.groupBy(data, 'codePostal'); | ||
|
||
exports.listByCodePostal = function(codePostal) { | ||
var key = codePostal.toString(); | ||
return (key in index) ? index[key] : []; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
var request = require('request'); | ||
var parse = require('csv-parse'); | ||
var JSONStream = require('JSONStream'); | ||
var fs = require('fs'); | ||
|
||
var sourceFile = 'https://www.data.gouv.fr/s/resources/base-officielle-des-codes-postaux/20141106-120608/code_postaux_v201410.csv'; | ||
|
||
// Override first line | ||
var columns = function() { | ||
return ['codeInsee', 'nomCommune', 'codePostal', 'libelleAcheminement']; | ||
}; | ||
|
||
// Request source file | ||
request(sourceFile) | ||
// Parse CSV as Object | ||
.pipe(parse({ delimiter: ';', trim: true, columns: columns })) | ||
// Turn into JSON Array String | ||
.pipe(JSONStream.stringify()) | ||
// Output | ||
.pipe(fs.createWriteStream(__dirname + '/codes-postaux.json')); |
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