Skip to content

Instantly share code, notes, and snippets.

@FWidm
Created June 16, 2019 18:45
Show Gist options
  • Save FWidm/5122b37607aefc206bcbb9ebefa6abe4 to your computer and use it in GitHub Desktop.
Save FWidm/5122b37607aefc206bcbb9ebefa6abe4 to your computer and use it in GitHub Desktop.
import time
import winsound
import re
from datetime import datetime
class ChatLine:
def __init__(self, date, chat_type, clan, name, content) -> None:
self.date_str = date
self.chat_type = self._determine_type(chat_type)
self.clan = clan
self.name = name
self.content = content
self.date = datetime.strptime(date, "%Y/%m/%d %H:%M:%S")
def _determine_type(self, type_str: str) -> str:
switcher = {
None: "Local",
"%": "Party",
"#": "Global",
"&": "Guild",
"@From": "Whisper",
"$": "Trade"
}
return switcher.get(type_str, "???")
def __repr__(self) -> str:
return f"{self.date.isoformat()}: {self.chat_type} {self.name} [{self.clan}]: {self.content}"
def follow(file):
file.seek(0, 2)
while True:
line = file.readline()
if not line:
time.sleep(0.1)
continue
yield line
def parse_line(line):
pattern = r"(?P<date>.*? .*?) .*?(?P<chat_type>\$|\#|\@From|\%|\&|\@From|\&) *(?P<clan><.*?>)*(?P<name>.*?:) *(?P<content>.*)"
match = re.search(pattern, line)
if match:
date = match.group("date")
chat_type = match.group("chat_type")
clan = match.group("clan")
name = match.group("name")
content = match.group("content")
return ChatLine(date, chat_type, clan, name, content)
if __name__ == '__main__':
# Path to your client.txt file
path = 'D:/Grinding Gear Games/logs/Client.txt'
logfile = open(path, "r", encoding="utf8")
loglines = follow(logfile)
# terms you want to be notified of
searchterms = [
"sadist's den", "sadists den", "sadist"]
# terms that will ignore the whole message regardless of search term matching
blacklist = ["wtb", "lf"]
for line in loglines:
line=line.lower()
if not any(b for b in blacklist if b in line) \
and any(term for term in searchterms if term in line):
matching_line = line.strip()
result = parse_line(matching_line)
if result:
print(result)
winsound.Beep(2500, 200)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment