1
0
Fork 0
mirror of https://github.com/betagouv/mon-entreprise synced 2025-02-09 01:45:03 +00:00
mon-entreprise/site/scripts/fetch-job-offers.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

47 lines
1.3 KiB
JavaScript
Raw Normal View History

// 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 15:24:01 +01:00
import dotenv from 'dotenv'
2021-12-07 13:46:03 +01:00
import { promisify } from 'util'
2022-11-03 17:32:04 +01:00
import { parseString } from 'xml2js'
2021-12-07 13:46:03 +01:00
import { createDataDir, writeInDataDir } from './utils.js'
2022-11-15 15:24:01 +01:00
dotenv.config()
2021-12-07 13:46:03 +01:00
const parseXML = promisify(parseString)
2022-11-24 16:29:50 +01:00
createDataDir()
const jobOffers = await fetchJobOffers()
writeInDataDir('job-offers.json', jobOffers)
async function fetchJobOffers() {
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
2022-11-24 19:19:02 +01:00
const xml = await parseXML(content)
jobOffers = xml.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) {
2022-11-24 19:19:02 +01:00
console.error('Beta.gouv.fr/jobs error : ')
console.error(err)
}
return jobOffers
}