Continous read of the log file
This commit is contained in:
commit
ccebedce22
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
.venv
|
59
trader.py
Normal file
59
trader.py
Normal file
@ -0,0 +1,59 @@
|
||||
import watchdog
|
||||
import argparse
|
||||
import time
|
||||
from parse import parse
|
||||
import datetime
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class Channel(Enum):
|
||||
WHISPER = 0
|
||||
GLOBAL = 1
|
||||
PARTY = 2
|
||||
LOCAL = 3
|
||||
TRADE = 4
|
||||
GUILD = 5
|
||||
|
||||
|
||||
channel_mapping = {'#': Channel.GLOBAL,
|
||||
'@': Channel.WHISPER,
|
||||
'%': Channel.PARTY,
|
||||
'': Channel.LOCAL,
|
||||
'$': Channel.TRADE,
|
||||
'&': Channel.GUILD}
|
||||
|
||||
def follow(thefile: str):
|
||||
thefile.seek(0, 2)
|
||||
while True:
|
||||
line = thefile.readline()
|
||||
if not line:
|
||||
time.sleep(0.1)
|
||||
continue
|
||||
yield line
|
||||
|
||||
|
||||
def parse_string(text: str):
|
||||
result = parse('{date} {time} {timemicro} {noidea} [{level} {client} {id}]{mess_type:1}{user}: {message}', text)
|
||||
# date = datetime.datetime.strptime(f'{result["date"]} {result["time"]}', '%Y/%m/%d %H:%M:%S')
|
||||
# print(f'{date.isoformat()}: {result["message"]}')
|
||||
print(text)
|
||||
print(result)
|
||||
|
||||
|
||||
def setup_args() -> argparse.Namespace:
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Poe Trader', epilog="And that's how you trade")
|
||||
|
||||
parser.add_argument(
|
||||
'-l', '--logfile', help='Path of the logfile that should be used', default=r'D:\Poe\logs\Client.txt')
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
args = setup_args()
|
||||
logfile = open(args.logfile, 'r', encoding='utf8')
|
||||
loglines = follow(logfile)
|
||||
for line in loglines:
|
||||
parse_string(line)
|
||||
# print(line)
|
Loading…
x
Reference in New Issue
Block a user