Skip to content

Instantly share code, notes, and snippets.

@FWidm
Created May 24, 2017 14:21
Show Gist options
  • Save FWidm/1f26b794c3378e0d54337ae1e0c29199 to your computer and use it in GitHub Desktop.
Save FWidm/1f26b794c3378e0d54337ae1e0c29199 to your computer and use it in GitHub Desktop.
import os
import time
import winsound
import sys
class Watcher(object):
def __init__(self, filepath, search_keys):
self._cached_stamp = 0
self.filepath = filepath
self.cur = 0
# goto file end ? - currently it parses the complete file
self.initialized = False
self.initialized = True
self.search_keys = search_keys
def watch(self):
cur = 0
try:
with open(self.filepath, encoding="utf-8") as f:
f.seek(self.cur, 0)
for line in f:
if (any(key in line.lower() for key in self.search_keys)):
x = line
print(line)
winsound.PlaySound("*", winsound.SND_ALIAS)
self.cur = f.tell()
except IOError as e:
pass
watcher = Watcher("D:\Grinding Gear Games\Path of Exile\logs\Client.txt", ["Rama", "kinslayer"])
watcher.watch()
while True:
try:
time.sleep(.2)
if (watcher.initialized):
watcher.watch()
except KeyboardInterrupt:
print('\nDone')
break
except:
print(f'Unhandled error: {sys.exc_info()[0]}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment