Created
March 26, 2012 00:37
-
-
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.
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
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