def get_user_data(user_id): cookies = request.cookies with connect(DSN) as connection: with connection.cursor(cursor_factory=RealDictCursor) as cursor: if 'token' in cookies: cursor.execute(Users.get_user_id(), cookies) record = cursor.fetchone() try: follower_id = record['user_id'] except KeyError: cursor(Users.logout(), cookies) follower_id = 0 else: follower_id = 0 cursor.execute(Users.get_user_data(), { 'id': user_id, 'follower_id': follower_id }) profile = cursor.fetchone() put_out_contacts(profile) return jsonify(converts_keys(profile, case='camel'))