diff --git a/trader.py b/trader.py index a78a009..8fdcb08 100644 --- a/trader.py +++ b/trader.py @@ -9,6 +9,11 @@ import logging log = logging.getLogger(__name__) logging.basicConfig(level=logging.DEBUG) + +re_log = re.compile('(?P\d\d\d\d/\d\d/\d\d \d\d:\d\d:\d\d) (\d+) (\S+) \[(?P\S+) (\S+) (\d+)\] (?P[#@%$&]?)(?P<\S+>)? ?(?P[^:]+): (?P.*)') +re_trade = re.compile('Hi, I would like to buy your (?P.+) listed for (?P\d+) (?P\S+) in (?P\S+) \(stash tab "(?P.+)"; position: left (?P\d+), top (?P\d+)\)' +) + class Channel(Enum): WHISPER = 0 GLOBAL = 1 @@ -67,9 +72,7 @@ class Message(): def parse_trade(self) -> Trade: - # @From NyhaiPuki: Hi, I would like to buy your level 21 23% Vaal Impurity of Lightning listed for 18 chaos in Ritual (stash tab "$"; position: left 22, top 5) - regex = 'Hi, I would like to buy your (?P.+) listed for (?P\d+) (?P\S+) in (?P\S+) \(stash tab "(?P.+)"; position: left (?P\d+), top (?P\d+)\)' - res = re.search(regex, self.message) + res = re_trade.search(self.message) return Trade(item=res['item'], amount=int(res['amount']), currency=res['currency'], @@ -90,8 +93,7 @@ def follow(thefile: str): def parse_string(text: str) -> Message: - result = re.search( - '(?P\d\d\d\d/\d\d/\d\d \d\d:\d\d:\d\d) (\d+) (\S+) \[(?P\S+) (\S+) (\d+)\] (?P[#@%$&]?)(?P<\S+>)? ?(?P[^:]+): (?P.*)', text) + result = re_log.search(text) if not result: log.debug(f'Result is none for text "{text}"') return None