Last active 1481585196

EVE Online unfinished chat log parser. Contains some useful functions.

evelogparse.py Raw
1import os
2import time
3
4# Config
5NAME = ["Steven Kafshaz"]
6
7LASTMSG = {}
8
9def filesbychannel(dirlist):
10 out = {}
11 for a in dirlist:
12 if a.split("_")[0] in out:
13 out[a.split("_")[0]].append(a)
14 else:
15 out[a.split("_")[0]] = [a]
16 return out
17
18def open_log(channel):
19 out = {"id": 0, "name": "", "listener": "", "started": "", "topic": "", "lines": []}
20 with open(channel[-1], "rb") as f:
21 a = f.read().decode("utf_16").split("\n")
22 out["id"] = int(a[6].split()[-1])
23 out["name"] = a[7].split()[-1]
24 out["listener"] = a[8].split()[-1]
25 out["topic"] = " > ".join(a[12].split(" > ")[1:]).strip()
26 out["lines"] = [parse_line(b.strip()) for b in a[13:]][:-1]
27 return out
28
29def parse_line(line):
30 out = {"timestamp": "", "fromusr": "", "text": ""}
31 try:
32 ts = " ".join(line.split(" ")[1:3])
33 out["timestamp"] = int(time.mktime(time.strptime(ts, "%Y.%m.%d %H:%M:%S")))
34 out["fromusr"] = line.split(" ] ")[1].split(" > ")[0].strip()
35 out["text"] = line.split(" > ")[1].strip()
36 return out
37 except (IndexError,ValueError):
38 return None
39
40def match(text):
41 return NAME[0] in text
42 out = {}
43 for a in NAME:
44 out[a] = a in text
45 return out
46
47"""
48def main():
49 while True:
50 channels = filesbychannel(os.listdir("."))
51 for ch in channels:
52 l = open_log(channels[ch])
53 LATEST[ch] =
54
55 time.sleep(1)
56"""