Skip to content

Instantly share code, notes, and snippets.

@cyroxx
Created March 26, 2012 00:37
Show Gist options
  • Save cyroxx/2201891 to your computer and use it in GitHub Desktop.
Save cyroxx/2201891 to your computer and use it in GitHub Desktop.
Quick and dirty XMLCard parser. Converts the base64-encoded word salad into a human-readable log.
from lxml import etree
from time import *
import base64
TIME_FORMAT = '%d.%m.%y %H:%M'
FILENAME = 'XMLCard.xml'
f = open(FILENAME)
a = etree.parse(f)
name = a.getroot()[0].attrib['nick'] # or 'disp' for the display name
for el in a.getroot()[0][0]:
t = localtime(float(el.attrib['time']))
t = strftime(TIME_FORMAT, t)
flag = int(el.attrib['flag'])
# identify who said that
who = None
if flag == 4 or flag == 20:
who = name
elif flag == 18:
who = 'Me'
decoded_msg = base64.decodestring(el.text)
# cut off after the first null byte we find
trimmed_msg = decoded_msg[:decoded_msg.find('\x00')]
print "[%s] %s: %s" % (t, who, trimmed_msg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment