list2form : gestion des erreurs et des petits fichiers (merci cgi.py…)
[progfou.git] / empathy / empathy-log2moin.py
CommitLineData
10e8b1e0
P
1#! /usr/bin/env python
2# -*- coding: UTF-8 -*-
3# Auteur: Jean Christophe André
4# Licence: Public Domain
5# Created: 2008-05-30
6
7from sys import argv
8from xml.dom import minidom
9from time import *
10
11aliases = {
12 u'Jean Christophe André': u'progfou',
13}
14
15result = ''
16last_day = False
17
18xmldoc = minidom.parse(argv[1]).documentElement
19for message in xmldoc.getElementsByTagName('message'):
20 # récupérer l'heure
21 time = strptime(message.getAttribute('time'), '%Y%m%dT%H:%M:%S')
22 timestamp = mktime(time) + 7 * 3600
23 time = localtime(timestamp)
24
25 # récupérer l'autheur
26 name = message.getAttribute('name')
27 if aliases.has_key(name):
28 name = aliases[name]
29
30 # récupérer le texte
31 text = ''
32 for child in message.childNodes:
33 child_text = message.firstChild.wholeText
34 child_text = child_text.replace(u'\uFEFF','')
35 child_text = child_text.replace("\n","\n <> ")
36 text += child_text
37
38 # construire la ligne de log IRC
39 if message.getAttribute('type') == 'normal':
40 day = strftime("%d/%m", time)
41 if day != last_day:
42 if last_day:
43 result += "}}}\n"
44 result += "== " + day + " ==\n{{{#!irc\n"
45 last_day = day
46 result += strftime('%H:%M', time)
47 result += ' <' + name + '> ' + text + "\n"
48 elif message.getAttribute('type') == 'action':
49 result += '* <' + name + '> ' + text + "\n"
50
51result += "}}}\n"
52print result.encode('utf-8')