slotUI/logger.py

Wed, 26 Jun 2013 11:11:04 +0200

author
Malte Bayer <mbayer@neo-soft.org>
date
Wed, 26 Jun 2013 11:11:04 +0200
changeset 140
f910ad6ed0b6
parent 137
94d71156517b
permissions
-rw-r--r--

client binary protocol implementation

class eventLogger:
    def __init__(self, filename):
        self.filename = filename

    def push(self, data):
        """Pushes data to logfile CSV output:
        struc:
            unix timestamp
            system clock
            rennbezeichnung
            slot
            slotname (player)
            runde
            letzte rundenzeit
            beste rundenzeit
            laplimit
            timelimit
        """
        try:
            fd = open(self.filename, 'a')
            ok = True
        except:
            ok = False
        if not ok:
            fd = open(self.filename, 'w')
        if ok:
            fd.write("%s;%s;\"%s\";%s;\"%s\";%s;%s;%s;%s;%s\n" % (
                data[0],
                data[1],
                data[2],
                data[3],
                data[4],
                data[5],
                data[6],
                data[7],
                data[8],
                data[9]
                ))
            fd.close()

mercurial