diff --git a/src/backend/database/database-wrapper.js b/src/backend/database/database-wrapper.ts similarity index 95% rename from src/backend/database/database-wrapper.js rename to src/backend/database/database-wrapper.ts index 2a5714c..c3a7b4c 100644 --- a/src/backend/database/database-wrapper.js +++ b/src/backend/database/database-wrapper.ts @@ -1,9 +1,5 @@ -import { - mongoRead, - mongoReadWithReadCredentials, - mongoUpsert, -} from "./mongo-wrapper"; -import { pgRead, pgReadWithReadCredentials, pgUpsert } from "./pg-wrapper"; +import { mongoRead, mongoReadWithReadCredentials, mongoUpsert } from './mongo-wrapper'; +import { pgRead, pgReadWithReadCredentials, pgUpsert } from './pg-wrapper'; export async function databaseUpsert({ contents, group }) { // No, this should be more rational, ({contents, group, schema})? Or should this be managed by this layer? Unclear. @@ -146,7 +142,7 @@ export async function databaseReadWithReadCredentials({ group }) { break; default: mongoDocName = `${group}-questions`; - responseMongo = mongoRemongoReadWithReadCredentialsad( + responseMongo = mongoReadWithReadCredentials( mongoDocName, "metaforecastCollection", "metaforecastDatabase" diff --git a/src/backend/database/mongo-wrapper.js b/src/backend/database/mongo-wrapper.ts similarity index 98% rename from src/backend/database/mongo-wrapper.js rename to src/backend/database/mongo-wrapper.ts index 02c38d8..f922407 100644 --- a/src/backend/database/mongo-wrapper.js +++ b/src/backend/database/mongo-wrapper.ts @@ -1,5 +1,7 @@ -import pkg from "mongodb"; -import { roughSizeOfObject } from "../utils/roughSize"; +import pkg from 'mongodb'; + +import { roughSizeOfObject } from '../utils/roughSize'; + const { MongoClient } = pkg; export async function mongoUpsert( diff --git a/src/backend/database/pg-wrapper.js b/src/backend/database/pg-wrapper.ts similarity index 98% rename from src/backend/database/pg-wrapper.js rename to src/backend/database/pg-wrapper.ts index 76c59ac..185da83 100644 --- a/src/backend/database/pg-wrapper.js +++ b/src/backend/database/pg-wrapper.ts @@ -1,7 +1,9 @@ -import pkg from "pg"; -import { platformNames } from "../platforms/all/platformNames"; -import { hash } from "../utils/hash"; -import { roughSizeOfObject } from "../utils/roughSize"; +import pkg from 'pg'; + +import { platformNames } from '../platforms/all/platformNames'; +import { hash } from '../utils/hash'; +import { roughSizeOfObject } from '../utils/roughSize'; + const { Pool } = pkg; // Definitions diff --git a/src/backend/flow/doEverything.js b/src/backend/flow/doEverything.ts similarity index 80% rename from src/backend/flow/doEverything.js rename to src/backend/flow/doEverything.ts index 81498c8..eabb4f1 100644 --- a/src/backend/flow/doEverything.js +++ b/src/backend/flow/doEverything.ts @@ -1,8 +1,9 @@ -import { platformFetchers } from "../platforms/all-platforms"; -import { rebuildAlgoliaDatabase } from "../utils/algolia"; -import { updateHistory } from "./history/updateHistory"; -import { mergeEverything } from "./mergeEverything"; -import { rebuildNetlifySiteWithNewData } from "./rebuildNetliftySiteWithNewData"; +import { platformFetchers } from '../platforms/all-platforms'; +import { rebuildAlgoliaDatabase } from '../utils/algolia'; +import { updateHistory } from './history/updateHistory'; +import { mergeEverything } from './mergeEverything'; +import { rebuildNetlifySiteWithNewData } from './rebuildNetliftySiteWithNewData'; + /* Do everything */ function sleep(ms) { return new Promise((resolve) => setTimeout(resolve, ms)); diff --git a/src/backend/flow/doEverythingForScheduler.js b/src/backend/flow/doEverythingForScheduler.js deleted file mode 100644 index 4b8e69f..0000000 --- a/src/backend/flow/doEverythingForScheduler.js +++ /dev/null @@ -1,3 +0,0 @@ -import { doEverything } from "./doEverything"; - -doEverything(); diff --git a/src/backend/flow/doEverythingForScheduler.ts b/src/backend/flow/doEverythingForScheduler.ts new file mode 100644 index 0000000..d2753d9 --- /dev/null +++ b/src/backend/flow/doEverythingForScheduler.ts @@ -0,0 +1,3 @@ +import { doEverything } from './doEverything'; + +doEverything(); diff --git a/src/backend/flow/history/old/addToHistory.js b/src/backend/flow/history/old/addToHistory.js deleted file mode 100644 index 3f4f880..0000000 --- a/src/backend/flow/history/old/addToHistory.js +++ /dev/null @@ -1,110 +0,0 @@ -import { - databaseReadWithReadCredentials, - databaseUpsert, -} from "../../database/database-wrapper"; -let isEmptyArray = (arr) => arr.length == 0; - -export async function addToHistory() { - let currentDate = new Date(); - let dateUpToMonth = currentDate.toISOString().slice(0, 7).replace("-", "_"); - - let currentJSONwithMetaculus = await databaseReadWithReadCredentials({ - group: "combined", - }); - let currentJSON = currentJSONwithMetaculus.filter( - (element) => - element.platform != "Metaculus" && element.platform != "Estimize" - ); // without Metaculus - // console.log(currentJSON.slice(0,20)) - // console.log(currentJSON) - let historyJSON = await databaseReadWithReadCredentials({ group: "history" }); - // console.log(historyJSON) - - let currentForecastsWithAHistory = currentJSON.filter( - (element) => - !isEmptyArray( - historyJSON.filter( - (historyElement) => - historyElement.title == element.title && - historyElement.url == element.url - ) - ) - ); - // console.log(currentForecastsWithAHistory) - - let currentForecastsWithoutAHistory = currentJSON.filter((element) => - isEmptyArray( - historyJSON.filter( - (historyElement) => - historyElement.title == element.title && - historyElement.url == element.url - ) - ) - ); - // console.log(currentForecastsWithoutAHistory) - - // Add both types of forecast - let newHistoryJSON = []; - for (let historyElement of historyJSON) { - let correspondingNewElementArray = currentForecastsWithAHistory.filter( - (element) => - historyElement.title == element.title && - historyElement.url == element.url - ); - // console.log(correspondingNewElement) - if (!isEmptyArray(correspondingNewElementArray)) { - let correspondingNewElement = correspondingNewElementArray[0]; - let timeStampOfNewElement = correspondingNewElement.timestamp; - let doesHistoryAlreadyContainElement = historyElement.history - .map((element) => element.timestamp) - .includes(timeStampOfNewElement); - if (!doesHistoryAlreadyContainElement) { - let historyWithNewElement = historyElement["history"].concat({ - timestamp: correspondingNewElement.timestamp, - options: correspondingNewElement.options, - qualityindicators: correspondingNewElement.qualityindicators, - }); - let newHistoryElement = { - ...correspondingNewElement, - history: historyWithNewElement, - }; - // If some element (like the description) changes, we keep the new one. - newHistoryJSON.push(newHistoryElement); - } else { - newHistoryJSON.push(historyElement); - } - } else { - // console.log(historyElement) - newHistoryJSON.push(historyElement); - } - } - - for (let currentForecast of currentForecastsWithoutAHistory) { - let newHistoryElement = { - ...currentForecast, - history: [ - { - timestamp: currentForecast.timestamp, - options: currentForecast.options, - qualityindicators: currentForecast.qualityindicators, - }, - ], - }; - delete newHistoryElement.timestamp; - delete newHistoryElement.options; - delete newHistoryElement.qualityindicators; - newHistoryJSON.push(newHistoryElement); - } - - await databaseUpsert({ contents: newHistoryJSON, group: "history" }); - - // console.log(newHistoryJSON.slice(0,5)) - // writeFileSync("metaforecast_history.json", JSON.stringify(newHistoryJSON, null, 2)) - // writefile(JSON.stringify(newHistoryJSON, null, 2), "metaforecasts_history", "", ".json") - //console.log(newHistoryJSON) - /* - let forecastsAlreadyInHistory = currentJSON.filter(element => !isEmptyArray(historyJSON.filter(historyElement => historyElement.title == element.title && historyElement.url == element.url ))) - */ - //console.log(new Date().toISOString()) -} -// updateHistory() diff --git a/src/backend/flow/history/old/createHistoryForMonth.js b/src/backend/flow/history/old/createHistoryForMonth.js deleted file mode 100644 index ba55000..0000000 --- a/src/backend/flow/history/old/createHistoryForMonth.js +++ /dev/null @@ -1,36 +0,0 @@ -import { databaseRead, databaseUpsert } from "../../database/database-wrapper"; - -export async function createHistoryForMonth() { - let currentDate = new Date(); - let dateUpToMonth = currentDate.toISOString().slice(0, 7).replace("-", "_"); - let metaforecasts = await databaseRead({ group: "combined" }); - let metaforecastsHistorySeed = metaforecasts - .map((element) => { - // let moreoriginsdata = element.author ? ({author: element.author}) : ({}) - return { - title: element.title, - url: element.url, - platform: element.platform, - moreoriginsdata: element.moreoriginsdata || {}, - description: element.description, - history: [ - { - timestamp: element.timestamp, - options: element.options, - qualityindicators: element.qualityindicators, - }, - ], - extra: element.extra || {}, - }; - }) - .filter( - (element) => - element.platform != "Metaculus" && element.platform != "Estimize" - ); - //console.log(metaforecastsHistorySeed) - await databaseUpsert({ - contents: metaforecastsHistorySeed, - group: "history", - }); -} -////createInitialHistory() diff --git a/src/backend/flow/history/old/createInitialHistoryWithMetaculus.js b/src/backend/flow/history/old/createInitialHistoryWithMetaculus.js deleted file mode 100644 index 9ed86aa..0000000 --- a/src/backend/flow/history/old/createInitialHistoryWithMetaculus.js +++ /dev/null @@ -1,29 +0,0 @@ -import { databaseRead, databaseUpsert } from "../database-wrapper"; - -let createInitialHistory = async () => { - let metaforecasts = await databaseRead({ group: "combined" }); - let metaforecastsHistorySeed = metaforecasts.map((element) => { - // let moreoriginsdata = element.author ? ({author: element.author}) : ({}) - return { - title: element.title, - url: element.url, - platform: element.platform, - moreoriginsdata: element.moreoriginsdata || {}, - description: element.description, - history: [ - { - timestamp: element.timestamp, - options: element.options, - qualityindicators: element.qualityindicators, - }, - ], - extra: element.extra || {}, - }; - }); - console.log(metaforecastsHistorySeed); - await databaseUpsert({ - contents: metaforecastsHistorySeed, - group: "history", - }); -}; -createInitialHistory(); diff --git a/src/backend/flow/history/old/updateHistory.js b/src/backend/flow/history/old/updateHistory.js deleted file mode 100644 index 6f67ce0..0000000 --- a/src/backend/flow/history/old/updateHistory.js +++ /dev/null @@ -1,21 +0,0 @@ -import { addToHistory } from "./addToHistory"; -import { createHistoryForMonth } from "./createHistoryForMonth"; - -export async function updateHistoryOld() { - let currentDate = new Date(); - let dayOfMonth = currentDate.getDate(); - if (dayOfMonth == 1) { - console.log( - `Creating history for the month ${currentDate.toISOString().slice(0, 7)}` - ); - await createHistoryForMonth(); - } else { - console.log(`Updating history for ${currentDate.toISOString()}`); - await addToHistory(); - } -} - -export async function updateHistory() { - let currentDate = new Date(); - let year = currentDate.toISOString().slice(0, 4); -} diff --git a/src/backend/flow/history/updateHistory.js b/src/backend/flow/history/updateHistory.ts similarity index 65% rename from src/backend/flow/history/updateHistory.js rename to src/backend/flow/history/updateHistory.ts index b4733dc..9caf1e0 100644 --- a/src/backend/flow/history/updateHistory.js +++ b/src/backend/flow/history/updateHistory.ts @@ -1,7 +1,4 @@ -import { - databaseReadWithReadCredentials, - databaseUpsert, -} from "../../database/database-wrapper"; +import { databaseReadWithReadCredentials, databaseUpsert } from '../../database/database-wrapper'; export async function updateHistory() { let latest = await databaseReadWithReadCredentials({ group: "combined" }); diff --git a/src/backend/flow/mergeEverything.js b/src/backend/flow/mergeEverything.ts similarity index 84% rename from src/backend/flow/mergeEverything.js rename to src/backend/flow/mergeEverything.ts index 300b5ac..4377bb3 100644 --- a/src/backend/flow/mergeEverything.js +++ b/src/backend/flow/mergeEverything.ts @@ -1,5 +1,6 @@ -import { databaseRead, databaseUpsert } from "../database/database-wrapper"; -import { platformNames } from "../platforms/all-platforms"; +import { databaseRead, databaseUpsert } from '../database/database-wrapper'; +import { platformNames } from '../platforms/all-platforms'; + /* Merge everything */ export async function mergeEverythingInner() { diff --git a/src/backend/flow/rebuildNetliftySiteWithNewData.js b/src/backend/flow/rebuildNetliftySiteWithNewData.ts similarity index 80% rename from src/backend/flow/rebuildNetliftySiteWithNewData.js rename to src/backend/flow/rebuildNetliftySiteWithNewData.ts index 5204ead..7d4fe71 100644 --- a/src/backend/flow/rebuildNetliftySiteWithNewData.js +++ b/src/backend/flow/rebuildNetliftySiteWithNewData.ts @@ -1,5 +1,6 @@ -import axios from "axios"; -import { applyIfSecretExists } from "../utils/getSecrets"; +import axios from 'axios'; + +import { applyIfSecretExists } from '../utils/getSecrets'; async function rebuildNetlifySiteWithNewData_inner(cookie) { let payload = {}; diff --git a/src/backend/manual/manualDownload.js b/src/backend/manual/manualDownload.ts similarity index 69% rename from src/backend/manual/manualDownload.js rename to src/backend/manual/manualDownload.ts index c5eb4ea..f229616 100644 --- a/src/backend/manual/manualDownload.js +++ b/src/backend/manual/manualDownload.ts @@ -1,6 +1,8 @@ -import "dotenv/config"; -import fs from "fs"; -import { databaseReadWithReadCredentials } from "../database/database-wrapper"; +import 'dotenv/config'; + +import fs from 'fs'; + +import { databaseReadWithReadCredentials } from '../database/database-wrapper'; let main = async () => { let json = await databaseReadWithReadCredentials({ group: "combined" }); diff --git a/src/backend/manual/manualInitialize.js b/src/backend/manual/manualInitialize.js deleted file mode 100644 index 1427013..0000000 --- a/src/backend/manual/manualInitialize.js +++ /dev/null @@ -1,3 +0,0 @@ -import { pgInitialize } from "../database/pg-wrapper"; - -pgInitialize(); diff --git a/src/backend/manual/manualInitialize.ts b/src/backend/manual/manualInitialize.ts new file mode 100644 index 0000000..cdb1d09 --- /dev/null +++ b/src/backend/manual/manualInitialize.ts @@ -0,0 +1,3 @@ +import { pgInitialize } from '../database/pg-wrapper'; + +pgInitialize(); diff --git a/src/backend/manual/manualSendToMongo.js b/src/backend/manual/manualSendToMongo.ts similarity index 83% rename from src/backend/manual/manualSendToMongo.js rename to src/backend/manual/manualSendToMongo.ts index 2aea360..19ddcfd 100644 --- a/src/backend/manual/manualSendToMongo.js +++ b/src/backend/manual/manualSendToMongo.ts @@ -1,5 +1,6 @@ -import fs from "fs"; -import { databaseUpsert } from "../database/database-wrapper"; +import fs from 'fs'; + +import { databaseUpsert } from '../database/database-wrapper'; /* This is necessary for estimize, the database of x-risk estimates, and for the OpenPhil/GiveWell predictions. Unlike the others, I'm not fetching them constantly, but only once. */ @@ -9,7 +10,9 @@ let suffixMongo = "-questions"; let main = async () => { for (let file of pushManualFiles) { - let fileRaw = fs.readFileSync(`./input/${file + suffixFiles}`); + let fileRaw = fs.readFileSync(`./input/${file + suffixFiles}`, { + encoding: "utf-8", + }); let fileContents = JSON.parse(fileRaw); console.log(fileContents); await databaseUpsert({ contents: fileContents, group: file }); diff --git a/src/backend/manual/pullSuperforecastsManually.js b/src/backend/manual/pullSuperforecastsManually.ts similarity index 61% rename from src/backend/manual/pullSuperforecastsManually.js rename to src/backend/manual/pullSuperforecastsManually.ts index 1a4829a..8f64ca3 100644 --- a/src/backend/manual/pullSuperforecastsManually.js +++ b/src/backend/manual/pullSuperforecastsManually.ts @@ -1,5 +1,5 @@ /* Imports */ -import { goodjudgment } from "../platforms/goodjudgment-fetch"; +import { goodjudgment } from '../platforms/goodjudgment-fetch'; /* Definitions */ diff --git a/src/backend/platforms/all-platforms.js b/src/backend/platforms/all-platforms.ts similarity index 100% rename from src/backend/platforms/all-platforms.js rename to src/backend/platforms/all-platforms.ts diff --git a/src/backend/platforms/all/platformFetchers.js b/src/backend/platforms/all/platformFetchers.ts similarity index 50% rename from src/backend/platforms/all/platformFetchers.js rename to src/backend/platforms/all/platformFetchers.ts index 04c1ce5..5bf174f 100644 --- a/src/backend/platforms/all/platformFetchers.js +++ b/src/backend/platforms/all/platformFetchers.ts @@ -1,17 +1,17 @@ -import { betfair } from "../betfair-fetch"; -import { fantasyscotus } from "../fantasyscotus-fetch"; -import { foretold } from "../foretold-fetch"; -import { goodjudgment } from "../goodjudgment-fetch"; -import { goodjudgmentopen } from "../goodjudmentopen-fetch"; -import { infer } from "../infer-fetch"; -import { kalshi } from "../kalshi-fetch"; -import { manifoldmarkets } from "../manifoldmarkets-fetch"; -import { metaculus } from "../metaculus-fetch"; -import { polymarket } from "../polymarket-fetch"; -import { predictit } from "../predictit-fetch"; -import { rootclaim } from "../rootclaim-fetch"; -import { smarkets } from "../smarkets-fetch"; -import { wildeford } from "../wildeford-fetch"; +import { betfair } from '../betfair-fetch'; +import { fantasyscotus } from '../fantasyscotus-fetch'; +import { foretold } from '../foretold-fetch'; +import { goodjudgment } from '../goodjudgment-fetch'; +import { goodjudgmentopen } from '../goodjudmentopen-fetch'; +import { infer } from '../infer-fetch'; +import { kalshi } from '../kalshi-fetch'; +import { manifoldmarkets } from '../manifoldmarkets-fetch'; +import { metaculus } from '../metaculus-fetch'; +import { polymarket } from '../polymarket-fetch'; +import { predictit } from '../predictit-fetch'; +import { rootclaim } from '../rootclaim-fetch'; +import { smarkets } from '../smarkets-fetch'; +import { wildeford } from '../wildeford-fetch'; /* Deprecated import { astralcodexten } from "../platforms/astralcodexten-fetch" diff --git a/src/backend/platforms/all/platformNames.js b/src/backend/platforms/all/platformNames.ts similarity index 100% rename from src/backend/platforms/all/platformNames.js rename to src/backend/platforms/all/platformNames.ts diff --git a/src/backend/platforms/betfair-fetch.js b/src/backend/platforms/betfair-fetch.ts similarity index 100% rename from src/backend/platforms/betfair-fetch.js rename to src/backend/platforms/betfair-fetch.ts diff --git a/src/backend/platforms/deprecated/astralcodexten-fetch.js b/src/backend/platforms/deprecated/astralcodexten-fetch.js deleted file mode 100644 index 5615238..0000000 --- a/src/backend/platforms/deprecated/astralcodexten-fetch.js +++ /dev/null @@ -1,97 +0,0 @@ -/* Imports */ -import axios from "axios"; -import { databaseUpsert } from "../utils/database-wrapper"; -import { calculateStars } from "../utils/stars"; - -/* Definitions */ -let graphQLendpoint = "https://api.foretold.io/graphql"; -let ScottAlexanderPredictions = ["6eebf79b-4b6f-487b-a6a5-748d82524637"]; - -/* Support functions */ -async function fetchAllCommunityQuestions(communityId) { - let response = await axios({ - url: graphQLendpoint, - method: "POST", - headers: { "Content-Type": "application/json" }, - data: JSON.stringify({ - query: ` - query { - measurables( - channelId: "${communityId}", - states: OPEN, - first: 500 - ){ - total - edges{ - node{ - id - name - valueType - measurementCount - previousAggregate{ - value{ - percentage - } - } - } - } - } - } - `, - }), - }) - .then((res) => res.data) - .then((res) => res.data.measurables.edges); - //console.log(response) - return response; -} - -/* Body */ - -export async function astralcodexten() { - let results = []; - for (let community of ScottAlexanderPredictions) { - let questions = await fetchAllCommunityQuestions(community); - questions = questions.map((question) => question.node); - questions = questions.filter((question) => question.previousAggregate); // Questions without any predictions - questions.forEach((question) => { - let options = []; - if (question.valueType == "PERCENTAGE") { - let probability = question.previousAggregate.value.percentage; - options = [ - { - name: "Yes", - probability: probability / 100, - type: "PROBABILITY", - }, - { - name: "No", - probability: 1 - probability / 100, - type: "PROBABILITY", - }, - ]; - } - let result = { - title: question.name.split(". ")[1], - url: `https://www.foretold.io/c/${community}/m/${question.id}`, - platform: "AstralCodexTen", - description: "...by the end of 2021", - options: options, - timestamp: new Date().toISOString(), - qualityindicators: { - numforecasts: Number((question.measurementCount + 1) / 2), - stars: calculateStars("AstralCodexTen", {}), - }, - /*liquidity: liquidity.toFixed(2), - tradevolume: tradevolume.toFixed(2), - address: obj.address*/ - }; - // console.log(result) - results.push(result); - }); - } - await databaseUpsert(results, "astralcodexten-questions"); - // console.log(results) - console.log("Done"); -} -// astralcodexten() diff --git a/src/backend/platforms/deprecated/coupcast-fetch.js b/src/backend/platforms/deprecated/coupcast-fetch.js deleted file mode 100644 index d3627df..0000000 --- a/src/backend/platforms/deprecated/coupcast-fetch.js +++ /dev/null @@ -1,184 +0,0 @@ -/* Imports */ -import axios from "axios"; -import Papa from "papaparse"; -import { databaseUpsert } from "../utils/database-wrapper"; -import { calculateStars } from "../utils/stars"; - -/* Definitions */ -let coupCastEndpoint = - "https://www.oneearthfuture.org/sites/all/themes/stability/stability_sub/data/dashboard_2021_code_06.csv"; -var datenow = new Date(); -var currentmonth = datenow.getMonth() + 1; -dd; -/* Support functions */ -let unique = (arr) => [...new Set(arr)]; -let sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); - -let sanitizeCountryName = (country_name) => { - let sanitized_name; - switch (country_name) { - case "Cen African Rep": - sanitized_name = "Central African Republic"; - break; - case "Congo-Brz": - sanitized_name = "Republic of the Congo"; - break; - case "Congo/Zaire": - sanitized_name = "Democratic Republic of the Congo"; - break; - case "Czech Rep": - sanitized_name = "Czech Republic"; - break; - case "Dominican Rep": - sanitized_name = "Dominican Republic"; - break; - case "Korea North": - sanitized_name = "North Korea"; - break; - case "Korea South": - sanitized_name = "South Korea"; - break; - case "UKG": - sanitized_name = "UK"; - break; - default: - sanitized_name = country_name; - } - return sanitized_name; -}; - -async function processArray(countryArray) { - let results = []; - for (let country of countryArray) { - let url = `https://www.oneearthfuture.org/activities/coup-cast`; - - // We don't really want the prediction for all months; one is enough - // console.log(country.month) - if (Number(country.month) == currentmonth) { - // Monthly - country.country_name = sanitizeCountryName(country.country_name); - let processedPrediction1 = { - title: `Will there be a coup in ${country.country_name} in the next month (as of ${country.month}/${country.year})?`, - url: url, - platform: "CoupCast", - description: `The current leader of ${country.country_name} is ${ - country.leader_name - }, who has been in power for ${Number(country.leader_years).toFixed( - 1 - )} years. ${ - country.country_name - } has a ${country.regime_type.toLowerCase()} regime type which has lasted for ${ - country.regime_years - } years.`, - options: [ - { - name: "Yes", - probability: country.month_risk, - type: "PROBABILITY", - }, - { - name: "No", - probability: 1 - country.month_risk, - type: "PROBABILITY", - }, - ], - timestamp: new Date().toISOString(), - qualityindicators: { - stars: calculateStars("Coupcast", {}), - }, - extra: { - country_name: country.country_name, - regime_type: country.regime_type, - month: country.month, - year: country.year, - leader_name: country.leader_name, - month_risk: country.month_risk, - annual_risk: country.annual_risk, - risk_change_percent: country.risk_change_percent, - regime_years: country.regime_years, - leader_years: country.leader_years, - country_code: country.country_code, - country_abb: country.country_abb, - }, - }; - - // Yearly - let processedPrediction2 = { - title: `Will there be a coup in ${country.country_name} in the next year (as of ${country.month}/${country.year})?`, - url: url, - platform: "CoupCast", - description: `The current leader of ${country.country_name} is ${ - country.leader_name - }, who has been in power for ${Number(country.leader_years).toFixed( - 1 - )} years. ${ - country.country_name - } has a ${country.regime_type.toLowerCase()} regime type which has lasted for ${ - country.regime_years - } years`, - options: [ - { - name: "Yes", - probability: country.annual_risk, - type: "PROBABILITY", - }, - { - name: "No", - probability: 1 - country.annual_risk, - type: "PROBABILITY", - }, - ], - timestamp: new Date().toISOString(), - qualityindicators: { - stars: calculateStars("CoupCast", {}), - }, - extra: { - country_name: country.country_name, - regime_type: country.regime_type, - month: country.month, - year: country.year, - leader_name: country.leader_name, - month_risk: country.month_risk, - annual_risk: country.annual_risk, - risk_change_percent: country.risk_change_percent, - regime_years: country.regime_years, - leader_years: country.leader_years, - country_code: country.country_code, - country_abb: country.country_abb, - }, - }; - - // results.push(processedPrediction1) - // Not pushing monthly - results.push(processedPrediction2); - } - } - await databaseUpsert(results, "coupcast-questions"); - // console.log(results) - console.log("Done"); -} - -/* Body */ - -export async function coupcast() { - let csvContent = await axios - .get(coupCastEndpoint) - .then((query) => query.data); - await Papa.parse(csvContent, { - header: true, - complete: async (results) => { - console.log("Downloaded", results.data.length, "records."); - /* console.log( - JSON.stringify( - unique(results.data.map(country => country.country_name)), - null, - 4 - ) - )*/ - // console.log(results.data) - await processArray(results.data); - }, - }); - await sleep(1000); // needed to wait for Papaparse's callback to be executed. -} -// coupcast() diff --git a/src/backend/platforms/deprecated/csetforetell-fetch.js b/src/backend/platforms/deprecated/csetforetell-fetch.js deleted file mode 100644 index 065f66f..0000000 --- a/src/backend/platforms/deprecated/csetforetell-fetch.js +++ /dev/null @@ -1,280 +0,0 @@ -/* Imports */ -import axios from "axios"; -import { Tabletojson } from "tabletojson"; -import { databaseUpsert } from "../utils/database-wrapper"; -import { applyIfSecretExists } from "../utils/getSecrets"; -import { calculateStars } from "../utils/stars"; -import toMarkdown from "../utils/toMarkdown"; - -/* Definitions */ -let htmlEndPoint = "https://www.cset-foretell.com/questions?page="; -String.prototype.replaceAll = function replaceAll(search, replace) { - return this.split(search).join(replace); -}; -const DEBUG_MODE = "on"; // "off" -const SLEEP_TIME_RANDOM = 100; //5000 // miliseconds -const SLEEP_TIME_EXTRA = 0; //1000 -/* Support functions */ - -async function fetchPage(page, cookie) { - console.log(`Page #${page}`); - if (page == 1) { - cookie = cookie.split(";")[0]; // Interesting that it otherwise doesn't work :( - } - let urlEndpoint = htmlEndPoint + page; - console.log(urlEndpoint); - let response = await axios({ - url: urlEndpoint, - method: "GET", - headers: { - "Content-Type": "text/html", - Cookie: cookie, - }, - }).then((res) => res.data); - // console.log(response) - return response; -} - -async function fetchStats(questionUrl, cookie) { - let response = await axios({ - url: questionUrl + "/stats", - method: "GET", - headers: { - "Content-Type": "text/html", - Cookie: cookie, - Referer: questionUrl, - }, - }).then((res) => res.data); - - if (response.includes("Sign up or sign in to forecast")) { - throw Error("Not logged in"); - } - - // Is binary? - let isbinary = response.includes("binary?":true"); - // console.log(`is binary? ${isbinary}`) - let options = []; - if (isbinary) { - // Crowd percentage - let htmlElements = response.split("\n"); - // DEBUG_MODE == "on" ? htmlLines.forEach(line => console.log(line)) : id() - let h3Element = htmlElements.filter((str) => str.includes("