-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
65 lines (55 loc) · 2.02 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
import os
import subprocess
import streamlit as st
from views import poll, current, history, debts
from utils import load_users
# Local Directory Configuration
os.makedirs("tmp", exist_ok=True)
HISTORY_DIR = "history"
WHOPAID_FILE = "tmp/whopaid.txt"
ORDER_FILE = "tmp/current_order.csv"
BAR_FILE = "tmp/bar.csv"
MACHINE_FILE = "tmp/machine.csv"
DEBTS_FILE = "tmp/debts.csv"
USERS_FILE = "inputs/users.yaml"
BACKUP_FILE = "inputs/settleup_backup.csv"
# 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)
# Sidebar for navigating through different views
menu = st.sidebar.selectbox("Select View", ["Poll", "Current", "Debts", "History"])
match menu:
case "Poll":
# Poll view to create an order
poll(ORDER_FILE)
case "Current":
# Current view to display the current order
current(HISTORY_DIR, WHOPAID_FILE, ORDER_FILE, BAR_FILE, MACHINE_FILE, DEBTS_FILE, BACKUP_FILE)
case "Debts":
# Debts view to check debts
debts(HISTORY_DIR, USERS_FILE, DEBTS_FILE, BACKUP_FILE)
case "History":
# History view to check past summaries
history(HISTORY_DIR, WHOPAID_FILE, ORDER_FILE, BAR_FILE, MACHINE_FILE, DEBTS_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)