about summary refs log tree commit diff stats
path: root/bin/weekconns.py
blob: ed9d3755ee1b61d8afe4179429250775da974c6a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/local/bin/python3 -I

# Lists the users who have connected in
# the last week for the stats page at
# https://tilde.institute/stats
# <gbmor> ben@gbmor.dev

from sys import exit
import subprocess

def weekconns():
    try:
        conntable = open("/var/www/htdocs/table.weekconns", "w")
    except:
        print("Can't access connected user table. Who are you?")
        exit(0)

    weekconns = list(set(subprocess.check_output("last | grep tty | awk '{print $1}'; exit 0", stderr=subprocess.STDOUT,shell=True).decode().strip()))
    conntable.write(str(len(weekconns)))
    conntable.close()

if __name__ == '__main__':
    weekconns()