Files
tilde-projects/Code/python/chatchecker.py
T

36 lines
1.3 KiB
Python
Raw Normal View History

2015-08-24 10:04:57 -05:00
#!/usr/bin/python
import fileinput
import json
import time
import calendar
import shutil
2018-01-24 20:51:54 +00:00
logfile = "/home/archangelic/irc/log"
#logfile = "/home/jumblesale/Code/irc/log"
2015-08-24 10:04:57 -05:00
outfile = "/home/krowbar/logs/userData.json"
userData = {} #hash keyed by "user" that contains an array of timestamps
2015-10-13 08:23:17 -05:00
#we only care about recent chats, let's say for the past couple weeks
oneWeek = 7 * 24 * 60 * 60
fiveMinutes = 5 * 60
timeCutoff = calendar.timegm(time.gmtime()) - (5 * oneWeek)
2015-08-24 10:04:57 -05:00
with open(logfile, "r") as log:
for line in log:
try:
time, user, message = line.split("\t", 3)
time = int(time)
except ValueError:
continue #There are some bad lines in the log file that we'll ignore if we can't parse
if time > timeCutoff:
2015-10-13 08:23:17 -05:00
#standardize all times into a single "week"
#time %= oneWeek
2015-08-24 10:04:57 -05:00
#if the user already exists in the list
if user in userData:
2015-10-13 08:23:17 -05:00
if time < userData[user][-1] + fiveMinutes:
continue #only record times that are at least five minutes apart
2015-08-24 10:04:57 -05:00
userData[user].append(time) #append the new time
else: #if they are new
userData[user] = [time] #create a new list
with open(outfile + ".tmp", "w") as tmpFile:
tmpFile.write(json.dumps(userData))
shutil.move(outfile + ".tmp", outfile)