#!/bin/sh -e
# This script is run by cron once a day.

exec > "$HOME/public_gemini/activity/index.gmi"

printf '# Active users on ctrl-c.club\n\n'
printf 'Top 20 users sorted by total size of gemini posts:\n'

find /home/*/public_gemini/ -type f -name \*.gmi -ls 2>/dev/null |
        awk '{sizes[$5] += $7; counts[$5]++}
                END {
			cmd = "sort -rnk3 | head -20";

			for (i in sizes)
				printf "=> /~%-15s %-10d\t%s\n", i, sizes[i], i | cmd;
			close(cmd);

			printf "\nTop 20 users sorted by total number of gemini pages:\n"
			for (i in counts)
				printf "=> /~%-15s %-10d\t%s\n", i, counts[i], i | cmd;
	}'

printf "\n=> activity.sh.txt This page is generated by this script.\n"
