2 # -*- coding: utf-8 -*-
8 from urlparse import urlparse
9 from email.utils import parseaddr
10 from lxml import etree
11 from lxml.builder import ElementMaker
12 from treecutter import constants as const
14 def append_text(tree, text):
15 children = tree.getchildren()
17 if children[-1].tail is None:
18 children[-1].tail = text
20 children[-1].tail += text
29 db = ElementMaker(namespace=const.DB_NS, nsmap=const.NSMAP)
30 ent = db.entry(align="center")
31 r = re.search(r"(?P<url>https?://[^ ]+)\|(?P<title>[\w\-\.]+)", text)
33 rep = r.groups(r.group(1))
34 ent.append(db.link(rep[1],**{const.XLINK+"href": rep[0]}))
40 if n[0] != '' and n[1] != '':
41 ent.append(db.address(db.personname(db.firstname(n[0].split(' ')[0]), db.surname(n[0].split(' ')[1])),db.email(n[1])))
49 def __init__(self, tablefile, title):
50 self.tablefile = tablefile
55 f = codecs.open(self.tablefile, encoding='utf-8')
57 c = re.split(r'\t+', line.rstrip())
61 db = ElementMaker(namespace=const.DB_NS, nsmap=const.NSMAP)
63 nrcol = str(len(cols[0]))
64 if cols[0][0][0] == '*':
65 cols[0][0] = cols[0][0][1:]
69 row.append(linkify(e))
76 row.append(linkify(e))
77 tab = db.table(db.title(self.title),
78 db.tgroup(head,body,cols=nrcol,
79 colsep='1',rowsep='1',align='left'),
83 if __name__ == "__main__":
84 for arg in sys.argv[1:]:
89 argument = al[1].decode('utf-8')
91 (tablefile, title) = argument.split('|')
92 tab = Table(tablefile,title)
96 sys.stdout.write(etree.tostring(txml,encoding='UTF-8',pretty_print=False))