From 44b908302ef870e0804023dd35b9e7cacc58728e Mon Sep 17 00:00:00 2001 From: Arnaud Ambroselli <31724752+arnaudambro@users.noreply.github.com> Date: Mon, 29 Jul 2024 15:53:33 +0200 Subject: [PATCH 1/3] fix: result_date iso date (#550) --- api-node/src/aggregators/bathing_water.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api-node/src/aggregators/bathing_water.ts b/api-node/src/aggregators/bathing_water.ts index 75defe9d..c91404e8 100644 --- a/api-node/src/aggregators/bathing_water.ts +++ b/api-node/src/aggregators/bathing_water.ts @@ -164,7 +164,7 @@ export async function getBathingWaterIndicator() { id_carte: idCarte, isite: site.isite, name: site.nom, - result_date: scrapingResult.result_date, + result_date: dayjs(scrapingResult.result_date).toISOString(), result_value: scrapingResult.result_value, swimming_season_start: scrapingResult.swimming_season_start, swimming_season_end: scrapingResult.swimming_season_end, From 590f54e2ac08a559d2d690f000ff818a88f4169d Mon Sep 17 00:00:00 2001 From: Social Groovy Bot <45039513+SocialGroovyBot@users.noreply.github.com> Date: Mon, 29 Jul 2024 13:55:26 +0000 Subject: [PATCH 2/3] chore(release): 1.37.4 --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f30c1faf..53cee7d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [1.37.4](https://github.com/SocialGouv/recosante/compare/v1.37.3...v1.37.4) (2024-07-29) + + +### Bug Fixes + +* result_date iso date ([#550](https://github.com/SocialGouv/recosante/issues/550)) ([44b9083](https://github.com/SocialGouv/recosante/commit/44b908302ef870e0804023dd35b9e7cacc58728e)) + ## [1.37.3](https://github.com/SocialGouv/recosante/compare/v1.37.2...v1.37.3) (2024-07-29) diff --git a/package.json b/package.json index d9e0d8ad..a5dd50e1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "recosante", - "version": "1.37.3", + "version": "1.37.4", "license": "Apache-2.0", "private": true, "author": "Fabrique des ministères sociaux", From 98fe855b90936b2251b866a87cdc117ca6ec064c Mon Sep 17 00:00:00 2001 From: Arnaud Ambroselli <31724752+arnaudambro@users.noreply.github.com> Date: Mon, 29 Jul 2024 17:18:31 +0200 Subject: [PATCH 3/3] fix: result again but date (#551) --- api-node/src/aggregators/bathing_water.ts | 4 +++- api-node/src/scripts/test-scrap-bathing-water.js | 10 ++++++++++ api-node/src/utils/bathing_water/scrapping.ts | 8 +++++++- 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 api-node/src/scripts/test-scrap-bathing-water.js diff --git a/api-node/src/aggregators/bathing_water.ts b/api-node/src/aggregators/bathing_water.ts index c91404e8..1a929f8e 100644 --- a/api-node/src/aggregators/bathing_water.ts +++ b/api-node/src/aggregators/bathing_water.ts @@ -116,6 +116,7 @@ export async function getBathingWaterIndicator() { continue; } insertedNewRows++; + await prisma.bathingWater.create({ data: { diffusion_date: dayjs().utc().toDate(), @@ -146,6 +147,7 @@ export async function getBathingWaterIndicator() { if (existingResults > 0) { continue; } + await prisma.bathingWater .create({ data: { @@ -164,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),