Exemple #1
0
 def __init__( self, email):
     self.valid = True
     self.id = email.strip().lower()
     self.data = {}
     rows = db.find( 't_user', 'email', self.id)
     if not rows:
         self.valid = False
         return
     self.data = rows[0]
Exemple #2
0
 def __init__( self, game_hash=None):
     self.valid = True
     self.data = {}
     #if not game_hash: app.logger.info('>>>>>>>>>> Game without game_hash')
     self.id = game_hash if game_hash else uuid.uuid4().hex[:16]
     rows = db.find( 't_game', 'game_hash', self.id)
     if not rows:
         self.valid = False
         return
     self.data = rows[0]
     if self.data['game_record']: # Convert json string to a python object
         self.data['game_record'] = json.loads( self.data['game_record'])
Exemple #3
0
 def createdb( self, data):
     ''' Create User in DB '''
     self.data = data
     self.data['email'] = self.id
     self.data['username'] = self.data['username'].strip()
     self.data['password'] = ''
     self.data['fname'] = self.data['fname'].strip()
     self.data['lname'] = self.data['lname'].strip()
     self.data['lang'] = 'eng'
     rows = db.find( 't_user', 'username',  self.data['username'])
     if rows:
         return 'err_user_exists'
     rows = db.find( 't_user', 'email',  self.id)
     if rows:
         return 'err_user_exists'
     db.insert( 't_user', (data,))
     db.tstamp( 't_user', 'email', self.id, 'ts_created')
     db.tstamp( 't_user', 'email', self.id, 'ts_last_seen')
     self.read_from_db()
     self.valid = True
     return 'ok'
Exemple #4
0
def find_game():
    """ Upload Sgf to find (GET) or find the game and show matches (POST) """

    # Pick sgf file we are trying to find
    if not 'action' in request.args:
        return render_template('find_game.tmpl', action='choose_file')

    # With the moves from the sgf, find the game in the DB, display link
    try:
        rc0s = []
        # Convert to 0 based 0-18 (row,col) pairs
        moves = json.loads(request.args['moves'])
        for move in moves:
            coord = move
            if coord in ('pass', 'resign'):
                rc0s.append(coord)
                continue
            point = go_utils.point_from_coords(coord)
            rc0 = (point.row - 1, point.col - 1)
            rc0s.append(rc0)
        zobrist = go_utils.game_zobrist(rc0s, ZOBRIST_MOVES)
        rows = db.find('t_game', 'zobrist', str(zobrist))

        games = []
        for row in rows:
            g = {}
            g['username'] = row['username']
            #g['handicap'] = row['handicap']
            #g['komi'] = row['komi']
            g['ts_started'] = row['ts_started'].strftime("%Y-%m-%d %H:%M")
            g['ts_latest_move'] = row['ts_latest_move'].strftime(
                "%Y-%m-%d %H:%M")
            #g['live'] = row['live']
            # Format seconds to hhmmss
            #g['t_idle'] = re.sub( r'[.].*', '' , str( timedelta( seconds=row['idle_secs'])))
            #g['nmoves'] = json.loads( row['game_record'])['n_visible']
            #g['n_obs'] = row['n_obs']
            if 'mobile' in request.url_rule.rule:
                g['link'] = url_for('watch_game_mobile',
                                    game_hash=row['game_hash'],
                                    live=0)
            else:
                g['link'] = url_for('watch_game',
                                    game_hash=row['game_hash'],
                                    live=0)
            games.append(g)
    except Exception as e:
        print('ERROR: Exception in find_game(): %s' % str(e))

    res = render_template('find_game.tmpl', action='show_games', games=games)
    return res
Exemple #5
0
 def update_db( self, data):
     """ Create or update game in DB """
     self.data.update( data)
     self.data['game_hash'] = self.id
     rows = db.find( 't_game', 'game_hash',  self.id)
     if not rows:
         db.insert( 't_game', (self.data,))
         db.tstamp( 't_game', 'game_hash', self.id, 'ts_started')
         self.valid = True
         return 'inserted'
     db.update_row( 't_game', 'game_hash', self.id, self.data)
     db.tstamp( 't_game', 'game_hash', self.id, 'ts_latest_move')
     if self.data['game_record']: # Convert json string to a python object
         self.data['game_record'] = json.loads( self.data['game_record'])
     self.valid = True
     return 'updated'
Exemple #6
0
 def read_db( self):
     """ Read our data from the db """
     data = db.find( 't_game', 'game_hash', self.id)[0]
     self.data.update( data)
Exemple #7
0
 def read_from_db( self):
     ''' Read our data from the db '''
     data = db.find( 't_user', 'email', self.id)[0]
     self.data.update( data)