forked from dzhusipov/fooocus-telegram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
47 lines (39 loc) · 1.28 KB
/
main.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
# main.py
import logging
import os
import threading
import time
from dotenv import load_dotenv
from telegram.ext import ApplicationBuilder
from bot_commands import setup_handlers
def clean_tmp_folder():
while True:
tmp_folder = 'tmp' # Replace with your tmp folder path
current_time = time.time()
for file in os.listdir(tmp_folder): # Iterate through files
file_path = os.path.join(tmp_folder, file)
file_mod_time = os.path.getmtime(file_path)
if current_time - file_mod_time > 60*5: # Check if file is older than 5 minutes
os.remove(file_path) # Delete the file
time.sleep(60) # Sleep for 1 minute
load_dotenv()
# Load environment variables
BOT_TOKEN = os.getenv("BOT_TOKEN")
if not BOT_TOKEN:
raise ValueError("No BOT_TOKEN set in .env file")
# Configure Logging
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(message)s",
handlers=[
logging.FileHandler("debug.log"),
logging.StreamHandler()
]
)
# Start the cleaning thread
cleaning_thread = threading.Thread(target=clean_tmp_folder, daemon=True)
cleaning_thread.start()
# Create and run the bot
app = ApplicationBuilder().token(BOT_TOKEN).build()
setup_handlers(app)
app.run_polling()