From 5e7596e6e77b0c5b21108d01855adedd8d5bd56f Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Sat, 9 Apr 2022 23:21:35 -0400 Subject: [PATCH] tweak: Clean infer description + cosmetic changes --- src/backend/platforms/infer.ts | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/backend/platforms/infer.ts b/src/backend/platforms/infer.ts index 5b9485a..0235070 100644 --- a/src/backend/platforms/infer.ts +++ b/src/backend/platforms/infer.ts @@ -20,6 +20,12 @@ const SLEEP_TIME_EXTRA = 2000; /* Support functions */ +function cleanDescription(text) { + let md = toMarkdown(text); + let result = md.replaceAll("---", "-").replaceAll(" ", " "); + return result; +} + async function fetchPage(page, cookie) { console.log(`Page #${page}`); if (page == 1) { @@ -68,7 +74,7 @@ async function fetchStats(questionUrl, cookie) { }); let firstEmbeddedJson = embeddedJsons[0]; let title = firstEmbeddedJson.question.name; - let description = firstEmbeddedJson.question.description; + let description = cleanDescription(firstEmbeddedJson.question.description); let comments_count = firstEmbeddedJson.question.comments_count; let numforecasters = firstEmbeddedJson.question.predictors_count; let numforecasts = firstEmbeddedJson.question.prediction_sets_count; @@ -120,17 +126,17 @@ function isSignedIn(html) { if (!isSignedInBool) { console.log("Error: Not signed in."); } - console.log(`Signed in? ${isSignedInBool}`); + console.log(`Signed in? ${isSignedInBool ? "yes" : "no"}`); return isSignedInBool; } -function isEnd(html) { - let isEndBool = html.includes("No questions match your filter"); - if (isEndBool) { +function reachedEnd(html) { + let reachedEndBool = html.includes("No questions match your filter"); + if (reachedEndBool) { //console.log(html) } - console.log(`IsEnd? ${isEndBool}`); - return isEndBool; + console.log(`Reached end? ${reachedEndBool ? "yes" : "no"}`); + return reachedEndBool; } function sleep(ms) { @@ -146,7 +152,7 @@ async function infer_inner(cookie: string) { await measureTime(async () => { // console.log("Downloading... This might take a couple of minutes. Results will be shown.") - while (!isEnd(response) && isSignedIn(response)) { + while (!reachedEnd(response) && isSignedIn(response)) { let htmlLines = response.split("\n"); // let h4elements = htmlLines.filter(str => str.includes("