Skip to content

Commit

Permalink
Switch to previous FIMOCT
Browse files Browse the repository at this point in the history
  • Loading branch information
jdesboeufs committed Mar 6, 2018
1 parent 8ca66df commit 03fc247
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
15 changes: 12 additions & 3 deletions build/download-fimoct.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand All @@ -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}
4 changes: 2 additions & 2 deletions build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 03fc247

Please sign in to comment.