#!/usr/bin/env python import sys import re import string from textwrap import * wrapper = TextWrapper() wrapper.width = 70 wrapper.initial_indent = "" wrapper.subsequent_indent = " " wrapper.break_long_words = False wrapper.break_on_hyphens = False regex_irc = re.compile("^\((.*)\) ([^:]*): (.*)$") regex_pre = re.compile("\
")
regex_url = re.compile(".*(https*:[^\s,\(\)]+).*")
regex_dot = re.compile("\.$")
last_speaker = None
for line in sys.stdin:
m = regex_irc.match(line)
if m:
timestamp = m.group(1)
speaker = m.group(2)
comment = m.group(3)
u = regex_url.match(comment)
if u:
url = u.group(1)
url = regex_dot.sub('', url)
#sys.stderr.write("url = %s\n" % (url))
link = '%s' % (url, url)
r = re.compile(url)
comment = r.sub(link, comment)
comment = wrapper.fill(comment)
if speaker == last_speaker:
print " %s\n" % (comment)
else:
last_speaker = speaker
print "%s: %s\n" % (speaker, comment)
elif regex_pre.search(line):
print regex_pre.sub("", line, count=1)
else:
last_speaker = None
print line