From d684d074f53bc66c26d41ede237f0d92473b5650 Mon Sep 17 00:00:00 2001 From: Vyacheslav Matyukhin Date: Thu, 19 May 2022 13:55:56 +0400 Subject: [PATCH] feat: metaculus fetcher takes markdown description from js vars --- src/backend/platforms/metaculus.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/backend/platforms/metaculus.ts b/src/backend/platforms/metaculus.ts index f1fef7a..d15d4e7 100644 --- a/src/backend/platforms/metaculus.ts +++ b/src/backend/platforms/metaculus.ts @@ -4,7 +4,6 @@ import axios from "axios"; import { average } from "../../utils"; import { sleep } from "../utils/sleep"; -import toMarkdown from "../utils/toMarkdown"; import { FetchedQuestion, Platform } from "./"; /* Definitions */ @@ -134,11 +133,13 @@ async function fetchQuestionPage(slug: string) { let description: string = ""; if (!isPublicFigurePrediction) { - const descriptionraw = questionPage.split( - `
` - )[1]; - const descriptionprocessed1 = descriptionraw.split("
")[0]; - description = toMarkdown(descriptionprocessed1); + const match = questionPage.match( + /\s*window\.metacData\.question = (.+);\s*/ + ); + if (!match) { + throw new Error("metacData not found"); + } + description = JSON.parse(match[1]).description; } return {