Skip to content

Commit

Permalink
fix: add local data until FEED_URL has been fixed (#365)
Browse files Browse the repository at this point in the history
  • Loading branch information
m-maillot committed Jan 25, 2022
1 parent 2328859 commit 76a7924
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/fetch-data/api.data.json

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions src/fetch-data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,30 @@ import got from "got";
import pLimit from "p-limit";
import path from "path";

import data from "./api.data.json";
import { scrapUrl } from "./scrapUrl";

const FEED_URL = "https://travail-emploi.gouv.fr/?page=oseo_json";

const limit = pLimit(10);

export async function fetchFeed(url) {
const response = await got.post(url, {
headers: {
"Content-Type": "application/json",
// See issue https://github.com/SocialGouv/cdtn-admin/issues/707
Cookie:
"atauthority=%7B%22name%22%3A%22atauthority%22%2C%22val%22%3A%7B%22authority_name%22%3A%22cnil%22%2C%22visitor_mode%22%3A%22exempt%22%7D%2C%22options%22%3A%7B%22end%22%3A%222023-01-14T08%3A34%3A09.636Z%22%2C%22path%22%3A%22%2F%22%7D%7D; TSPD_101=08eeb285a9ab28006ea1b33079132448a70a8eeb5c082316b043fdebcc52e6493d0e0785ddc6dbf1dfc2cef3ddc5b0b40827d62c5a0510000167604732602cb5904334b599d12d1a:08eeb285a9ab2800da071da76ed893ba52f7c19b60efdc66209516375a1c20487a7c303deb2d387889bedf6b67e35ad5088d839d27063000cdfeb3bf91d21d637bd0b7179fdf324de7cc500eef41a59e6a2dca60ea9e22c764e90a572c2ff28cf36a36c98def608f; BIGipServerpool-dicom-portail-dares2.cegedim.cloud-HTTP=!uEusk+oWgYdRv8kqJlLL3fNyljz02f1hkUzl16O5bs3qacwFr3MVUhQr3X8bWzdw/B6Zw7ZvKi+gYtU1LcZ96Dl07OA=",
},
http2: true,
retry: 3,
});
const { fiches: feed } = JSON.parse(response.body);
return feed;
}

export async function loadFeed() {
const { fiches: feed } = data;
return Promise.resolve(feed);
}

export async function scrap(urls) {
const inputs = urls.map(({ id, url }) => limit(() => scrapUrl(id, url)));
const results = await Promise.allSettled(inputs);
Expand Down Expand Up @@ -63,7 +68,9 @@ export async function scrap(urls) {

if (module === require.main) {
const t0 = Date.now();
fetchFeed(FEED_URL)
// cf issue https://github.com/SocialGouv/cdtn-admin/issues/707
// fetchFeed(FEED_URL)
loadFeed()
.then(scrap)
.then((fiches) => {
console.log(`done in ${Math.round((Date.now() - t0) / 1000)} sec`);
Expand Down

0 comments on commit 76a7924

Please sign in to comment.