diff --git a/package.json b/package.json index c590d4e..a8c974b 100644 --- a/package.json +++ b/package.json @@ -25,8 +25,12 @@ "typescript": "^4.1.3" }, "scripts": { + "bulkAdd": "ts-node ./scripts/bulk_add.ts", "build": "ts-node ./scripts/build.ts && tsc -d", "prepare": "yarn build", "validate": "yarn build && ts-node ./scripts/validate.ts" + }, + "dependencies": { + "axios": "^0.21.1" } } diff --git a/scripts/bulk_add.ts b/scripts/bulk_add.ts index 94ef6ee..3cbd1df 100644 --- a/scripts/bulk_add.ts +++ b/scripts/bulk_add.ts @@ -1,8 +1,50 @@ +import axios from "axios"; + const SNAPSHOT_API = "https://hub.snapshot.page/api/"; -async function fetchAllSpaces() { - const spaces = fetch(`${SNAPSHOT_API}/spaces`).then((res) => { - console.log("res => ", res); - return res.body; +interface Space { + strategies: any[]; + plugins: any; + filters: any; + name: string; + network: string; // '1', '56', etc + symbol: string; + domain: string; + about: string; + twitter: string; + github: string; +} + +function filterObject(obj: any, predicate: Function) { + let result: Record = {}; + + for (let key in obj) { + if (obj.hasOwnProperty(key) && !predicate(obj[key])) { + result[key] = obj[key]; + } + } + + return result; +} + +async function fetchAllSpaces(): Promise> { + return axios.get(`${SNAPSHOT_API}/spaces`).then((res) => { + const spaces = res.data; + + return spaces; }); } + +async function fetchMainnetSpaces() { + const allSpaces = await fetchAllSpaces(); + + const filtered = filterObject(allSpaces, (space: Space) => space.network !== "1"); + + return filtered; +} + +fetchMainnetSpaces(); + +// async function run() { + +// } diff --git a/yarn.lock b/yarn.lock index 4cc3d28..fb97f37 100644 --- a/yarn.lock +++ b/yarn.lock @@ -19,6 +19,13 @@ arg@^4.1.0: resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089" integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA== +axios@^0.21.1: + version "0.21.1" + resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.1.tgz#22563481962f4d6bde9a76d516ef0e5d3c09b2b8" + integrity sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA== + dependencies: + follow-redirects "^1.10.0" + buffer-from@^1.0.0: version "1.1.1" resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef" @@ -34,6 +41,11 @@ diff@^4.0.1: resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d" integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A== +follow-redirects@^1.10.0: + version "1.13.3" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.3.tgz#e5598ad50174c1bc4e872301e82ac2cd97f90267" + integrity sha512-DUgl6+HDzB0iEptNQEXLx/KhTmDb8tZUHSeLqpnjpknR70H0nC2t9N73BK6fN4hOvJ84pKlIQVQ4k5FFlBedKA== + fp-ts@^2.9.5: version "2.9.5" resolved "https://registry.yarnpkg.com/fp-ts/-/fp-ts-2.9.5.tgz#6690cd8b76b84214a38fc77cbbbd04a38f86ea90"