evelogparse.py
· 1.4 KiB · Python
Raw
import os
import time
# Config
NAME = ["Steven Kafshaz"]
LASTMSG = {}
def filesbychannel(dirlist):
out = {}
for a in dirlist:
if a.split("_")[0] in out:
out[a.split("_")[0]].append(a)
else:
out[a.split("_")[0]] = [a]
return out
def open_log(channel):
out = {"id": 0, "name": "", "listener": "", "started": "", "topic": "", "lines": []}
with open(channel[-1], "rb") as f:
a = f.read().decode("utf_16").split("\n")
out["id"] = int(a[6].split()[-1])
out["name"] = a[7].split()[-1]
out["listener"] = a[8].split()[-1]
out["topic"] = " > ".join(a[12].split(" > ")[1:]).strip()
out["lines"] = [parse_line(b.strip()) for b in a[13:]][:-1]
return out
def parse_line(line):
out = {"timestamp": "", "fromusr": "", "text": ""}
try:
ts = " ".join(line.split(" ")[1:3])
out["timestamp"] = int(time.mktime(time.strptime(ts, "%Y.%m.%d %H:%M:%S")))
out["fromusr"] = line.split(" ] ")[1].split(" > ")[0].strip()
out["text"] = line.split(" > ")[1].strip()
return out
except (IndexError,ValueError):
return None
def match(text):
return NAME[0] in text
out = {}
for a in NAME:
out[a] = a in text
return out
"""
def main():
while True:
channels = filesbychannel(os.listdir("."))
for ch in channels:
l = open_log(channels[ch])
LATEST[ch] =
time.sleep(1)
"""
| 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 | """ |