import re from typing import Dict from million.model.message import Message import million.analyze.dns_solver as dns _memoization: Dict[Message, int] = {} _dns_solver: dns.DNS_solver = dns.DNS_solver() def get(msg: Message) -> int: """ Returns the estimated value counted in this message """ return _memoization.get(msg, _compute(msg)) def reset(msg: Message) -> None: """ Drop memorized value of this Message """ if msg in _memoization: _memoization.pop(msg) def reset() -> None: """ Drop every memorized message value """ _memoization.clear() def _compute(msg: Message) -> int: value = _dns_solver.solve(msg) or _computeContent(msg) or None _memoization[msg] = value return value # 1🍁 pour 1420 ? # @Elias Cheddar pour 69 ? def _computeContent(msg: Message) -> int: if not msg.content: return s = re.sub(r'[^\s\d.,]|[.,]{2,}',"", msg.content) match = re.search(r"\d+", s) if match: return int(match.group()) return None