Alialdlfy1 commited on
Commit
9a56186
·
verified ·
1 Parent(s): 6a0445b

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -74
app.py DELETED
@@ -1,74 +0,0 @@
1
- import os
2
- import sys
3
- import time
4
- import subprocess
5
- import streamlit as st
6
-
7
- st.set_page_config(page_title="Telegram Auto Poster")
8
- st.title("🤖 بوت النشر التلقائي")
9
-
10
- LOCK_FILE = "/tmp/telegram_auto_poster_app.lock"
11
- PID_FILE = "/tmp/telegram_auto_poster_bot.pid"
12
-
13
- def _pid_is_running(pid: int) -> bool:
14
- try:
15
- os.kill(pid, 0)
16
- return True
17
- except ProcessLookupError:
18
- return False
19
- except PermissionError:
20
- return True
21
- except Exception:
22
- return False
23
-
24
- def get_running_pid():
25
- if not os.path.exists(PID_FILE):
26
- return None
27
-
28
- try:
29
- pid_text = open(PID_FILE, "r", encoding="utf-8").read().strip()
30
- if not pid_text:
31
- return None
32
- pid = int(pid_text)
33
- return pid if _pid_is_running(pid) else None
34
- except Exception:
35
- return None
36
-
37
- def start_bot_process():
38
- os.makedirs("/data", exist_ok=True)
39
-
40
- existing_pid = get_running_pid()
41
- if existing_pid:
42
- return existing_pid, False
43
-
44
- env = os.environ.copy()
45
- env["PYTHONUNBUFFERED"] = "1"
46
-
47
- process = subprocess.Popen(
48
- [sys.executable, "-u", "-c", "from bot_core import run_bot; run_bot()"],
49
- env=env,
50
- stdout=None,
51
- stderr=None,
52
- start_new_session=True
53
- )
54
-
55
- with open(PID_FILE, "w", encoding="utf-8") as f:
56
- f.write(str(process.pid))
57
-
58
- with open(LOCK_FILE, "w", encoding="utf-8") as f:
59
- f.write(str(time.time()))
60
-
61
- return process.pid, True
62
-
63
- pid, started_now = start_bot_process()
64
-
65
- if started_now:
66
- st.success(f"✅ تم تشغيل البوت بنجاح. PID: {pid}")
67
- else:
68
- st.success(f"✅ البوت يعمل مسبقاً. PID: {pid}")
69
-
70
- st.info("البوت يعمل في الخلفية. استخدم تيليجرام للتحكم.")
71
-
72
- with st.expander("معلومات التشغيل"):
73
- st.write("إذا غيّرت Secrets أو رفعت ملفات جديدة، استخدم Restart Space من Hugging Face.")
74
- st.write("ملف PID:", PID_FILE)