From 91993f5c06dd0bea5dbbe1120465cb2818f7bb55 Mon Sep 17 00:00:00 2001 From: Jan Andrle Date: Tue, 1 Aug 2023 13:28:28 +0200 Subject: [PATCH] :tada: Signed-off-by: Jan Andrle --- .gitignore | 132 +++++++++++++ LICENSE | 9 + README.md | 3 + mastodonCzStats.js | 97 ++++++++++ mastodonCzStats.json | 452 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 693 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 mastodonCzStats.js create mode 100644 mastodonCzStats.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ceaea36 --- /dev/null +++ b/.gitignore @@ -0,0 +1,132 @@ +# ---> Node +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) +web_modules/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional stylelint cache +.stylelintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variable files +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next +out + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# vuepress v2.x temp and cache directory +.temp +.cache + +# Docusaurus cache and generated files +.docusaurus + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# yarn v2 +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2a2c3d6 --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) 2023 jaandrle + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..8908c4b --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# mastodonCzStats + +Experimentální skript k získání českých Mastodon instancí a dodatečných informací. \ No newline at end of file diff --git a/mastodonCzStats.js b/mastodonCzStats.js new file mode 100644 index 0000000..5370229 --- /dev/null +++ b/mastodonCzStats.js @@ -0,0 +1,97 @@ +#!/usr/bin/env nodejsscript +/* jshint esversion: 11,-W097, -W040, module: true, node: true, expr: true, undef: true *//* global echo, $, pipe, s, fetch, cyclicLoop */ +const instances_cz_pre= new Set([ + "mastodonczech.cz", + "mastodon.arch-linux.cz", + "nasface.cz", + "witter.cz", + "cztwitter.cz", + "mastodon.pirati.cz", + "gomastodon.cz", + "f.cz", + "toot.whatever.cz", + "mastodon.macsnet.cz", + "lgbtcz.social", + "kompost.cz", + "boskovice.social", + "propulse.club", + "mastodon.1984.cz", + "mastodon.rozhlas.cz", + "fediverse.cz", + "mastodon.queerclub.cz", + "mastodon.urbancloud.cz", + "kocour.club", + "mastodon.telekomunikace.cz", + "ajtaci.club", + "mastodon.darksheep.social", + "social.filik.eu", + "social.meyer.cz", + "mastodon.posvic.cz", + "mastodon.starnet.cz", + "blogator.com", + "hatedon.1984.cz", + "mastodon.loutaci.cz", + "social.gwei.cz", + "mastodon.vyboh.net", + "mastodon.skorpil.cz", + "mastodon.hinata.cz", + "social.toxwat.cz", + "spondr.cz", + "hlidacstatu.social", + "mastodon.train.cz", + "social.bobek.cz", + "social.blep.cz", + "mastodon.kickme.cz", + "mastodon.starlink.cz", + "mastodon.kiklhorn.cz", + "mastodon.haxo.cz", + "mutant.cz", + "masto.den1.cz", + "mastodon.gmb.cz", + "rodina-sucha.cz", + "social.taborsky.cz", +]); +const timeOut= (l= 500)=> AbortSignal.timeout(l); +(async function main(){ + let stats= []; + for(const instance of instances_cz_pre){ + echo.use("-R", "Shromažďuji instance: " + instance); + const peers= await fetch("https://"+instance+"/api/v1/instance/peers", { signal: timeOut() }) + .then(res=> res.json()).catch(()=> []); + if(peers && Array.isArray(peers)) + peers.filter(i=> i.endsWith(".cz")).forEach(i=> instances_cz_pre.add(i)); + } + const instances_cz= Array.from(instances_cz_pre); + const { length }= instances_cz; + for await(const data of collectStats(instances_cz, 4)){ + echo.use("-R", "Shromažďuji data za instance: " + instances_cz.indexOf(data.instance)+"/"+length+": "+data.instance); + stats.push(data); + } + const out= { + instances_cz: stats.sort((a, b)=> b.registrations-a.registrations), + sum: stats.reduce((acc, stats) => sumStats([acc, stats]), { statuses: 0, logins: 0, registrations: 0, mau: 0, user_count: 0 }) + }; + echo(JSON.stringify(out, null, " ")).to("./mastodonCzStats.json"); + $.exit(0); +})(); + +async function* collectStats(instances, weeks = 1) { + for(const instance of instances){ + const { stats, mau, user_count }= await fetchInstanceStats(instance).catch(e=> ({})); + if(!stats || !Array.isArray(stats)) continue; + yield { instance, mau, user_count, ...sumStats(stats.slice(0, weeks + 1)) }; + } +} +function sumStats(arr) { + const out= Object.keys(arr[0]).reduce((acc, curr)=> (acc[curr]= 0, acc), {}); + for (const key of Object.keys(out)) + for (const s of arr) out[key]+= Number(s[key]); + return out; +} +async function fetchInstanceStats(instance) { + const url_main= "https://" + instance + "/api/"; + const stats= await fetch(url_main+"v1/instance/activity", { signal: timeOut() }).then(res=> res.json()); + const { usage: { users } }= await fetch(url_main+"v2/instance", { signal: timeOut() }).then(res=> res.json()); + const { stats: { user_count } }= await fetch(url_main+"v1/instance", { signal: timeOut() }).then(res=> res.json()); + return { instance, stats, mau: users.active_month, user_count }; +} diff --git a/mastodonCzStats.json b/mastodonCzStats.json new file mode 100644 index 0000000..6a211bf --- /dev/null +++ b/mastodonCzStats.json @@ -0,0 +1,452 @@ +{ + "instances_cz": [ + { + "instance": "mastodonczech.cz", + "mau": 1865, + "user_count": 5020, + "week": 8447769225, + "statuses": 21569, + "logins": 4394, + "registrations": 236 + }, + { + "instance": "mastodon.arch-linux.cz", + "mau": 558, + "user_count": 2862, + "week": 8447718935, + "statuses": 11147, + "logins": 1226, + "registrations": 171 + }, + { + "instance": "witter.cz", + "mau": 492, + "user_count": 1326, + "week": 8447743540, + "statuses": 7547, + "logins": 1385, + "registrations": 114 + }, + { + "instance": "cztwitter.cz", + "mau": 411, + "user_count": 762, + "week": 8447959625, + "statuses": 14342, + "logins": 1116, + "registrations": 102 + }, + { + "instance": "lgbtcz.social", + "mau": 18, + "user_count": 38, + "week": 8447725520, + "statuses": 728, + "logins": 53, + "registrations": 6 + }, + { + "instance": "mastodon.ok1bt.cz", + "mau": 7, + "user_count": 7, + "week": 8447981270, + "statuses": 25, + "logins": 10, + "registrations": 5 + }, + { + "instance": "nasface.cz", + "mau": 37, + "user_count": 1376, + "week": 8447899535, + "statuses": 14, + "logins": 58, + "registrations": 3 + }, + { + "instance": "torsten.cz", + "mau": 3, + "user_count": 3, + "week": 8447981290, + "statuses": 10, + "logins": 3, + "registrations": 3 + }, + { + "instance": "mastodon.pirati.cz", + "mau": 81, + "user_count": 358, + "week": 8447807405, + "statuses": 197, + "logins": 184, + "registrations": 2 + }, + { + "instance": "gomastodon.cz", + "mau": 15, + "user_count": 229, + "week": 8447626815, + "statuses": 7, + "logins": 34, + "registrations": 2 + }, + { + "instance": "toot.whatever.cz", + "mau": 8, + "user_count": 52, + "week": 8447922070, + "statuses": 30, + "logins": 21, + "registrations": 2 + }, + { + "instance": "masto.den1.cz", + "mau": 4, + "user_count": 3, + "week": 8447695030, + "statuses": 617, + "logins": 16, + "registrations": 2 + }, + { + "instance": "propulse.club", + "mau": 13, + "user_count": 21, + "week": 8447634375, + "statuses": 3563, + "logins": 43, + "registrations": 1 + }, + { + "instance": "mastodon.starnet.cz", + "mau": 2, + "user_count": 6, + "week": 8447877915, + "statuses": 30, + "logins": 5, + "registrations": 1 + }, + { + "instance": "mastodon.loutaci.cz", + "mau": 3, + "user_count": 5, + "week": 8447792935, + "statuses": 0, + "logins": 6, + "registrations": 1 + }, + { + "instance": "f.cz", + "mau": 35, + "user_count": 87, + "week": 8447788120, + "statuses": 588, + "logins": 93, + "registrations": 0 + }, + { + "instance": "mastodon.macsnet.cz", + "mau": 3, + "user_count": 52, + "week": 8447874370, + "statuses": 424, + "logins": 12, + "registrations": 0 + }, + { + "instance": "mastodon.1984.cz", + "mau": 4, + "user_count": 20, + "week": 8447805105, + "statuses": 115, + "logins": 11, + "registrations": 0 + }, + { + "instance": "mastodon.rozhlas.cz", + "mau": 11, + "user_count": 18, + "week": 8447826630, + "statuses": 416, + "logins": 34, + "registrations": 0 + }, + { + "instance": "fediverse.cz", + "mau": 3, + "user_count": 17, + "week": 8447857235, + "statuses": 2, + "logins": 7, + "registrations": 0 + }, + { + "instance": "mastodon.queerclub.cz", + "mau": 4, + "user_count": 17, + "week": 8447564720, + "statuses": 0, + "logins": 4, + "registrations": 0 + }, + { + "instance": "mastodon.urbancloud.cz", + "mau": 9, + "user_count": 16, + "week": 8447981170, + "statuses": 19, + "logins": 25, + "registrations": 0 + }, + { + "instance": "kocour.club", + "mau": 10, + "user_count": 14, + "week": 8447954840, + "statuses": 31, + "logins": 37, + "registrations": 0 + }, + { + "instance": "mastodon.telekomunikace.cz", + "mau": 1, + "user_count": 11, + "week": 8447736285, + "statuses": 1, + "logins": 3, + "registrations": 0 + }, + { + "instance": "ajtaci.club", + "mau": 1, + "user_count": 9, + "week": 8447791520, + "statuses": 5, + "logins": 4, + "registrations": 0 + }, + { + "instance": "mastodon.darksheep.social", + "mau": 2, + "user_count": 8, + "week": 8447814335, + "statuses": 0, + "logins": 7, + "registrations": 0 + }, + { + "instance": "social.filik.eu", + "mau": 3, + "user_count": 7, + "week": 8447700765, + "statuses": 17, + "logins": 11, + "registrations": 0 + }, + { + "instance": "social.meyer.cz", + "mau": 5, + "user_count": 7, + "week": 8447738005, + "statuses": 203, + "logins": 22, + "registrations": 0 + }, + { + "instance": "mastodon.posvic.cz", + "mau": 1, + "user_count": 7, + "week": 8447952215, + "statuses": 1, + "logins": 5, + "registrations": 0 + }, + { + "instance": "blogator.com", + "mau": 1, + "user_count": 5, + "week": 8447903500, + "statuses": 0, + "logins": 2, + "registrations": 0 + }, + { + "instance": "hatedon.1984.cz", + "mau": 2, + "user_count": 5, + "week": 8447691480, + "statuses": 1, + "logins": 2, + "registrations": 0 + }, + { + "instance": "social.gwei.cz", + "mau": 2, + "user_count": 4, + "week": 8447593930, + "statuses": 3, + "logins": 8, + "registrations": 0 + }, + { + "instance": "mastodon.vyboh.net", + "mau": 1, + "user_count": 4, + "week": 8447616070, + "statuses": 0, + "logins": 2, + "registrations": 0 + }, + { + "instance": "mastodon.skorpil.cz", + "mau": 3, + "user_count": 3, + "week": 8447553360, + "statuses": 43, + "logins": 12, + "registrations": 0 + }, + { + "instance": "mastodon.hinata.cz", + "mau": 1, + "user_count": 3, + "week": 8447557805, + "statuses": 0, + "logins": 4, + "registrations": 0 + }, + { + "instance": "social.toxwat.cz", + "mau": 1, + "user_count": 3, + "week": 8447789740, + "statuses": 0, + "logins": 3, + "registrations": 0 + }, + { + "instance": "spondr.cz", + "mau": 3, + "user_count": 3, + "week": 8447679050, + "statuses": 234, + "logins": 14, + "registrations": 0 + }, + { + "instance": "hlidacstatu.social", + "mau": 1, + "user_count": 3, + "week": 8447887955, + "statuses": 14, + "logins": 4, + "registrations": 0 + }, + { + "instance": "mastodon.train.cz", + "mau": 2, + "user_count": 2, + "week": 8447737970, + "statuses": 0, + "logins": 5, + "registrations": 0 + }, + { + "instance": "social.bobek.cz", + "mau": 1, + "user_count": 2, + "week": 8447892025, + "statuses": 0, + "logins": 5, + "registrations": 0 + }, + { + "instance": "social.blep.cz", + "mau": 1, + "user_count": 2, + "week": 8447739845, + "statuses": 0, + "logins": 3, + "registrations": 0 + }, + { + "instance": "mastodon.kickme.cz", + "mau": 1, + "user_count": 2, + "week": 8447897000, + "statuses": 0, + "logins": 2, + "registrations": 0 + }, + { + "instance": "mastodon.starlink.cz", + "mau": 1, + "user_count": 2, + "week": 8447981220, + "statuses": 0, + "logins": 4, + "registrations": 0 + }, + { + "instance": "mastodon.haxo.cz", + "mau": 1, + "user_count": 2, + "week": 8447557695, + "statuses": 0, + "logins": 3, + "registrations": 0 + }, + { + "instance": "mutant.cz", + "mau": 1, + "user_count": 2, + "week": 8447730400, + "statuses": 0, + "logins": 5, + "registrations": 0 + }, + { + "instance": "mastodon.gmb.cz", + "mau": 1, + "user_count": 1, + "week": 8447583580, + "statuses": 13, + "logins": 4, + "registrations": 0 + }, + { + "instance": "rodina-sucha.cz", + "mau": 1, + "user_count": 1, + "week": 8447709195, + "statuses": 68, + "logins": 5, + "registrations": 0 + }, + { + "instance": "social.taborsky.cz", + "mau": 1, + "user_count": 1, + "week": 8447858115, + "statuses": 1, + "logins": 4, + "registrations": 0 + }, + { + "instance": "mastodon.zs-studanka.cz", + "mau": 1, + "user_count": 1, + "week": 8447954915, + "statuses": 1, + "logins": 3, + "registrations": 0 + } + ], + "sum": { + "statuses": 62026, + "logins": 8923, + "registrations": 651, + "mau": 3636, + "user_count": 12409 + } +}