2021-02-16 14:18:23 +00:00
|
|
|
/* Imports */
|
2022-03-28 17:59:07 +00:00
|
|
|
import axios from "axios";
|
|
|
|
import fs from "fs";
|
2022-03-27 21:10:31 +00:00
|
|
|
|
2022-05-09 21:15:18 +00:00
|
|
|
import { average } from "../../utils";
|
2022-03-30 16:53:22 +00:00
|
|
|
import { Platform } from "./";
|
2021-02-16 14:18:23 +00:00
|
|
|
|
2022-04-01 20:24:35 +00:00
|
|
|
const platformName = "givewellopenphil";
|
|
|
|
|
2021-02-16 14:18:23 +00:00
|
|
|
/* Support functions */
|
2022-05-09 17:37:28 +00:00
|
|
|
async function fetchPage(url: string): Promise<string> {
|
|
|
|
const response = await axios({
|
2021-02-16 14:18:23 +00:00
|
|
|
url: url,
|
2022-02-11 14:21:36 +00:00
|
|
|
method: "GET",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "text/html",
|
|
|
|
},
|
|
|
|
}).then((res) => res.data);
|
|
|
|
return response;
|
2021-02-16 14:18:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Body */
|
|
|
|
|
2022-02-14 20:39:30 +00:00
|
|
|
async function main1() {
|
2022-03-16 21:02:34 +00:00
|
|
|
let rawdata = fs.readFileSync("./input/givewellopenphil-urls.txt");
|
2022-02-11 14:21:36 +00:00
|
|
|
let data = rawdata
|
|
|
|
.toString()
|
|
|
|
.split("\n")
|
|
|
|
.filter((url) => url != "");
|
2021-04-08 19:32:03 +00:00
|
|
|
// console.log(data)
|
2022-02-11 14:21:36 +00:00
|
|
|
let results = [];
|
2021-03-02 13:29:27 +00:00
|
|
|
for (let url of data) {
|
2021-04-08 19:32:03 +00:00
|
|
|
// console.log(url)
|
2022-02-11 14:21:36 +00:00
|
|
|
let page = await fetchPage(url);
|
2021-03-02 13:29:27 +00:00
|
|
|
|
2021-02-16 14:18:23 +00:00
|
|
|
// Title
|
2022-02-11 14:21:36 +00:00
|
|
|
let titleraw = page.split('<meta name="twitter:title" content="')[1];
|
|
|
|
let title = titleraw.split('" />')[0];
|
2021-03-02 13:29:27 +00:00
|
|
|
|
2021-02-16 14:18:23 +00:00
|
|
|
// Description
|
2022-02-11 14:21:36 +00:00
|
|
|
let internalforecasts = page
|
|
|
|
.split("<h2")
|
|
|
|
.filter(
|
|
|
|
(section) =>
|
|
|
|
section.includes("Internal forecast") ||
|
|
|
|
section.includes("internal forecast")
|
|
|
|
);
|
|
|
|
let description = "<h2 " + internalforecasts[1];
|
2021-03-02 13:29:27 +00:00
|
|
|
|
2022-04-23 19:44:38 +00:00
|
|
|
const result = {
|
|
|
|
title,
|
|
|
|
url,
|
2022-04-01 20:24:35 +00:00
|
|
|
platform: platformName,
|
2022-04-23 19:44:38 +00:00
|
|
|
description,
|
|
|
|
options: [],
|
2022-05-09 21:15:18 +00:00
|
|
|
qualityindicators: {},
|
2022-02-11 14:21:36 +00:00
|
|
|
}; // Note: This requires some processing afterwards
|
2021-04-08 19:32:03 +00:00
|
|
|
// console.log(result)
|
2022-02-11 14:21:36 +00:00
|
|
|
results.push(result);
|
2021-02-16 14:18:23 +00:00
|
|
|
}
|
2022-03-31 10:00:09 +00:00
|
|
|
// await databaseUpsert({
|
|
|
|
// contents: results,
|
|
|
|
// group: "givewell-questions-unprocessed",
|
|
|
|
// });
|
2022-02-14 20:39:30 +00:00
|
|
|
}
|
2022-02-12 06:27:56 +00:00
|
|
|
|
2022-03-30 16:53:22 +00:00
|
|
|
export const givewellopenphil: Platform = {
|
2022-04-01 20:24:35 +00:00
|
|
|
name: platformName,
|
|
|
|
label: "GiveWell/OpenPhilanthropy",
|
|
|
|
color: "#32407e",
|
2022-05-12 13:58:56 +00:00
|
|
|
version: "v1",
|
2022-03-30 16:53:22 +00:00
|
|
|
async fetcher() {
|
|
|
|
// main1()
|
|
|
|
return; // not necessary to refill the DB every time
|
|
|
|
const rawdata = fs.readFileSync("./input/givewellopenphil-questions.json", {
|
|
|
|
encoding: "utf-8",
|
|
|
|
});
|
|
|
|
const data = JSON.parse(rawdata);
|
|
|
|
const dataWithDate = data.map((datum: any) => ({
|
|
|
|
...datum,
|
2022-04-01 23:25:12 +00:00
|
|
|
platform: platformName,
|
2022-05-20 20:59:33 +00:00
|
|
|
// timestamp: new Date("2021-02-23"),
|
2022-03-30 16:53:22 +00:00
|
|
|
}));
|
|
|
|
return dataWithDate;
|
|
|
|
},
|
2022-05-09 21:15:18 +00:00
|
|
|
calculateStars(data) {
|
|
|
|
let nuno = () => 2;
|
|
|
|
let eli = () => null;
|
|
|
|
let misha = () => null;
|
|
|
|
let starsDecimal = average([nuno()]); //, eli(), misha()])
|
|
|
|
let starsInteger = Math.round(starsDecimal);
|
|
|
|
return starsInteger;
|
|
|
|
},
|
2022-03-30 16:53:22 +00:00
|
|
|
};
|