From 831712dee72c2b68cd23d0f5732723305f67c424 Mon Sep 17 00:00:00 2001 From: 0ceanSlim Date: Thu, 22 Feb 2024 10:58:22 -0500 Subject: [PATCH] breeding usage api functional --- app.py | 2 ++ src/api/get_breeding_pairs.py | 16 +--------------- src/api/get_breeding_usage.py | 36 +++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 15 deletions(-) create mode 100644 src/api/get_breeding_usage.py diff --git a/app.py b/app.py index 92a5f83..6a73245 100644 --- a/app.py +++ b/app.py @@ -6,6 +6,7 @@ from src.api.get_monsters import * from src.api.get_families import * from src.api.get_monster_stats import * from src.api.get_breeding_pairs import * +from src.api.get_breeding_usage import * from src.views.serve_content import * from src.views.breed_info import * @@ -22,6 +23,7 @@ app.register_blueprint(get_families_bp) app.register_blueprint(get_monsters_bp) app.register_blueprint(get_monster_stats_bp) app.register_blueprint(get_breeding_pairs_bp) +app.register_blueprint(get_breeding_usage_bp) # Register Serve Content Blueprints app.register_blueprint(serve_content) diff --git a/src/api/get_breeding_pairs.py b/src/api/get_breeding_pairs.py index d8b19ee..2c85044 100644 --- a/src/api/get_breeding_pairs.py +++ b/src/api/get_breeding_pairs.py @@ -1,4 +1,4 @@ -from flask import Flask, jsonify, request, Blueprint +from flask import jsonify, Blueprint get_breeding_pairs_bp = Blueprint('breeding_pairs',__name__) @@ -26,21 +26,7 @@ def get_breeding_pairs(monster): pairs.append({'base': entry['base'], 'mate': entry['mate'], 'offspring': entry['offspring']}) return pairs -#def get_usage_list(monster): -# used_in = [] -# for entry in breeding_info: -# if entry['offspring'].lower() == monster.lower(): -# used_in.append({'base': entry['base'], 'mate': entry['mate']}) -# return used_in - @get_breeding_pairs_bp.route('/api/breeding/pairs/', methods=['GET']) def breeding_pairs(monster): pairs = get_breeding_pairs(monster) return jsonify({'breeding_pairs': pairs}) - -#@app.route('api/breeding/usage/', methods=['GET']) -#def usage_list(monster): -# used_in = get_usage_list(monster) -# return jsonify({'used_in': used_in}) -# - diff --git a/src/api/get_breeding_usage.py b/src/api/get_breeding_usage.py new file mode 100644 index 0000000..fc62c99 --- /dev/null +++ b/src/api/get_breeding_usage.py @@ -0,0 +1,36 @@ +from flask import jsonify, Blueprint + +get_breeding_usage_bp = Blueprint('breeding_usage',__name__) + +import os + +# Get the current script directory +script_dir = os.path.dirname(os.path.abspath(__file__)) + +# Construct the path to the CSV file in the data directory +csv_file_path = os.path.join(script_dir, '..', 'data', 'updated_breeding_pairs.csv') + +# Read the CSV file and store breeding information +breeding_info = [] +with open(csv_file_path, 'r') as file: + lines = file.readlines() + header = lines[0].strip().split(',') + for line in lines[1:]: + data = line.strip().split(',') + breeding_info.append(dict(zip(header, data))) + + +def get_usage_list(monster): + used_in = [] + for entry in breeding_info: + if entry['base'].lower() == monster.lower() or entry['mate'].lower() == monster.lower(): + used_in.append({'base': entry['base'], 'mate': entry['mate'], 'offspring': entry['offspring']}) + return used_in + + +@get_breeding_usage_bp.route('/api/breeding/usage/', methods=['GET']) +def usage_list(monster): + used_in = get_usage_list(monster) + return jsonify({'used_in': used_in}) + +