diff --git a/api-node/src/aggregators/bathing_water.ts b/api-node/src/aggregators/bathing_water.ts index 10c57bd8..1a929f8e 100644 --- a/api-node/src/aggregators/bathing_water.ts +++ b/api-node/src/aggregators/bathing_water.ts @@ -41,7 +41,6 @@ export async function getBathingWaterIndicator() { const municipalities = await prisma.municipality.findMany({ where: { bathing_water_sites: { gt: 0 }, - COM: String(76637), }, orderBy: { DEP: 'desc', @@ -117,6 +116,7 @@ export async function getBathingWaterIndicator() { continue; } insertedNewRows++; + await prisma.bathingWater.create({ data: { diffusion_date: dayjs().utc().toDate(), @@ -147,6 +147,7 @@ export async function getBathingWaterIndicator() { if (existingResults > 0) { continue; } + await prisma.bathingWater .create({ data: { @@ -165,7 +166,7 @@ export async function getBathingWaterIndicator() { id_carte: idCarte, isite: site.isite, name: site.nom, - result_date: dayjs(scrapingResult.result_date).toISOString(), + result_date: dayjs(scrapingResult.result_date).toDate(), result_value: scrapingResult.result_value, swimming_season_start: scrapingResult.swimming_season_start, swimming_season_end: scrapingResult.swimming_season_end, diff --git a/api-node/src/scripts/test-scrap-bathing-water.js b/api-node/src/scripts/test-scrap-bathing-water.js new file mode 100644 index 00000000..37f23835 --- /dev/null +++ b/api-node/src/scripts/test-scrap-bathing-water.js @@ -0,0 +1,10 @@ +import { getBathingWaterIndicator } from '~/aggregators/bathing_water'; +import { scrapeHtmlBaignadesSitePage } from '~/utils/bathing_water/scrapping'; + +const url = + 'https://baignades.sante.gouv.fr/baignades/consultSite.do?dptddass=076&site=076002097&annee=2024'; + +(async () => { + const result = await getBathingWaterIndicator(url); + console.log(result); +})(); diff --git a/api-node/src/utils/bathing_water/scrapping.ts b/api-node/src/utils/bathing_water/scrapping.ts index 4ea2a196..9c41f8da 100644 --- a/api-node/src/utils/bathing_water/scrapping.ts +++ b/api-node/src/utils/bathing_water/scrapping.ts @@ -5,8 +5,13 @@ import { } from '@prisma/client'; import { type ScrapingResult } from '~/types/api/bathing_water'; import * as cheerio from 'cheerio'; -import dayjs from 'dayjs'; import { capture } from '~/third-parties/sentry'; +import dayjs from 'dayjs'; +import customParseFormat from 'dayjs/plugin/customParseFormat'; +import utc from 'dayjs/plugin/utc'; + +dayjs.extend(customParseFormat); +dayjs.extend(utc); const fetch = fetchRetry(global.fetch); // Regular expression to match the date in dd/mm/yyyy format @@ -129,6 +134,7 @@ export async function scrapeHtmlBaignadesSitePage( return BathingWaterResultEnum.GOOD; } } + return { result_date: dayjs(date, 'DD/MM/YYYY').format('YYYY-MM-DD'), result_value: transformLabelToEnum(label),