2021-02-16 14:18:23 +00:00
|
|
|
/* Imports */
|
2022-02-11 14:21:36 +00:00
|
|
|
import axios from "axios";
|
2022-03-16 21:02:34 +00:00
|
|
|
import fs from "fs";
|
2022-03-26 00:36:50 +00:00
|
|
|
import { databaseUpsert } from "../database/database-wrapper";
|
|
|
|
import { calculateStars } from "../utils/stars";
|
2021-02-16 14:18:23 +00:00
|
|
|
|
|
|
|
/* Support functions */
|
2021-03-02 13:29:27 +00:00
|
|
|
async function fetchPage(url) {
|
|
|
|
let 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);
|
2021-02-16 14:18:23 +00:00
|
|
|
//console.log(response)
|
2022-02-11 14:21:36 +00:00
|
|
|
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
|
|
|
|
2021-02-16 14:18:23 +00:00
|
|
|
let result = {
|
2022-02-11 14:21:36 +00:00
|
|
|
title: title,
|
|
|
|
url: url,
|
|
|
|
platform: "GiveWell",
|
|
|
|
description: description,
|
|
|
|
timestamp: new Date().toISOString(),
|
|
|
|
qualityindicators: {
|
|
|
|
stars: calculateStars("GiveWell/OpenPhilanthropy", {}),
|
|
|
|
},
|
|
|
|
}; // 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-02-14 20:39:30 +00:00
|
|
|
await databaseUpsert({
|
|
|
|
contents: results,
|
|
|
|
group: "givewell-questions-unprocessed",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// main1()
|
2022-02-12 06:27:56 +00:00
|
|
|
|
2022-02-14 20:39:30 +00:00
|
|
|
async function main2() {
|
2022-03-16 21:02:34 +00:00
|
|
|
let rawdata = fs.readFileSync("./input/givewellopenphil-questions.json");
|
2022-02-14 20:39:30 +00:00
|
|
|
let data = JSON.parse(rawdata);
|
2022-03-16 21:02:34 +00:00
|
|
|
let dataWithDate = data.map((datum) => ({
|
|
|
|
...datum,
|
|
|
|
timestamp: "2021-02-23",
|
|
|
|
}));
|
2022-02-14 20:39:30 +00:00
|
|
|
await databaseUpsert({ group: "givewellopenphil", contents: dataWithDate });
|
2021-02-16 14:18:23 +00:00
|
|
|
}
|
2022-02-14 20:39:30 +00:00
|
|
|
main2();
|