Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
turn weechat logs into html
<!doctype html>
<html lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="Nathan Bergey">
<link href=',700|PT+Sans:400,700,400italic' rel='stylesheet' type='text/css'>
<link href="/resources/css/bootstrap.min.css" rel="stylesheet">
<link href="/resources/css/style.css" rel="stylesheet">
<title>PSAS IRC Log</title>
<div class="wrapper">
<div id="header">
<div class="container">
<div id="content">
<div class="container">
<h1>#psas IRC Log</h1>
<div id="log">
<pre>{% for line in log %}<span class="time">{{ line['t'] }}</span> <span class="nick {{ line['c'] }} {%if line['bot'] %}bot{% endif %}">{{ line['nick'] }}</span> <span class="break">|</span> <span class="message">{{ line['msg'] }}</span>
{% endfor %}</pre>
<div id="footer">
<div class="container">
<a class="pull-right" href="#">Back to top</a>
made by @natronics in the fabulous hipster paradise of Portland, Ore.
#!/usr/bin/env python
import datetime
from jinja2 import Template
# get a logfile
logfile = 'irc.psas.#psas.weechatlog'
# template
template = Template(open('log.html', 'r').read())
# ignore usesr:
ignore = ['github']
# ignore join/part messages
joins = ['-->', '--', '<--']
# things that are bots
bots = ['psasbot']
# number of colours (lets you have css class [a,b,c ... Nc]
Nc = 7
log = []
nicks = []
with open(logfile, 'r') as f_in:
for line in f_in:
li = line.split('\t')
time = li[0]
nick = li[1]
message = li[2:]
if nick not in ignore+joins:
time = datetime.datetime.strptime(time, '%Y-%m-%d %H:%M:%S')
bot = False
if nick in bots:
bot = True
c = ''
if nick not in nicks:
c = nicks.index(nick) % Nc
c = chr(97+c)
nick = ' '*(15 - len(nick)) + nick
log.append({'t': time.strftime('%H:%M:%S'), 'nick': nick, 'c': c, 'bot': bot, 'msg': ' '.join(message).strip()})
print template.render(log=log)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment