boardroom-inc-protocol-Info/scripts/bulk_add.ts

60 lines
1.2 KiB
TypeScript
Raw Normal View History

2021-04-22 18:48:54 +00:00
import axios from "axios";
2021-04-22 18:25:49 +00:00
const SNAPSHOT_API = "https://hub.snapshot.page/api/";
2021-04-22 18:48:54 +00:00
interface Space {
strategies: any[];
plugins: any;
filters: any;
name: string;
network: string; // '1', '56', etc
members?: [];
2021-04-22 18:48:54 +00:00
symbol: string;
domain: string;
about: string;
twitter: string;
github: string;
}
function filterObject(obj: any, predicate: Function) {
let result: Record<string, any> = {};
for (let key in obj) {
if (obj.hasOwnProperty(key) && predicate(obj[key])) {
2021-04-22 18:48:54 +00:00
result[key] = obj[key];
}
}
return result;
}
async function fetchAllSpaces(): Promise<Record<string, Space>> {
return axios.get(`${SNAPSHOT_API}/spaces`).then((res) => {
const spaces = res.data;
return spaces;
2021-04-22 18:25:49 +00:00
});
}
2021-04-22 18:48:54 +00:00
async function fetchMainnetSpaces() {
const allSpaces = await fetchAllSpaces();
const filtered = filterObject(allSpaces, (space: Space) => space.network === "1");
2021-04-22 18:48:54 +00:00
return filtered;
}
async function run() {
const allMainnetSpaces = await fetchMainnetSpaces();
2021-04-22 18:48:54 +00:00
console.log(Object.keys(allMainnetSpaces).length);
2021-04-22 18:48:54 +00:00
const withMembers = filterObject(allMainnetSpaces, (space: Space) => space.members && space.members.length > 4);
console.log(Object.keys(withMembers).length);
console.log(withMembers);
}
run();