Update app.py
Browse files
app.py
CHANGED
@@ -83,8 +83,9 @@ logger.addHandler(list_handler)
|
|
83 |
# -------------------------------------------------------------------
|
84 |
# Utility Functions & UI Helpers
|
85 |
# -------------------------------------------------------------------
|
86 |
-
def
|
87 |
-
|
|
|
88 |
|
89 |
def get_inline_keyboard_for_stream():
|
90 |
# Inline keyboard for streaming controls after stream has started
|
@@ -161,11 +162,11 @@ def validate_inputs():
|
|
161 |
def live_log_updater(chat_id):
|
162 |
global live_log_message_id, streaming_state
|
163 |
try:
|
164 |
-
# Send initial live log message
|
165 |
payload = {
|
166 |
"chat_id": chat_id,
|
167 |
-
"text": "
|
168 |
-
"parse_mode": "
|
169 |
}
|
170 |
resp = requests.post(f"{TELEGRAM_API_URL}/sendMessage", json=payload)
|
171 |
if resp.ok:
|
@@ -175,17 +176,18 @@ def live_log_updater(chat_id):
|
|
175 |
logging.error("Failed to send live log message.")
|
176 |
return
|
177 |
|
178 |
-
# Update live log every
|
179 |
while streaming_state in ["streaming", "paused"]:
|
180 |
-
|
|
|
181 |
edit_payload = {
|
182 |
"chat_id": chat_id,
|
183 |
"message_id": live_log_message_id,
|
184 |
"text": log_text,
|
185 |
-
"parse_mode": "
|
186 |
}
|
187 |
requests.post(f"{TELEGRAM_API_URL}/editMessageText", json=edit_payload)
|
188 |
-
time.sleep(
|
189 |
except Exception as e:
|
190 |
logging.error(f"Error in live log updater: {e}")
|
191 |
|
@@ -392,7 +394,7 @@ def start_streaming(chat_id):
|
|
392 |
stream_thread.start()
|
393 |
logging.info("Streaming thread started.")
|
394 |
|
395 |
-
# Start the live log updater thread (updates every
|
396 |
live_log_thread = threading.Thread(target=live_log_updater, args=(chat_id,))
|
397 |
live_log_thread.daemon = True
|
398 |
live_log_thread.start()
|
|
|
83 |
# -------------------------------------------------------------------
|
84 |
# Utility Functions & UI Helpers
|
85 |
# -------------------------------------------------------------------
|
86 |
+
def create_html_message(text: str):
|
87 |
+
# Wrap text in <pre> tags for monospaced output
|
88 |
+
return {"parse_mode": "HTML", "text": f"<pre>{text}</pre>"}
|
89 |
|
90 |
def get_inline_keyboard_for_stream():
|
91 |
# Inline keyboard for streaming controls after stream has started
|
|
|
162 |
def live_log_updater(chat_id):
|
163 |
global live_log_message_id, streaming_state
|
164 |
try:
|
165 |
+
# Send initial live log message in HTML format
|
166 |
payload = {
|
167 |
"chat_id": chat_id,
|
168 |
+
"text": "<pre>Live Logs:\nInitializing...</pre>",
|
169 |
+
"parse_mode": "HTML"
|
170 |
}
|
171 |
resp = requests.post(f"{TELEGRAM_API_URL}/sendMessage", json=payload)
|
172 |
if resp.ok:
|
|
|
176 |
logging.error("Failed to send live log message.")
|
177 |
return
|
178 |
|
179 |
+
# Update live log every 1 second until streaming stops
|
180 |
while streaming_state in ["streaming", "paused"]:
|
181 |
+
# Show the last 15 log lines in HTML format
|
182 |
+
log_text = "<pre>" + "\n".join(live_log_lines[-15:]) + "</pre>"
|
183 |
edit_payload = {
|
184 |
"chat_id": chat_id,
|
185 |
"message_id": live_log_message_id,
|
186 |
"text": log_text,
|
187 |
+
"parse_mode": "HTML"
|
188 |
}
|
189 |
requests.post(f"{TELEGRAM_API_URL}/editMessageText", json=edit_payload)
|
190 |
+
time.sleep(1)
|
191 |
except Exception as e:
|
192 |
logging.error(f"Error in live log updater: {e}")
|
193 |
|
|
|
394 |
stream_thread.start()
|
395 |
logging.info("Streaming thread started.")
|
396 |
|
397 |
+
# Start the live log updater thread (updates every 1 second in HTML format)
|
398 |
live_log_thread = threading.Thread(target=live_log_updater, args=(chat_id,))
|
399 |
live_log_thread.daemon = True
|
400 |
live_log_thread.start()
|