def line_gen(basedir,chan):
subdir = chan+".chat"
sdpath = os.path.join(basedir,subdir)
fn = max(x for x in os.listdir(sdpath) if x.endswith(".txt"))
path = os.path.join(sdpath,fn)
ch = chan.encode('utf-8')
for x in tail_f(path):
if x == EWOULDBLOCK:
continue
s = x.encode('utf-8')
time,name,rest = split_line(s)
if name[-1] == ':'.encode('utf-8'):
t = colored(time,'cyan',attrs=['bold'])
c = colored(ch,'cyan',attrs=['bold'])
n = colored(name,'red',attrs=['bold'])
r = highlight(rest)
else:
t = colored(time,'cyan')
c = colored(ch,'cyan')
n = colored(name,'yellow',attrs=['dark'])
r = colored(rest,attrs=['dark'])
yield ' '.join((t,c,n,r))
评论列表
文章目录