Skip to content

Instantly share code, notes, and snippets.

@ThomasG77
Last active March 11, 2017 07:28
Show Gist options
  • Select an option

  • Save ThomasG77/5c731eddbcb9b5fbbd73b91a36b5b6c7 to your computer and use it in GitHub Desktop.

Select an option

Save ThomasG77/5c731eddbcb9b5fbbd73b91a36b5b6c7 to your computer and use it in GitHub Desktop.
Test geocoding using Node with both current 0.5.x ad upcoming 1.0 addok versions
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
"ID";"ENSEIGNE";"NUMERO ET LIBELLE DE VOIE";"COMPLEMENT";"CODE POSTAL";"COMMUNE"
1;"Tabac";"le bourg";;"01400";"ABERGEMENT-CLEMENCIAT"
2;"Centre Commercial Dame Louise-tabac-";"42 rue roger vaillant";;"01500";"AMBERIEU-EN-BUGEY"
3;"Tabac De La Gare";"6 avenue du general sarrail";;"01500";"AMBERIEU-EN-BUGEY"
4;"Tabac";"14 rue berard";;"01500";"AMBERIEU-EN-BUGEY"
5;"Tabac";"12 avenue paul painleve";;"01500";"AMBERIEU-EN-BUGEY"
6;"La Roseraie";"18 rue de la ruelle";;"01330";"AMBERIEUX-EN-DOMBES"
7;"Tabac";"grande rue";;"01500";"AMBRONAY"
8;"Tabac";"19 rue de la mairie";;"01350";"ANGLEFORT"
9;"L'equateur";"69 rue general andrea";;"01100";"ARBENT"
{
"name": "node-geocoding-client",
"version": "1.0.0",
"description": "",
"main": "unirest-post-multipart.js",
"dependencies": {
"unirest": "^0.5.1"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
const unirest = require('unirest');
const geocoder_url_0_5x = 'http://api-adresse.data.gouv.fr/search/csv/';
const geocoder_url_1_0x = 'http://devapi-adresse.data.gouv.fr/search/csv/';
// Works OK
unirest.post(geocoder_url_0_5x)
.headers({'Content-Type': 'multipart/form-data'})
.field('columns', 'NUMERO ET LIBELLE DE VOIE') // Form field
.field('columns', 'COMMUNE')
.attach('data', './annuaire-des-debits-de-tabac-deb.csv') // Attachment
.end(function (response) {
console.log('v0.5', response.body);
});
// Return undefined
unirest.post(geocoder_url_1_0x)
.headers({'Content-Type': 'multipart/form-data'})
.field('columns', 'NUMERO ET LIBELLE DE VOIE') // Form field
.field('columns', 'COMMUNE')
.attach('data', './annuaire-des-debits-de-tabac-deb.csv') // Attachment
.end(function (response) {
console.log('v1.0', response.body);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment