Compile regex at the beginning
This commit is contained in:
parent
b49002774a
commit
d09bbc7fca
12
trader.py
12
trader.py
@ -9,6 +9,11 @@ import logging
|
||||
log = logging.getLogger(__name__)
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
|
||||
re_log = re.compile('(?P<date>\d\d\d\d/\d\d/\d\d \d\d:\d\d:\d\d) (\d+) (\S+) \[(?P<level>\S+) (\S+) (\d+)\] (?P<channel>[#@%$&]?)(?P<guild><\S+>)? ?(?P<user>[^:]+): (?P<message>.*)')
|
||||
re_trade = re.compile('Hi, I would like to buy your (?P<item>.+) listed for (?P<amount>\d+) (?P<currency>\S+) in (?P<league>\S+) \(stash tab "(?P<tab>.+)"; position: left (?P<col>\d+), top (?P<row>\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<item>.+) listed for (?P<amount>\d+) (?P<currency>\S+) in (?P<league>\S+) \(stash tab "(?P<tab>.+)"; position: left (?P<col>\d+), top (?P<row>\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<date>\d\d\d\d/\d\d/\d\d \d\d:\d\d:\d\d) (\d+) (\S+) \[(?P<level>\S+) (\S+) (\d+)\] (?P<channel>[#@%$&]?)(?P<guild><\S+>)? ?(?P<user>[^:]+): (?P<message>.*)', text)
|
||||
result = re_log.search(text)
|
||||
if not result:
|
||||
log.debug(f'Result is none for text "{text}"')
|
||||
return None
|
||||
|
Loading…
x
Reference in New Issue
Block a user