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

# Lists the users who have connected in
# the last week for the stats page at
# https://tilde.institute/stats

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()