-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
48 lines (39 loc) · 1.32 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
import streamlit as st
import asyncio
from main import main, stop_autocatcher, TOKENS
# Streamlit UI
st.title("Pokefier Bot")
log_area = st.empty() # Placeholder for logs
# Status Flags
if "bot_running" not in st.session_state:
st.session_state.bot_running = False
# Function to read logs
def read_logs(file_path="logs/pokefier.log"):
try:
with open(file_path, "r") as log_file:
return log_file.read()
except FileNotFoundError:
return "Log file not found."
# Start Button
if st.button("Start Bot"):
if not st.session_state.bot_running:
st.session_state.bot_running = True
st.info("Starting bots...")
# Start the bots asynchronously
asyncio.run(main(TOKENS))
st.success("Bots started!")
# Display logs dynamically
while st.session_state.bot_running:
logs = read_logs() # Read log file
log_area.code(logs, language="text")
asyncio.sleep(1) # Refresh every second
else:
st.warning("Bots are already running.")
# Stop Button
if st.button("Stop Bot"):
if st.session_state.bot_running:
asyncio.run(stop_autocatcher()) # Stop bots asynchronously
st.session_state.bot_running = False
st.success("Bots stopped!")
else:
st.warning("Bots are not running.")