Skip to content

Commit

Permalink
Fichier qui créée l'annuaire des communes d'un département
Browse files Browse the repository at this point in the history
  • Loading branch information
laem committed Jan 18, 2025
1 parent 860f84e commit 0272dae
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ public/indoorequal/

# Sentry Config File
.env.sentry-build-plugin
public/communes*
20 changes: 20 additions & 0 deletions lib/annuaireScope.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import fs from 'fs'

const doFetch = async (departementCode = 35) => {
const request = await fetch(
`https://geo.api.gouv.fr/departements/${departementCode}/communes`
)
const json = await request.json()

const big = json.filter((commune) => commune.population > 10000)

const sorted = big.sort((b, a) => a.population - b.population)
console.log(sorted)
fs.writeFileSync(
'public/communes-' + departementCode + '.json',
JSON.stringify(sorted)
)
return sorted
}

doFetch()

0 comments on commit 0272dae

Please sign in to comment.