""" copy(Array.from(document.querySelectorAll('._3oh-')).map(n => n.innerText).join('\n')); save to 'chat.txt' usage: python chat.py < chat.txt > chat.html enjoy. """ import re import sys from collections import Counter, namedtuple text = sys.stdin.read() lines = text.split('\n') participants = map(lambda x: x[0], Counter(lines).most_common(2)) ChatBlock = namedtuple('ChatBlock', ['participant', 'messages']) chat = [] current_block = None for line in lines: if re.match(r'^\d\d?:\d\d(AM|PM)$', line): pass elif line in participants: if current_block: chat.append(current_block) current_block = ChatBlock(participant=line, messages=[]) else: current_block.messages.append(line) if current_block: chat.append(current_block) print """
""" for block in chat: print '
'.format(participants.index(block.participant)) print '

{}

'.format(block.participant) for message in block.messages: print '
{}
'.format(message) print '
' print """