feat: add contrib folder
This commit is contained in:
parent
159f9c2b45
commit
3230c0d0c8
3
contrib/README.md
Normal file
3
contrib/README.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
## User contributions
|
||||
|
||||
This folder contains utilities and snippets contributed by users. We welcome contributions.
|
91
contrib/download-all.mjs
Normal file
91
contrib/download-all.mjs
Normal file
|
@ -0,0 +1,91 @@
|
|||
/* Imports */
|
||||
import fs from "fs";
|
||||
import axios from "axios";
|
||||
|
||||
/* Definitions */
|
||||
const VERBOSE = true;
|
||||
let print = (message) => (VERBOSE ? console.log(message) : null);
|
||||
let graphQLendpoint = "https://metaforecast.org/api/graphql";
|
||||
let buildQuery = (endCursor) => `{
|
||||
questions(first: 1000 ${!!endCursor ? `after: "${endCursor}"` : ""}) {
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
title
|
||||
url
|
||||
description
|
||||
options {
|
||||
name
|
||||
probability
|
||||
}
|
||||
qualityIndicators {
|
||||
numForecasts
|
||||
stars
|
||||
}
|
||||
timestamp
|
||||
}
|
||||
}
|
||||
pageInfo {
|
||||
endCursor
|
||||
startCursor
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
/* Support functions */
|
||||
let getSomeMetaforecastPredictions = async (query) => {
|
||||
let response = await axios({
|
||||
url: graphQLendpoint,
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
data: JSON.stringify({ query: query }),
|
||||
})
|
||||
.then((res) => res.data)
|
||||
.then((res) => res.data); // not a typo
|
||||
return response;
|
||||
};
|
||||
|
||||
let save = (questions) => {
|
||||
fs.writeFileSync("forecasts.json", JSON.stringify(questions, null, 4));
|
||||
let tsvHeaders = "title\tplatform\tdate\tforecast\n";
|
||||
let tsvRows = questions
|
||||
.map(
|
||||
(question) =>
|
||||
`${question.title}\t${question.platform}\t${
|
||||
question.timestamp
|
||||
}\t${JSON.stringify(question.options)}`
|
||||
)
|
||||
.join("\n");
|
||||
let tsvFile = tsvHeaders + tsvRows;
|
||||
print("Saving results to results.tsv");
|
||||
fs.writeFileSync("forecasts.tsv", tsvFile);
|
||||
};
|
||||
|
||||
let getNodes = (questions) => {
|
||||
let edges = questions.edges;
|
||||
let nodes = edges.map((edge) => edge.node);
|
||||
return nodes;
|
||||
};
|
||||
// main
|
||||
let getAllMetaforecastPredictions = async () => {
|
||||
print("Fetching forecasts");
|
||||
let results = [];
|
||||
let firstQuery = await getSomeMetaforecastPredictions(buildQuery());
|
||||
results.push(...getNodes(firstQuery.questions));
|
||||
let endCursor = firstQuery.questions.pageInfo.endCursor;
|
||||
while (endCursor) {
|
||||
print("Cursor: " + endCursor);
|
||||
let queryResults = await getSomeMetaforecastPredictions(
|
||||
buildQuery(endCursor)
|
||||
);
|
||||
let nodes = getNodes(queryResults.questions);
|
||||
results.push(...nodes);
|
||||
endCursor = queryResults.questions.pageInfo.endCursor;
|
||||
}
|
||||
//results = results.map((result) => result.node);
|
||||
save(results);
|
||||
return results;
|
||||
};
|
||||
|
||||
getAllMetaforecastPredictions();
|
12
contrib/iframe-snippet.md
Normal file
12
contrib/iframe-snippet.md
Normal file
|
@ -0,0 +1,12 @@
|
|||
iframe snippet as used on [Global Guessing](https://globalguessing.com/russia-ukraine-forecasts/)
|
||||
|
||||
```html
|
||||
<iframe
|
||||
src="https://metaforecast.org/secretDashboard?dashboardId=561472e0d2&numCols=2"
|
||||
height="800"
|
||||
width="100%"
|
||||
frameborder="0"
|
||||
title="US Inflation"
|
||||
>
|
||||
</iframe>
|
||||
```
|
Loading…
Reference in New Issue
Block a user