-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
80 lines (64 loc) · 2.56 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import os
import subprocess
import streamlit as st
from views import poll, current, history, debts, spotlight
from utils import load_users, load_settleup, save_csv
# Inputs directory
USERS_FILE = "inputs/users.yaml" # Users, initial debts, and description
# History directory
HISTORY_DIR = "history"
os.makedirs(HISTORY_DIR, exist_ok=True)
LST_FILE = os.path.join(HISTORY_DIR, "last.csv") # Last debts
# Tmp directory
TMP_DIR = "tmp"
os.makedirs(TMP_DIR, exist_ok=True)
WHO_FILE = os.path.join(TMP_DIR, "whopaid.txt") # Who paid
ORD_FILE = os.path.join(TMP_DIR, "order.csv") # The order
BAR_FILE = os.path.join(TMP_DIR, "bar.csv") # What to ask at the bar
MAC_FILE = os.path.join(TMP_DIR, "machine.csv") # What to put in the paying machine
DEB_FILE = os.path.join(TMP_DIR, "debts.csv") # Debts per user
# Set name and icon to webpage
st.set_page_config(
page_title="Café GTI",
page_icon="☕",
)
# Initialize session state
if "state" not in st.session_state:
st.session_state.state = "Poll"
if "users" not in st.session_state:
st.session_state.users = load_users(USERS_FILE)
if not os.path.isfile(LST_FILE):
save_csv(load_settleup(USERS_FILE), LST_FILE)
# Sidebar for navigating through different views
menu = st.sidebar.selectbox("Select View", ["Poll ☕", "Current 💥", "Debts 💲", "History 📜", "Morosos 👻"])
match menu:
# Poll view to create an order
case "Poll ☕":
poll(ORD_FILE)
# Current view to display the current order
case "Current 💥":
current(HISTORY_DIR, WHO_FILE, ORD_FILE, BAR_FILE, MAC_FILE, DEB_FILE, LST_FILE)
# Debts view to check debts
case "Debts 💲":
debts(USERS_FILE, LST_FILE)
# History view to check past summaries
case "History 📜":
history(HISTORY_DIR, WHO_FILE, ORD_FILE, BAR_FILE, MAC_FILE, DEB_FILE)
# Spotlight view to see the story of the person with larger debt
case "Morosos 👻":
spotlight(LST_FILE)
if __name__ == "__main__":
# Define the port you want your app to run on
PORT = 8500
# Check if Streamlit is already running on the specified port
try:
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(1)
s.connect(("127.0.0.1", PORT))
s.close()
print(f"Streamlit is already running on port {PORT}.")
except (socket.error, ConnectionRefusedError):
print(f"Launching Streamlit app on port {PORT}...")
# Run Streamlit programmatically
subprocess.run(["streamlit", "run", __file__, "--server.port", str(PORT)], check=True)