Last active 1481585196

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

Steven Smith revised this gist 1400184193. Go to revision

1 file changed, 56 insertions

evelogparse.py(file created)

@@ -0,0 +1,56 @@
1 + import os
2 + import time
3 +
4 + # Config
5 + NAME = ["Steven Kafshaz"]
6 +
7 + LASTMSG = {}
8 +
9 + def 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 +
18 + def 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 +
29 + def 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 +
40 + def 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 + """
48 + def 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 + """
Newer Older