-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_bots.py
More file actions
34 lines (27 loc) · 966 Bytes
/
run_bots.py
File metadata and controls
34 lines (27 loc) · 966 Bytes
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
import subprocess
def run_bots():
try:
with open('api_keys.txt', 'r') as file:
tokens = file.readlines()
except FileNotFoundError:
print("File api_keys.txt not found!")
return
for token in tokens:
if not token:
print("Token cannot be empty!")
return
token = token.strip()
if token:
safe_token = token.replace(':', '_')
container_name = f"bot_{safe_token}"
command = [
'docker', 'run', '-d', '--name', container_name,
'--rm', 'aiogram_bot_image', 'python', 'main.py', token.strip()
]
try:
subprocess.run(command, check=True)
print(f"Container started: {container_name}")
except subprocess.CalledProcessError as e:
print(f"Error starting container {container_name}: {e}")
if __name__ == "__main__":
run_bots()