def out(line):
    with open(output + "/account_stats.txt", "a") as f:
        f.write(str(line) + "\n")


out(datetime.datetime.today())

has = 0
cannot = 0
last_week = 0
last_month = 0
oneweekago = datetime.datetime.today() - datetime.timedelta(days=7)
onemonthago = datetime.datetime.today() - datetime.timedelta(days=30)
dnet = MoodleDBConnection()
raw = dnet.call_sql("select lastaccess,lastlogin,idnumber from ssismdl_user where idnumber like '%P' and deleted=0")
total = len(raw)

for line in raw:
    lastaccess, lastlogin, idnumber = line
    lastaccess_date = convert(lastaccess)
    lastlogin_date = convert(lastlogin)
    if lastaccess and not lastlogin:
        cannot += 1
    if lastlogin:
        has += 1
    if lastlogin_date > oneweekago:
        last_week += 1
    if lastlogin_date > onemonthago:
        last_month += 1
out("{} total DragonNet parent accounts".format(total))