Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: result again but date #551

Merged
merged 3 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note test

Unused import scrapeHtmlBaignadesSitePage.

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
Loading