Last active
January 9, 2020 15:26
-
-
Save icy/5a9fadfb3c123061c62ef6db96545431 to your computer and use it in GitHub Desktop.
telegram-group-stats.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# license : mit | |
# author : kyanh-huynh | |
# purpose : print stats from telegram group exported data | |
members() { | |
grep -Ee '(invited|joined|date details)' messages* \ | |
|grep -v http \ | |
|sed -E -e 's#^.+joined.+#foobar.html:joined#g' \ | |
-E -e 's#^.+title="[0-9]+\.(.+) .*#bar.html: \1#g' \ | |
| awk 'BEGIN{p=0}{if ($0 ~ /bar.html/) { if (p>0) ; p=0; date=$2; } | |
else { printf("%s: %s\n", date, $0) > "/dev/stderr"; p+=1 ; stats[date] += 1;} | |
} END{ for (d in stats) {printf("%s %s\n", d, stats[d]);};}' \ | |
|sed -e 's/\./ /g' \ | |
|sort -n -k 2 \ | |
|awk 'BEGIN{s=0}{s+=$3; printf("%s-%s %s %s\n", $1, $2, $3, s)}' | |
} | |
posts() { | |
grep -Ee 'date details" title="' messages* \ | |
|grep -v http \ | |
|sed -E -e 's#^.+title="[0-9]+\.(.+) .*#bar.html: \1#g' \ | |
| awk '{if ($0 ~ /bar.html/) { date=$2; stats[date] += 1;} } | |
END{ for (d in stats) {printf("%s %s\n", d, stats[d]);};}' \ | |
|sed -e 's/\./ /g' \ | |
|sort -n -k 2 \ | |
|awk 'BEGIN{s=0}{s+=$3; printf("%s-%s %s %s\n", $1, $2, $3, s)}' \ | |
|column -t | |
} | |
plt_posts() { | |
cat <<'EOF' | |
set terminal jpeg | |
set output 'stats-posts.jpeg' | |
set title 'linuxvn posts' | |
set xtic rotate | |
plot "stats.txt" using 3:xticlabel(1) with lines | |
EOF | |
} | |
plt_members() { | |
cat <<'EOF' | |
set terminal jpeg | |
set output 'stats-members.jpeg' | |
set title 'linuxvn members' | |
set xtic rotate | |
plot "stats.txt" using 3:xticlabel(1) with lines | |
EOF | |
} | |
plot_members() { | |
members > stats.txt 2>/dev/null | |
plt_members > members.plot | |
gnuplot members.plot | |
} | |
plot_posts() { | |
posts > stats.txt | |
plt_posts > posts.plot | |
gnuplot posts.plot | |
} | |
echo rm -rfv / ... "ok haha don't just copy and paste" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment