Ejemplo n.º 1
0
def log_entry ( req, scoreent, rank ):

    # base game path
    writepath = actlogfullpath ( req )

    # req [ 'gamename' ]
    # req [ 'prid' ]
    # scoreent [ 'score' ]
    # scoreent [ 'time' ] # as int, not float, epoch

    d = dict()
    d [ 'gamename' ] = req [ 'gamename' ]
    d [ 'prid' ] = req [ 'prid' ]
    d [ 'score' ] = scoreent [ 'score' ]
    d [ 'time' ] = scoreent [ 'time' ]
    d [ 'rank' ] = rank
    d [ '_target' ] = 'MONTHLY'
    try:
        if req [ '_backdate' ] == 'ALLTIM':
            d [ '_target' ] = 'ALLTIME'
    except:
        pass

    log = _readlog ( req )

    log.insert ( 0, d ) # insert to head
    log.pop() # drop last entry, so we maintain size

    _writelog ( req, log )

    return None
Ejemplo n.º 2
0
def _writelog ( req, log ):
    writepath = actlogfullpath ( req )

    logj = json.dumps ( log )

    f = open ( writepath, "w" )
    f.write ( logj )
    f.close()

    return None
Ejemplo n.º 3
0
def _readlog ( req ):

    writepath = actlogfullpath ( req )

    try:
        f = open ( writepath, "r" )
        logfile = f.read()
        f.close()

        log = json.loads ( logfile )

    except:
        logging.warning ( "assuming new actlog file" )

        log = list()
        for i in range ( logsize() ):
            log.append ( { 'gamename': '', 'prid': '_default_', 'score': 0, 'time': 0, 'rank': 0 } )

    return log