diff --git a/build/download-fimoct.js b/build/download-fimoct.js index f67a3f6..cbcd922 100644 --- a/build/download-fimoct.js +++ b/build/download-fimoct.js @@ -34,8 +34,7 @@ async function getLatestFIMOCTArchiveURL() { return latestArchive.url } -async function getLatestFIMOCTFileBuffer() { - const url = await getLatestFIMOCTArchiveURL() +async function fetchAndExtractFIMOCT(url) { const response = await request.get(url) .buffer(true) .parse(request.parse['application/octet-stream']) @@ -47,4 +46,14 @@ async function getLatestFIMOCTFileBuffer() { return candidateFile.data } -module.exports = {getLatestFIMOCTFileBuffer} +async function getLatestFIMOCTFileBuffer() { + const url = await getLatestFIMOCTArchiveURL() + return fetchAndExtractFIMOCT(url) +} + +async function getCurrentFIMOCTFileBuffer() { + const url = 'https://www.data.gouv.fr/s/resources/fichiers-fimoca-et-fimoct-relatifs-aux-structures-de-la-dgfip/20171222-100050/FIMOCTT7Z00061.zip' + return fetchAndExtractFIMOCT(url) +} + +module.exports = {getLatestFIMOCTFileBuffer, getCurrentFIMOCTFileBuffer} diff --git a/build/index.js b/build/index.js index ab53575..26e57f8 100644 --- a/build/index.js +++ b/build/index.js @@ -3,7 +3,7 @@ const fs = require('fs') const {join} = require('path') const {promisify} = require('util') const {chain, pick} = require('lodash') -const {getLatestFIMOCTFileBuffer} = require('./download-fimoct') +const {getCurrentFIMOCTFileBuffer} = require('./download-fimoct') const {extractFromFIMOCT} = require('./extract-fimoct') const {getIndexedCommunes} = require('./cog') @@ -35,7 +35,7 @@ function buildCompact(codesPostaux) { } async function doStuff() { - const buffer = await getLatestFIMOCTFileBuffer() + const buffer = await getCurrentFIMOCTFileBuffer() const codesPostaux = await extractFromFIMOCT(buffer) const communes = await getIndexedCommunes() codesPostaux.forEach(e => expandWithCommune(e, communes))