mirror of
https://github.com/ethanrusz/scouter.git
synced 2024-11-23 20:27:45 -05:00
Create database module
This commit is contained in:
parent
b2c392e5c5
commit
3eba2b644a
3 changed files with 28 additions and 1 deletions
5
app.py
5
app.py
|
@ -1,4 +1,5 @@
|
|||
import streamlit as st
|
||||
import database as db
|
||||
|
||||
|
||||
class Moon:
|
||||
|
@ -92,9 +93,11 @@ def main():
|
|||
st.markdown("# :red[Lethal Company] Scouter")
|
||||
st.markdown(":rainbow[What does the scouter say about this moon's power level?]")
|
||||
|
||||
moon_strings = db.get_moon_list()
|
||||
|
||||
moon = st.selectbox(
|
||||
"Moon",
|
||||
sorted(m.name for m in moons),
|
||||
moon_strings,
|
||||
placeholder="Moon! Pick a moon!",
|
||||
help="Pick your current moon.",
|
||||
)
|
||||
|
|
1
database/__init__.py
Normal file
1
database/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
from .database import *
|
23
database/database.py
Normal file
23
database/database.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
import os
|
||||
import sqlite3
|
||||
|
||||
|
||||
def get_connection() -> sqlite3.Connection:
|
||||
if os.getenv("DATABASE_FILE"):
|
||||
return sqlite3.connect(os.getenv("DATABASE_FILE"))
|
||||
else:
|
||||
return sqlite3.connect("./scouter.db")
|
||||
|
||||
|
||||
def get_moon_list() -> list[str] | None:
|
||||
with get_connection() as connection:
|
||||
cursor = connection.cursor()
|
||||
moons = cursor.execute(
|
||||
"select moon_name from moon order by moon_id"
|
||||
)
|
||||
|
||||
if moons:
|
||||
moons = [moon[0] for moon in moons]
|
||||
return moons
|
||||
else:
|
||||
return None
|
Loading…
Reference in a new issue