def logout(): try: db.update_row('t_user', 'email', current_user.id, {'watch_game_hash': ''}) logout_user() except: app.logger.info('ERROR: Exception in logout()') return redirect(url_for('index'))
def clear_watch_game(): """ Clear watched game before unload """ try: db.update_row('t_user', 'email', current_user.id, {'watch_game_hash': ''}) return jsonify({'result': 'ok'}) except: app.logger.info('ERROR: Exception in clear_watch_game()') return jsonify({'result': 'error: exception in clear_watch_game()'})
def watch_game_mobile(): """ User clicks on the game he wants to watch """ try: gh = request.args['game_hash'] live = request.args['live'] # Remember which game we are watching db.update_row('t_user', 'email', current_user.id, {'watch_game_hash': gh}) return render_template('watch_mobile.tmpl', game_hash=gh, live=live) except: app.logger.info('ERROR: Exception in watch_game_mobile()') return redirect(url_for('index'))
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'
def main(): if len(sys.argv) != 2: usage(True) n = 0 total = db.select('select count(*) from v_games_no_zobrist')[0]['count'] while (1): rows = db.select('select * from v_games_no_zobrist limit 10') #rows = db.select( "select * from t_game where game_hash = 'a7161d79bb484e77'") #BP() if len(rows) == 0: break n += len(rows) print('Updating zobrist hashes %d/%d' % (n, total)) for row in rows: try: game_hash = row['game_hash'] game = dbmodel.Game(game_hash) if not game.data['game_record']: print('No game record for game hash %s; ignoring' % game_hash) continue rec = game.data['game_record']['record'] if not rec: print('No moves for game hash %s; erasing game' % game_hash) db.update_row('t_game', 'game_hash', game_hash, {'game_record': ''}) continue if len(game.data['game_record']['var_record']) > len(rec): rec = game.data['game_record']['var_record'] moves = [x['mv'] for x in rec] rc0s = [] # Convert to 0 based 0-18 (row,col) pairs 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) db.update_row('t_game', 'game_hash', game_hash, {'zobrist': str(zobrist)}) db.tstamp('t_game', 'game_hash', game_hash, 'ts_zobrist') print('updated %s' % game_hash) except Exception as e: print( 'Exception updating zobrist for game hash %s; erasing game' % game_hash) db.update_row('t_game', 'game_hash', game_hash, {'game_record': ''}) print('Done')
def set_email_verified( self): ''' Mark email as verified ''' self.data['email_verified'] = True db.update_row( 't_user', 'email', self.id, { 'email_verified':True })
def set_password( self, password): ''' Update password ''' hashed_password = bcrypt.generate_password_hash( password).decode('utf-8') self.data['password'] = hashed_password db.update_row( 't_user', 'email', self.id, { 'password':hashed_password })
def update_db( self): ''' Write our data back to the db ''' db.update_row( 't_user', 'email', self.id, self.data)