-
Notifications
You must be signed in to change notification settings - Fork 6
/
givewellopenphil.ts
94 lines (85 loc) · 2.29 KB
/
givewellopenphil.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* Imports */
import axios from "axios";
import fs from "fs";
import { average } from "../../utils";
import { Platform } from "./";
const platformName = "givewellopenphil";
/* Support functions */
async function fetchPage(url: string): Promise<string> {
const response = await axios({
url: url,
method: "GET",
headers: {
"Content-Type": "text/html",
},
}).then((res) => res.data);
return response;
}
/* Body */
async function main1() {
let rawdata = fs.readFileSync("./input/givewellopenphil-urls.txt");
let data = rawdata
.toString()
.split("\n")
.filter((url) => url != "");
// console.log(data)
let results = [];
for (let url of data) {
// console.log(url)
let page = await fetchPage(url);
// Title
let titleraw = page.split('<meta name="twitter:title" content="')[1];
let title = titleraw.split('" />')[0];
// Description
let internalforecasts = page
.split("<h2")
.filter(
(section) =>
section.includes("Internal forecast") ||
section.includes("internal forecast")
);
let description = "<h2 " + internalforecasts[1];
const result = {
title,
url,
platform: platformName,
description,
options: [],
qualityindicators: {},
}; // Note: This requires some processing afterwards
// console.log(result)
results.push(result);
}
// await databaseUpsert({
// contents: results,
// group: "givewell-questions-unprocessed",
// });
}
export const givewellopenphil: Platform = {
name: platformName,
label: "GiveWell/OpenPhilanthropy",
color: "#32407e",
version: "v1",
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,
platform: platformName,
// timestamp: new Date("2021-02-23"),
}));
return dataWithDate;
},
calculateStars(data) {
let nuno = () => 2;
let eli = () => null;
let misha = () => null;
let starsDecimal = average([nuno()]); //, eli(), misha()])
let starsInteger = Math.round(starsDecimal);
return starsInteger;
},
};