import time, os, sys, textwrap black = 30 red = 31 green = 32 yellow = 33 blue = 34 purple = 35 cyan = 36 white = 37 NICKCOLORS = { 'hpk': blue, 'stakkars': green, 'pedronis': cyan, 'arigo': purple, 'arigato': purple, 'cfbolz': red, 'ericvrp': blue, 'mwh': purple, 'antocuni': red, 'dialtone': purple, 'braintone': black, 'sanxiyn': green, 'fijal': cyan, 'jgustak': white, 'lac': blue, } def colorof(name): if name.startswith('CIA-'): return black return NICKCOLORS.get(name, yellow) # ----- below: the coloring algorithm of xchat ----- # ----- but personally I prefer a uniform yellow # for all people not usually talking much ----- ##def colorof(name, TABLE=[green, red, purple, yellow, green, ## cyan, cyan, blue, purple]): ## sum = 0 ## for c in name: ## sum += ord(c) ## sum %= len(TABLE) ## return TABLE[sum] def terminal_width(): # logic taken from py.test.terminal.out try: fullwidth = int(os.environ.get('COLUMNS', 80)) except ValueError: fullwidth = 80 try: import termios,fcntl,struct call = fcntl.ioctl(0,termios.TIOCGWINSZ,"\000"*8) height, fullwidth = struct.unpack( "hhhh", call ) [:2] except: pass return fullwidth def dump_url(url, width=None): g = os.popen("lynx -source '%s'" % url, "r") dump_file(g, width=width) g.close() def dump_file(g, width=None): if width is None: width = terminal_width() - 2 for line in g: word1, word2, rest = line.split(' ', 2) if word2 == 'Action:': word2 = '*' indent = len(word1)+1+len(word2)+1 rest = textwrap.wrap(rest, width = width-indent) rest = ('\n' + ' '*indent).join(rest) if word2.startswith('<') and word2.endswith('>'): nick = word2[1:-1] elif word2 == '*': nick = rest.split(' ', 1)[0] else: nick = word2 color = colorof(nick) if nick != word2[1:-1]: rest = '\x1b[%sm%s\x1b[0m' % (color, rest) # fix for 'less': rest = rest.replace('\n', '\x1b[0m\n\x1b[%sm' % (color,)) word2 = '\x1b[%sm%s' % (color, word2) word2 = '\x1b[1m%s\x1b[0m' % word2 print '%s %s %s' % (word1, word2, rest) def parse_date(args): year, month, day = time.localtime()[:3] if args: day = int(args.pop(0)) if args: month = int(args.pop(0)) if args: year = int(args.pop(0)) return (year, month, day) DEFAULT_URL = 'http://tismerysoft.de/pypy/raw-irc-logs/%(channel)s/%%23%(channel)s.log.%(year)04d%(month)02d%(day)02d' #CMD = "ssh tismerysoft.de cat irc-logs/%(channel)s/\\\\#%(channel)s.log.%(year)04d%(month)02d%(day)02d" if __name__ == '__main__': args = sys.argv[1:] if args and not args[0].isdigit(): channel = args.pop(0) else: channel = 'pypy' year, month, day = parse_date(args) if 'DEFAULT_URL' in globals(): url = DEFAULT_URL % locals() print url sys.stdout.flush() dump_url(url) else: cmd = CMD % locals() print cmd sys.stdout.flush() g = os.popen(cmd, 'r') dump_file(g) g.close()