Skip to content

Commit

Permalink
fix: result again but date (#551)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudambro authored Jul 29, 2024
1 parent 590f54e commit 98fe855
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
4 changes: 3 additions & 1 deletion api-node/src/aggregators/bathing_water.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export async function getBathingWaterIndicator() {
continue;
}
insertedNewRows++;

await prisma.bathingWater.create({
data: {
diffusion_date: dayjs().utc().toDate(),
Expand Down Expand Up @@ -146,6 +147,7 @@ export async function getBathingWaterIndicator() {
if (existingResults > 0) {
continue;
}

await prisma.bathingWater
.create({
data: {
Expand All @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions api-node/src/scripts/test-scrap-bathing-water.js
Original file line number Diff line number Diff line change
@@ -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);
})();
8 changes: 7 additions & 1 deletion api-node/src/utils/bathing_water/scrapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 98fe855

Please sign in to comment.