feat: metaculus fetcher takes markdown description from js vars

This commit is contained in:
Vyacheslav Matyukhin 2022-05-19 13:55:56 +04:00
parent 4d736f711d
commit d684d074f5
No known key found for this signature in database
GPG Key ID: 3D2A774C5489F96C

View File

@ -4,7 +4,6 @@ import axios from "axios";
import { average } from "../../utils"; import { average } from "../../utils";
import { sleep } from "../utils/sleep"; import { sleep } from "../utils/sleep";
import toMarkdown from "../utils/toMarkdown";
import { FetchedQuestion, Platform } from "./"; import { FetchedQuestion, Platform } from "./";
/* Definitions */ /* Definitions */
@ -134,11 +133,13 @@ async function fetchQuestionPage(slug: string) {
let description: string = ""; let description: string = "";
if (!isPublicFigurePrediction) { if (!isPublicFigurePrediction) {
const descriptionraw = questionPage.split( const match = questionPage.match(
`<div class="content" ng-bind-html-compile="qctrl.question.description_html">` /\s*window\.metacData\.question = (.+);\s*/
)[1]; );
const descriptionprocessed1 = descriptionraw.split("</div>")[0]; if (!match) {
description = toMarkdown(descriptionprocessed1); throw new Error("metacData not found");
}
description = JSON.parse(match[1]).description;
} }
return { return {