mirror of
https://github.com/ethanrusz/scouter.git
synced 2024-11-24 04:27:46 -05:00
Add scrap to database
This commit is contained in:
parent
19150301d6
commit
9768d706f2
4 changed files with 154 additions and 9 deletions
19
app.py
19
app.py
|
@ -21,6 +21,9 @@ class Run:
|
|||
def main():
|
||||
st.set_page_config("Lethal Company Scouter", "🛰️")
|
||||
|
||||
st.markdown("# :red[Lethal Company] Scouter")
|
||||
st.markdown(":rainbow[What does the scouter say about this moon's power level?]")
|
||||
|
||||
moon_name = st.selectbox(
|
||||
"Moon",
|
||||
db.get_moon_list(),
|
||||
|
@ -32,8 +35,8 @@ def main():
|
|||
|
||||
st.markdown(f"## {run.moon.name} ({run.moon.tier})")
|
||||
|
||||
st.info(f"Risk: {run.moon.risk_level} | Min scrap: {run.moon.min_scrap} "
|
||||
f"| Max scrap: {run.moon.max_scrap} | Default layout: {run.moon.default_layout}")
|
||||
st.write(run)
|
||||
st.write(run.moon)
|
||||
|
||||
# Begin column layout
|
||||
left_column, right_column = st.columns(2)
|
||||
|
@ -44,6 +47,18 @@ def main():
|
|||
with right_column:
|
||||
st.markdown("### Inside")
|
||||
|
||||
st.markdown('## Scrap Lookup')
|
||||
|
||||
scrap_name = st.selectbox(
|
||||
'Scrap Name',
|
||||
db.get_scrap_list(),
|
||||
placeholder='Select a scrap name!'
|
||||
)
|
||||
scrap_id = db.get_scrap_id_by_name(scrap_name)
|
||||
scrap = db.get_scrap_by_id(scrap_id)
|
||||
|
||||
st.write(scrap)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
@ -1 +1,53 @@
|
|||
;
|
||||
insert into main.scrap (scrap_id, scrap_name, min_value, max_value, weight, conductive, two_handed)
|
||||
values (1, 'Air Horn', 52, 72, 0, 0, 0),
|
||||
(2, 'Apparatus', 80, 80, 31, 1, 1),
|
||||
(3, 'Bee Hive', 50, 156, 0, 1, 1),
|
||||
(4, 'Bottles', 44, 56, 19, 0, 1),
|
||||
(5, 'Brass Bell', 48, 80, 24, 1, 0),
|
||||
(6, 'Candy', 6, 36, 11, 0, 0),
|
||||
(7, 'Cash Register', 80, 160, 84, 1, 1),
|
||||
(8, 'Chemical Jug', 32, 84, 32, 0, 1),
|
||||
(9, 'Clown Horn', 52, 72, 0, 1, 0),
|
||||
(10, 'Coffee Mug', 24, 68, 5, 0, 0),
|
||||
(11, 'Comedy Mask', 28, 52, 11, 0, 0),
|
||||
(12, 'Cookie Mold Pan', 12, 40, 16, 0, 0),
|
||||
(13, 'Dustpan', 12, 32, 0, 0, 0),
|
||||
(14, 'Egg Beater', 12, 44, 11, 1, 0),
|
||||
(15, 'Fancy Lamp', 60, 128, 21, 1, 1),
|
||||
(16, 'Flask', 16, 44, 19, 1, 0),
|
||||
(17, 'Gift', 12, 28, 19, 0, 0),
|
||||
(18, 'Gold Bar', 102, 210, 77, 1, 0),
|
||||
(19, 'Golden Cup', 40, 80, 16, 0, 0),
|
||||
(20, 'Hair Brush', 8, 36, 11, 0, 0),
|
||||
(21, 'Hairdryer', 60, 100, 7, 0, 0),
|
||||
(22, 'Homemade Flashbang', 10, 28, 5, 0, 0),
|
||||
(23, 'Jar of Pickles', 32, 60, 16, 0, 0),
|
||||
(24, 'Large Axle', 36, 56, 16, 1, 1),
|
||||
(25, 'Large Bolt', 20, 32, 19, 1, 0),
|
||||
(26, 'Laser Pointer', 32, 100, 0, 0, 0),
|
||||
(27, 'Magic 7 Ball', 36, 72, 16, 0, 0),
|
||||
(28, 'Magnifying Glass', 44, 60, 11, 0, 0),
|
||||
(29, 'Metal Sheet', 10, 22, 26, 1, 0),
|
||||
(30, 'Old Phone', 48, 64, 5, 0, 0),
|
||||
(31, 'Painting', 60, 124, 32, 0, 1),
|
||||
(32, 'Perfume Bottle', 48, 104, 0, 0, 0),
|
||||
(33, 'Pill Bottle', 16, 40, 0, 0, 0),
|
||||
(34, 'Plastic Fish', 28, 40, 0, 0, 0),
|
||||
(35, 'Player Body', 5, 5, 11, 0, 1),
|
||||
(36, 'Red Soda', 18, 90, 7, 1, 0),
|
||||
(37, 'Remote', 20, 48, 0, 0, 0),
|
||||
(38, 'Robot Toy', 56, 88, 21, 1, 0),
|
||||
(39, 'Rubber Duckie', 2, 100, 0, 0, 0),
|
||||
(40, 'Shotgun', 30, 90, 16, 0, 0),
|
||||
(41, 'Shotgun Shell', 0, 0, 0, 0, 0),
|
||||
(42, 'Steering Wheel', 16, 32, 16, 0, 0),
|
||||
(43, 'Stop Sign', 20, 52, 21, 1, 0),
|
||||
(44, 'Tea Kettle', 32, 56, 21, 1, 0),
|
||||
(45, 'Teeth', 60, 84, 0, 0, 0),
|
||||
(46, 'Toothpaste', 14, 48, 0, 0, 0),
|
||||
(47, 'Toy Cube', 24, 44, 0, 0, 0),
|
||||
(48, 'Tragedy Mask', 28, 52, 11, 0, 0),
|
||||
(49, 'V-Type Engine', 20, 56, 16, 1, 1),
|
||||
(50, 'Wedding Ring', 52, 80, 16, 1, 0),
|
||||
(51, 'Whoopie Cushion', 6, 20, 0, 1, 0),
|
||||
(52, 'Yield Sign', 18, 36, 42, 1, 0);
|
|
@ -5,7 +5,7 @@ import sqlite3
|
|||
class Moon:
|
||||
def __init__(self, moon_id, name, risk_level, cost, default_layout, map_size_multiplier, min_scrap, max_scrap,
|
||||
outside_max_power, inside_max_power, tier):
|
||||
self.id = moon_id
|
||||
self.moon_id = moon_id
|
||||
self.name = name
|
||||
self.risk_level = risk_level
|
||||
self.cost = cost
|
||||
|
@ -18,6 +18,17 @@ class Moon:
|
|||
self.tier = tier
|
||||
|
||||
|
||||
class Scrap:
|
||||
def __init__(self, scrap_id, name, min_value, max_value, weight, conductive, two_handed):
|
||||
self.scrap_id = scrap_id
|
||||
self.name = name
|
||||
self.min_value = min_value
|
||||
self.max_value = max_value
|
||||
self.weight = weight
|
||||
self.conductive = conductive
|
||||
self.two_handed = two_handed
|
||||
|
||||
|
||||
def get_connection() -> sqlite3.Connection:
|
||||
"""Opens a connection to the SQLite3 database at the default path
|
||||
or a path provided by an environment variable if one exists.
|
||||
|
@ -59,13 +70,13 @@ def get_moon_list() -> list[str] | None:
|
|||
"""
|
||||
with get_connection() as connection:
|
||||
cursor = connection.cursor()
|
||||
moons = cursor.execute(
|
||||
moon_names = cursor.execute(
|
||||
"select moon_name from moon order by moon_id"
|
||||
).fetchall()
|
||||
|
||||
if moons:
|
||||
moons = [moon[0] for moon in moons]
|
||||
return moons
|
||||
if moon_names:
|
||||
moon_names = [moon[0] for moon in moon_names]
|
||||
return moon_names
|
||||
else:
|
||||
return None
|
||||
|
||||
|
@ -77,7 +88,6 @@ def get_moon_by_id(moon_id: int) -> Moon | None:
|
|||
:return: A moon object or None if no moon is found
|
||||
"""
|
||||
with get_connection() as connection:
|
||||
connection.text_factory = str
|
||||
cursor = connection.cursor()
|
||||
|
||||
query = """
|
||||
|
@ -108,3 +118,71 @@ limit 1;"""
|
|||
return Moon(*moon)
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
def get_scrap_list() -> list[str] | None:
|
||||
"""Provides a list of all scrap names from the database.
|
||||
|
||||
:return: All scrap names as a list of strings or None if no scrap is found
|
||||
"""
|
||||
with get_connection() as connection:
|
||||
cursor = connection.cursor()
|
||||
scrap_names = cursor.execute(
|
||||
"select scrap_name from scrap order by scrap_id"
|
||||
)
|
||||
|
||||
if scrap_names:
|
||||
scrap_names = [scrap[0] for scrap in scrap_names]
|
||||
return scrap_names
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
def get_scrap_id_by_name(scrap_name: str) -> int | None:
|
||||
"""Queries the database for a scrap ID that matches the given name.
|
||||
|
||||
:param scrap_name: Moon name as a string
|
||||
:return: The scrap's ID as an int or None if no scrap is found
|
||||
"""
|
||||
with get_connection() as connection:
|
||||
cursor = connection.cursor()
|
||||
scrap_id = cursor.execute(
|
||||
"select scrap_id "
|
||||
"from scrap "
|
||||
"where scrap_name = ? "
|
||||
"order by scrap_name "
|
||||
"limit 1;",
|
||||
(scrap_name,)
|
||||
).fetchone()
|
||||
|
||||
if scrap_id:
|
||||
return scrap_id[0]
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
def get_scrap_by_id(scrap_id: int) -> Scrap | None:
|
||||
with get_connection() as connection:
|
||||
cursor = connection.cursor()
|
||||
|
||||
query = """
|
||||
select s.scrap_id,
|
||||
s.scrap_name,
|
||||
s.min_value,
|
||||
s.max_value,
|
||||
s.weight,
|
||||
s.conductive,
|
||||
s.two_handed
|
||||
from scrap as s
|
||||
where scrap_id = ?
|
||||
limit 1;
|
||||
"""
|
||||
scrap = cursor.execute(
|
||||
query,
|
||||
(scrap_id,)
|
||||
).fetchone()
|
||||
|
||||
if scrap:
|
||||
return Scrap(*scrap)
|
||||
else:
|
||||
return None
|
||||
|
|
BIN
scouter.db
BIN
scouter.db
Binary file not shown.
Loading…
Reference in a new issue