"""ConversationEvent base class and subclasses. These classes are wrappers for hangouts_pb2.Event instances. Parsing is done through property methods, which prefer logging warnings to raising exceptions. """ import logging from hangups import parsers, message_parser, user, hangouts_pb2 logger = logging.getLogger(__name__) chat_message_parser = message_parser.ChatMessageParser() class ConversationEvent(object): """An event which becomes part of the permanent record of a conversation. This corresponds to hangouts_pb2.Event. This is the base class for such events. """ def __init__(self, event): self._event = event # Event @property def timestamp(self): """A timestamp of when the event occurred.""" return parsers.from_timestamp(self._event.timestamp)
def parse_text(text): parser = message_parser.ChatMessageParser() return [(s.text, s.params) for s in parser.parse(text)]