dev-cron (#1)

Reviewed-on: #1
Co-authored-by: Bot <andrle.jan@centrum.cz>
Co-committed-by: Bot <andrle.jan@centrum.cz>
This commit is contained in:
2024-06-28 14:11:01 +02:00
committed by Jan Andrle
parent ea27404353
commit fc181ea086
6 changed files with 920 additions and 294 deletions

View File

@ -1,58 +1,15 @@
#!/usr/bin/env nodejsscript
#!/usr/bin/env -S npx 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 store= "./mastodonCzStats.json";
const instances_cz_pre= new Set(s.cat(store).xargs(JSON.parse).instances_cz.map(i=> i.instance));
const { version, description }= s.cat("package.json").xargs(JSON.parse);
const timeOut= (l= 500)=> AbortSignal.timeout(l);
(async function main(){
$.api("", true)
.version(version)
.describe(description)
.option("--git", "Commit changes to git")
.action(async function main({ git: is_git }){
let stats= [];
for(const instance of instances_cz_pre){
echo.use("-R", "Shromažďuji instance: " + instance);
@ -71,10 +28,24 @@ const timeOut= (l= 500)=> AbortSignal.timeout(l);
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");
echo(JSON.stringify(out, null, " ")).to(store);
if(is_git) gitCommit([ store ], "cron");
$.exit(0);
})();
})
.parse();
function gitCommit(files, des= "not specified"){
if(!files.length || !s.run`git diff --numstat`.trim())
return echo("Nothig todo");
echo("Diff to save");
s.run`git config user.name "Bot"`;
s.run`git config user.email "${"zc.murtnec@naj.elrdna".split("").reverse().join("")}"`;
s.run`git add ${files}`;
s.run`git commit -m "Updated by bot ${des}"`;
s.run`git push`;
s.run`git config --remove-section user`;
}
async function* collectStats(instances, weeks = 1) {
for(const instance of instances){
const { stats, mau, user_count }= await fetchInstanceStats(instance).catch(e=> ({}));