From 4bcb98f2c13348a244cfcf92b3c78dfc48ed3995 Mon Sep 17 00:00:00 2001 From: 0ceanSlim Date: Wed, 14 Feb 2024 15:55:41 -0500 Subject: [PATCH] src dir setup, some utils moved --- app.py | 115 +++++++++++++++++++--- src/api/__innit__.py | 0 src/{ => data}/database.db | Bin src/{ => data}/skills_data.csv | 0 src/{ => data}/updated_breeding_pairs.csv | 0 src/python/__innit__.py | 4 - src/python/breed.py | 99 ------------------- src/routes/__innit__.py | 0 src/util/__innit__.py | 0 src/util/utils.py | 14 +++ static/style/output.css | 15 +-- 11 files changed, 119 insertions(+), 128 deletions(-) create mode 100644 src/api/__innit__.py rename src/{ => data}/database.db (100%) rename src/{ => data}/skills_data.csv (100%) rename src/{ => data}/updated_breeding_pairs.csv (100%) delete mode 100644 src/python/__innit__.py delete mode 100644 src/python/breed.py create mode 100644 src/routes/__innit__.py create mode 100644 src/util/__innit__.py create mode 100644 src/util/utils.py diff --git a/app.py b/app.py index 8b5f253..bd6148a 100644 --- a/app.py +++ b/app.py @@ -1,16 +1,11 @@ from flask import Flask, render_template, g, abort, request, jsonify, send_from_directory, url_for -import sqlite3, os, csv -from src.python.breed import get_breed_id, get_breeding_pairs, get_used_in_breeds +import os + +from src.util.utils import * app = Flask(__name__) -DATABASE = "src/database.db" - - -def connect_db(): - return sqlite3.connect(DATABASE) - @app.before_request def before_request(): @@ -221,14 +216,104 @@ def get_breeding_combinations(): }, used_in_breeds=used_in_breeds, ) + +def get_used_in_breeds(target_monster): + cursor = g.db.cursor() -def read_csv(file_path): - data = [] - with open(file_path, 'r', newline='', encoding='utf-8') as csvfile: - reader = csv.DictReader(csvfile) - for row in reader: - data.append(row) - return data + # Fetch breed IDs where the selected monster is used as a base + cursor.execute( + """ + SELECT breed_id + FROM breed_requirements + WHERE requirement_type = 'base' + AND requirement_value = ? + """, + (target_monster,), + ) + + base_breed_ids = [row[0] for row in cursor.fetchall()] + + # Fetch breed IDs where the selected monster is used as a mate + cursor.execute( + """ + SELECT breed_id + FROM breed_requirements + WHERE requirement_type = 'mate' + AND requirement_value = ? + """, + (target_monster,), + ) + + mate_breed_ids = [row[0] for row in cursor.fetchall()] + + # Combine the results from both queries + used_in_breed_ids = base_breed_ids + mate_breed_ids + + # Fetch the target monsters for the obtained breed IDs + used_in_breeds = [] + for breed_id in used_in_breed_ids: + cursor.execute( + """ + SELECT target + FROM breeds + WHERE id = ? + """, + (breed_id,), + ) + target_monster = cursor.fetchone() + if target_monster: + used_in_breeds.append(target_monster[0]) + + return used_in_breeds + +def get_breed_id(target_monster): + cursor = g.db.cursor() + + # Fetch breed ID based on the selected monster as a target + cursor.execute( + """ + SELECT breeds.id + FROM breeds + WHERE breeds.target = ? + """, + (target_monster,), + ) + + breed_id = cursor.fetchone() + + if breed_id: + return breed_id[0] + else: + return None + + +def get_breeding_pairs(breed_id): + cursor = g.db.cursor() + + # Fetch base and mate breeding combinations based on the breed ID + cursor.execute( + """ + SELECT requirement_type, requirement_value + FROM breed_requirements + WHERE breed_id = ? + """, + (breed_id,), + ) + + breeding_info = cursor.fetchall() + + base_pair = [ + value + for (requirement_type, value) in breeding_info + if requirement_type == "base" + ] + mate_pair = [ + value + for (requirement_type, value) in breeding_info + if requirement_type == "mate" + ] + + return base_pair, mate_pair @app.route('/skills') def skills(): diff --git a/src/api/__innit__.py b/src/api/__innit__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/database.db b/src/data/database.db similarity index 100% rename from src/database.db rename to src/data/database.db diff --git a/src/skills_data.csv b/src/data/skills_data.csv similarity index 100% rename from src/skills_data.csv rename to src/data/skills_data.csv diff --git a/src/updated_breeding_pairs.csv b/src/data/updated_breeding_pairs.csv similarity index 100% rename from src/updated_breeding_pairs.csv rename to src/data/updated_breeding_pairs.csv diff --git a/src/python/__innit__.py b/src/python/__innit__.py deleted file mode 100644 index b95b022..0000000 --- a/src/python/__innit__.py +++ /dev/null @@ -1,4 +0,0 @@ -from .breed import get_breeding_pairs, get_breed_id, get_used_in_breeds - - -__all__ = ["breed",] diff --git a/src/python/breed.py b/src/python/breed.py deleted file mode 100644 index 891b159..0000000 --- a/src/python/breed.py +++ /dev/null @@ -1,99 +0,0 @@ -from flask import g - -def get_used_in_breeds(target_monster): - cursor = g.db.cursor() - - # Fetch breed IDs where the selected monster is used as a base - cursor.execute( - """ - SELECT breed_id - FROM breed_requirements - WHERE requirement_type = 'base' - AND requirement_value = ? - """, - (target_monster,), - ) - - base_breed_ids = [row[0] for row in cursor.fetchall()] - - # Fetch breed IDs where the selected monster is used as a mate - cursor.execute( - """ - SELECT breed_id - FROM breed_requirements - WHERE requirement_type = 'mate' - AND requirement_value = ? - """, - (target_monster,), - ) - - mate_breed_ids = [row[0] for row in cursor.fetchall()] - - # Combine the results from both queries - used_in_breed_ids = base_breed_ids + mate_breed_ids - - # Fetch the target monsters for the obtained breed IDs - used_in_breeds = [] - for breed_id in used_in_breed_ids: - cursor.execute( - """ - SELECT target - FROM breeds - WHERE id = ? - """, - (breed_id,), - ) - target_monster = cursor.fetchone() - if target_monster: - used_in_breeds.append(target_monster[0]) - - return used_in_breeds - -def get_breed_id(target_monster): - cursor = g.db.cursor() - - # Fetch breed ID based on the selected monster as a target - cursor.execute( - """ - SELECT breeds.id - FROM breeds - WHERE breeds.target = ? - """, - (target_monster,), - ) - - breed_id = cursor.fetchone() - - if breed_id: - return breed_id[0] - else: - return None - - -def get_breeding_pairs(breed_id): - cursor = g.db.cursor() - - # Fetch base and mate breeding combinations based on the breed ID - cursor.execute( - """ - SELECT requirement_type, requirement_value - FROM breed_requirements - WHERE breed_id = ? - """, - (breed_id,), - ) - - breeding_info = cursor.fetchall() - - base_pair = [ - value - for (requirement_type, value) in breeding_info - if requirement_type == "base" - ] - mate_pair = [ - value - for (requirement_type, value) in breeding_info - if requirement_type == "mate" - ] - - return base_pair, mate_pair \ No newline at end of file diff --git a/src/routes/__innit__.py b/src/routes/__innit__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/util/__innit__.py b/src/util/__innit__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/util/utils.py b/src/util/utils.py new file mode 100644 index 0000000..aacf2c0 --- /dev/null +++ b/src/util/utils.py @@ -0,0 +1,14 @@ +import sqlite3, csv + +DATABASE = "src/data/database.db" + +def connect_db(): + return sqlite3.connect(DATABASE) + +def read_csv(file_path): + data = [] + with open(file_path, 'r', newline='', encoding='utf-8') as csvfile: + reader = csv.DictReader(csvfile) + for row in reader: + data.append(row) + return data \ No newline at end of file diff --git a/static/style/output.css b/static/style/output.css index eb3bdb6..1b8f4ac 100644 --- a/static/style/output.css +++ b/static/style/output.css @@ -655,6 +655,11 @@ video { border-color: rgb(148 163 184 / var(--tw-border-opacity)); } +.bg-gray-900 { + --tw-bg-opacity: 1; + background-color: rgb(17 24 39 / var(--tw-bg-opacity)); +} + .bg-neutral-800 { --tw-bg-opacity: 1; background-color: rgb(38 38 38 / var(--tw-bg-opacity)); @@ -665,11 +670,6 @@ video { background-color: rgb(15 23 42 / var(--tw-bg-opacity)); } -.bg-gray-900 { - --tw-bg-opacity: 1; - background-color: rgb(17 24 39 / var(--tw-bg-opacity)); -} - .p-2 { padding: 0.5rem; } @@ -736,11 +736,6 @@ video { line-height: 1.75rem; } -.text-blue-500 { - --tw-text-opacity: 1; - color: rgb(59 130 246 / var(--tw-text-opacity)); -} - .text-purple-400 { --tw-text-opacity: 1; color: rgb(192 132 252 / var(--tw-text-opacity));