-
-
Save Thynix/828ae905d902dc70f8dc to your computer and use it in GitHub Desktop.
turn weechat logs into html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<head> | |
<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="natronics.org"> | |
<meta name="author" content="Nathan Bergey"> | |
<link href='http://fonts.googleapis.com/css?family=Arvo:400,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> | |
</head> | |
<body> | |
<div class="wrapper"> | |
<div id="header"> | |
<div class="container"> | |
<h1>natronics.org</h1> | |
</div> | |
</div> | |
<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> | |
</div> | |
</div> | |
</div> | |
<div id="footer"> | |
<div class="container"> | |
<a class="pull-right" href="#">Back to top</a> | |
<p> | |
made by @natronics in the fabulous hipster paradise of Portland, Ore. | |
</p> | |
</div> | |
</div> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 = '' | |
else: | |
if nick not in nicks: | |
nicks.append(nick) | |
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