2022-12-10 09:14:48 +00:00
|
|
|
import fs from 'fs';
|
|
|
|
|
|
|
|
const { INSTANCES_SOCIAL_SECRET_TOKEN } = process.env;
|
|
|
|
|
|
|
|
const params = new URLSearchParams({
|
2023-01-01 13:00:43 +00:00
|
|
|
count: 0,
|
2023-06-05 06:57:53 +00:00
|
|
|
min_users: 500,
|
2022-12-10 09:14:48 +00:00
|
|
|
sort_by: 'active_users',
|
|
|
|
sort_order: 'desc',
|
|
|
|
});
|
|
|
|
|
|
|
|
const url = `https://instances.social/api/1.0/instances/list?${params.toString()}`;
|
|
|
|
const results = await fetch(url, {
|
|
|
|
headers: {
|
|
|
|
Authorization: `Bearer ${INSTANCES_SOCIAL_SECRET_TOKEN}`,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const json = await results.json();
|
2023-08-22 12:11:28 +00:00
|
|
|
|
|
|
|
// Filters
|
|
|
|
json.instances = json.instances.filter(
|
|
|
|
(instance) => Number(instance.connections) > 20,
|
|
|
|
);
|
|
|
|
|
2022-12-10 09:14:48 +00:00
|
|
|
const names = json.instances.map((instance) => instance.name);
|
|
|
|
|
|
|
|
// Write to file
|
|
|
|
const path = './src/data/instances.json';
|
|
|
|
fs.writeFileSync(path, JSON.stringify(names, null, '\t'), 'utf8');
|
2023-08-22 12:11:28 +00:00
|
|
|
|
|
|
|
// Write everything to file, for debugging
|
|
|
|
const path2 = './src/data/instances-full.json';
|
|
|
|
fs.writeFileSync(path2, JSON.stringify(json, null, '\t'), 'utf8');
|