tweak: Added some metaculus checking

But this doesn't work, because many questions
are being validated at once. Aarg.
This commit is contained in:
NunoSempere 2022-10-26 16:08:18 +01:00
parent a873cc4497
commit 002a0e5e2f

View File

@ -72,7 +72,14 @@ async function apiQuestionToFetchedQuestions(apiQuestion: ApiQuestion): Promise<
if (apiQuestion.type === "group") { if (apiQuestion.type === "group") {
await sleep(SLEEP_TIME); await sleep(SLEEP_TIME);
const apiQuestionDetails = await fetchSingleApiQuestion(apiQuestion.id); let apiQuestionDetailsTemp
try{
apiQuestionDetailsTemp = await fetchSingleApiQuestion(apiQuestion.id);
}catch(error){
console.log(error)
return []
}
const apiQuestionDetails = apiQuestionDetailsTemp
if (apiQuestionDetails.type !== "group") { if (apiQuestionDetails.type !== "group") {
console.log("Error: expected `group` type") console.log("Error: expected `group` type")
return [] //throw new Error("Expected `group` type"); // shouldn't happen, this is mostly for typescript return [] //throw new Error("Expected `group` type"); // shouldn't happen, this is mostly for typescript
@ -119,8 +126,8 @@ async function apiQuestionToFetchedQuestions(apiQuestion: ApiQuestion): Promise<
} }
await sleep(SLEEP_TIME); await sleep(SLEEP_TIME);
const apiQuestionDetails = await fetchSingleApiQuestion(apiQuestion.id);
try{ try{
const apiQuestionDetails = await fetchSingleApiQuestion(apiQuestion.id);
const tmp = buildFetchedQuestion(apiQuestion); const tmp = buildFetchedQuestion(apiQuestion);
return [{ return [{
... tmp, ... tmp,
@ -154,15 +161,21 @@ export const metaculus: Platform<"id" | "debug"> = {
let allQuestions: FetchedQuestion[] = []; let allQuestions: FetchedQuestion[] = [];
if (opts.args ?. id) { if (opts.args ?. id) {
console.log("Using optional id arg.") try{
const id = Number(opts.args.id); console.log("Using optional id arg.")
const apiQuestion = await fetchSingleApiQuestion(id); const id = Number(opts.args.id);
const questions = await apiQuestionToFetchedQuestions(apiQuestion); const apiQuestion = await fetchSingleApiQuestion(id);
console.log(questions); const questions = await apiQuestionToFetchedQuestions(apiQuestion);
return {questions, partial: true}; console.log(questions);
return {questions, partial: true};
}catch(error){
console.log(error)
return {questions: [], partial: true};
}
} }
let next: string |null = "https://www.metaculus.com/api2/questions/"; let next: string | null = "https://www.metaculus.com/api2/questions/";
let i = 1; let i = 1;
while (next) { while (next) {
console.log(`\nQuery #${i} - ${next}`); console.log(`\nQuery #${i} - ${next}`);