breeding pairs api
This commit is contained in:
parent
1cd836b35f
commit
043299112b
2
app.py
2
app.py
@ -5,6 +5,7 @@ from src.util.utils import *
|
|||||||
from src.api.get_monsters import *
|
from src.api.get_monsters import *
|
||||||
from src.api.get_families import *
|
from src.api.get_families import *
|
||||||
from src.api.get_monster_stats import *
|
from src.api.get_monster_stats import *
|
||||||
|
from src.api.get_breeding_pairs import *
|
||||||
|
|
||||||
from src.views.serve_content import *
|
from src.views.serve_content import *
|
||||||
from src.views.breed_info import *
|
from src.views.breed_info import *
|
||||||
@ -20,6 +21,7 @@ app.teardown_request(teardown_request)
|
|||||||
app.register_blueprint(get_families_bp)
|
app.register_blueprint(get_families_bp)
|
||||||
app.register_blueprint(get_monsters_bp)
|
app.register_blueprint(get_monsters_bp)
|
||||||
app.register_blueprint(get_monster_stats_bp)
|
app.register_blueprint(get_monster_stats_bp)
|
||||||
|
app.register_blueprint(get_breeding_pairs_bp)
|
||||||
|
|
||||||
# Register Serve Content Blueprints
|
# Register Serve Content Blueprints
|
||||||
app.register_blueprint(serve_content)
|
app.register_blueprint(serve_content)
|
||||||
|
46
src/api/get_breeding_pairs.py
Normal file
46
src/api/get_breeding_pairs.py
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
from flask import Flask, jsonify, request, Blueprint
|
||||||
|
|
||||||
|
get_breeding_pairs_bp = Blueprint('breeding_pairs',__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_breeding_pairs(monster):
|
||||||
|
pairs = []
|
||||||
|
for entry in breeding_info:
|
||||||
|
if entry['base'].lower() == monster.lower() or entry['mate'].lower() == monster.lower():
|
||||||
|
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('/breeding-pairs/<monster>', methods=['GET'])
|
||||||
|
def breeding_pairs(monster):
|
||||||
|
pairs = get_breeding_pairs(monster)
|
||||||
|
return jsonify({'breeding_pairs': pairs})
|
||||||
|
|
||||||
|
#@app.route('/usage-list/<monster>', methods=['GET'])
|
||||||
|
#def usage_list(monster):
|
||||||
|
# used_in = get_usage_list(monster)
|
||||||
|
# return jsonify({'used_in': used_in})
|
||||||
|
#
|
||||||
|
|
@ -1,3 +1,4 @@
|
|||||||
|
base,mate,offspring
|
||||||
beast,dragon,Almiraj
|
beast,dragon,Almiraj
|
||||||
Saccer,dragon,Antbear
|
Saccer,dragon,Antbear
|
||||||
beast,PutrePup,Arrowdog
|
beast,PutrePup,Arrowdog
|
||||||
|
|
Loading…
Reference in New Issue
Block a user