python code for app
python code for app
# This code outlines a basic API for a board game rental service.
app = Flask(__name__)
customers = [
{"name": "Alice", "preferred_genres": ["Strategy", "Party"], "rental_history":
[1, 3]},
{"name": "Bob", "preferred_genres": ["Family"], "rental_history": [2]},
]
rentals = []
if not game:
return jsonify({"error": "Game not found"}), 404
if not customer:
return jsonify({"error": "Customer not found"}), 404
if not game['available']:
return jsonify({"error": "Game is currently unavailable"}), 400
game['available'] = False
rental = {"game_id": game_id, "customer_name": customer_name}
rentals.append(rental)
# Update customer's rental history
customer['rental_history'].append(game_id)
if not game:
return jsonify({"error": "Game not found"}), 404
if game['available']:
return jsonify({"error": "Game is already marked as available"}), 400
game['available'] = True
rentals[:] = [rental for rental in rentals if rental['game_id'] != game_id]
if not customer:
return jsonify({"error": "Customer not found"}), 404
preferred_genres = customer['preferred_genres']
rented_games = customer['rental_history']
recommended_games = [
game for game in games
if game['genre'] in preferred_genres and game['id'] not in rented_games and
game['available']
]
if __name__ == '__main__':
app.run(debug=True)