Skip to content

Commit

Permalink
Merge branch 'master' of github.com:SocialGouv/recosante
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudambro committed Jul 29, 2024
2 parents dfcde4d + 98fe855 commit 30080a9
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)


Expand Down
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 @@ -117,6 +117,7 @@ export async function getBathingWaterIndicator() {
continue;
}
insertedNewRows++;

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

await prisma.bathingWater
.create({
data: {
Expand All @@ -165,7 +167,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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 30080a9

Please sign in to comment.