2021-12-13 14:16:34 +00:00
|
|
|
// We publish our job offers on https://beta.gouv.fr/recrutement/. To augment
|
|
|
|
// their reach, we also publish a banner on our website automatically by using
|
|
|
|
// the beta.gouv.fr API.
|
2022-11-15 14:24:01 +00:00
|
|
|
import dotenv from 'dotenv'
|
2021-12-07 12:46:03 +00:00
|
|
|
import { promisify } from 'util'
|
2022-11-03 16:32:04 +00:00
|
|
|
import { parseString } from 'xml2js'
|
|
|
|
|
2021-12-07 12:46:03 +00:00
|
|
|
import { createDataDir, writeInDataDir } from './utils.js'
|
2021-12-13 14:16:34 +00:00
|
|
|
|
2022-11-15 14:24:01 +00:00
|
|
|
dotenv.config()
|
|
|
|
|
2021-12-07 12:46:03 +00:00
|
|
|
const parseXML = promisify(parseString)
|
2021-12-13 14:16:34 +00:00
|
|
|
|
|
|
|
main()
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
createDataDir()
|
|
|
|
const jobOffers = await fetchJobOffers()
|
|
|
|
writeInDataDir('job-offers.json', jobOffers)
|
|
|
|
}
|
|
|
|
|
|
|
|
async function fetchJobOffers() {
|
2022-03-29 12:58:40 +00:00
|
|
|
let jobOffers = []
|
|
|
|
|
|
|
|
try {
|
|
|
|
const response = await fetch('https://beta.gouv.fr/jobs.xml')
|
|
|
|
const content = await response.text()
|
|
|
|
|
|
|
|
// The XML API isn't the most ergonomic, we ought to have a JSON API.
|
|
|
|
// cf. https://github.com/betagouv/beta.gouv.fr/issues/6343
|
|
|
|
jobOffers = (await parseXML(content)).feed.entry
|
|
|
|
.map((entry) => ({
|
|
|
|
title: entry.title[0]['_'].trim(),
|
|
|
|
link: entry.link[0].$.href,
|
|
|
|
content: entry.content[0]['_'].trim(),
|
|
|
|
}))
|
|
|
|
.filter(({ title }) => title.includes('Offre de Mon-entreprise'))
|
|
|
|
.map(({ title, ...rest }) => ({
|
|
|
|
...rest,
|
|
|
|
title: title.replace(' - Offre de Mon-entreprise', ''),
|
|
|
|
}))
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
}
|
2021-12-13 14:16:34 +00:00
|
|
|
|
|
|
|
return jobOffers
|
|
|
|
}
|