Skip to content

Instantly share code, notes, and snippets.

@mythmon
Last active August 29, 2015 14:13
Show Gist options
  • Save mythmon/77a48d501519a51d13e2 to your computer and use it in GitHub Desktop.
Save mythmon/77a48d501519a51d13e2 to your computer and use it in GitHub Desktop.

This parses logs from my weechat. They probably aren't the same as logs from your weechat. I run it like

$ cat ~/.weechat/logs/irc.freenode.\#osu-lug/2015-01-*.weechatlog | ./logs.py 
#!/usr/bin/env python
import re
import sys
from collections import defaultdict, Counter
def parse_line(line):
parts = line.strip().split('\t')
if len(parts) == 2:
return {
'type': 'meta',
'date': parts[0],
'message': parts[1],
}
elif len(parts) == 3:
if parts[1] in ['-->', '<--', '--']:
return parse_joinpartmode(parts)
elif parts[1].strip() == '*':
source, message = parts[2].split(' ', 1)
return {
'type': 'action',
'date': parts[0],
'source': source,
'message': message,
}
else:
return {
'type': 'message',
'date': parts[0],
'source': fix_nicks(parts[1]),
'message': parts[2],
}
else:
return {
'type': 'unknown',
'date': parts[0],
'parts': parts[1:],
}
def fix_nicks(nick):
nick = re.sub(r'_+$', '', nick)
nick = re.sub(r'^[@+]', '', nick)
return nick
def parse_joinpartmode(parts):
assert len(parts) == 3
if parts[1] == '<--':
type = 'leave'
elif parts[1] == '-->':
type = 'join'
elif parts[1] == '--':
type = 'mode'
return {
'date': parts[0],
'type': type,
'message': parts[2],
}
def average(nums):
return sum(nums) / len(nums)
class Any(object):
def __eq__(self, other):
return True
def __neq__(self, other):
return False
def main():
messages = [parse_line(line) for line in sys.stdin.readlines()]
streaks = Counter()
for msg in [m for m in messages if m['type'] in ['action', 'message']]:
streaks[msg['source']] = 0
current = Any()
for msg in [m for m in messages if m['type'] in ['action', 'message']]:
if msg['source'] == current:
streaks[msg['source']] += 1
current = msg['source']
else:
current = msg['source']
print('Streaking messages')
for rank, (nick, streaks) in enumerate(streaks.most_common(), 1):
print('#{0:>2}: {1} ({2} streaking messages)'.format(rank, nick, streaks))
#message_by_nick = defaultdict(lambda: [])
#for msg in [m for m in messages if m['type'] in ['message', 'action']]:
# message_by_nick[msg['source']].append(len(msg['message']))
#message_by_nick = defaultdict(lambda: [])
#for msg in [m for m in messages if m['type'] in ['message', 'action']]:
# message_by_nick[msg['source']].append(len(msg['message'].split(' ')))
#averages = {nick: average(word_counts) for nick, word_counts in message_by_nick.items()}
#print('Words per message')
#for rank, (nick, count) in enumerate(sorted(averages.items(), key=lambda a: a[1]), 1):
# print('#{0:>2}: {1} ({2:.2f} words/msg)'.format(rank, nick, count))
if __name__ == '__main__':
main()
2015-01-22 15:20:11 +pop` lrr: good to know.
2015-01-22 15:20:12 edunham jnoah: aren't there weechat plugins to do that clientside?
2015-01-22 15:20:27 jnoah i would think so. good point
2015-01-22 15:20:43 bryon if it spit out ONLY the title of the youtube vid, i'd probably be ok with it
2015-01-22 15:20:50 bryon but it spit too much
2015-01-22 15:20:56 lrr phrasing
2015-01-22 15:21:09 edunham bryon: again, that can be done clientside if you care
2015-01-22 15:21:16 bryon right
2015-01-22 15:21:28 bryon but i don't care to see ANY info about links
2015-01-22 15:21:32 bryon i like the mystery
2015-01-22 15:21:38 bryon what am I clicking?
2015-01-22 15:21:38 edunham brave
2015-01-22 15:21:41 bryon is it goatse?
2015-01-22 15:21:46 bryon i guess we'll find out!
2015-01-22 15:23:09 Mathuin nsfw roulette
2015-01-22 15:23:27 jnoah 50/50
2015-01-22 15:23:28 lrr isn't that just chatroulette?
2015-01-22 15:23:34 lrr or omegle?
2015-01-22 15:27:33 jnoah 50/50 subreddit *
2015-01-22 15:30:55 <-- EOBeav ([email protected]) has quit (Quit: Outa here)
2015-01-22 15:42:38 ekem ls downloads
2015-01-22 15:43:00 ekem all mah wat
2015-01-22 15:43:27 bryon ls Downloads/
2015-01-22 15:43:27 @hamper Game.of.Thrones.S01.2011.HDTV.720p.x264-KILLERS/
2015-01-22 15:43:39 * ekem calls policia
2015-01-22 15:43:43 ekem ls /
2015-01-22 15:43:57 ekem ls /home/mythmon/
2015-01-22 15:44:03 * bryon hacks ekem's phone, reroute's to his mom's 900 number.
2015-01-22 15:44:03 ekem :(
2015-01-22 15:44:11 ekem my mom is dead
2015-01-22 15:44:14 ekem you jerk
2015-01-22 15:44:21 ekem but if you can get ahold of her
2015-01-22 15:44:22 ekem im down
2015-01-22 15:44:25 bryon 900 number from beyond the grave = extra charges
2015-01-22 15:44:37 ekem (bryon_is_jerk)++
2015-01-22 15:44:39 ekem well played
2015-01-22 15:44:43 bryon =]
2015-01-22 15:44:56 bryon yo, if your mom really IS dead, condolences
2015-01-22 15:45:27 ekem my mother isnt really dead, but you sir have failed the voight-kampff test
2015-01-22 15:45:54 bryon i always say "my mom is dead" too when people bring her up
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment