Skip to content

Commit 79d6ddd

Browse files
committed
⚙️ Optimizando sistema de actualización y gestión
1 parent 77cef5c commit 79d6ddd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2394
-158
lines changed

.github/workflows/deploy.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Deploy Bot
2+
on:
3+
push:
4+
branches: [ main ]
5+
6+
jobs:
7+
deploy:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v3
11+
12+
- name: Set up SSH
13+
uses: webfactory/ssh-agent@v0.8.0
14+
with:
15+
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
16+
17+
- name: Add SSH key fingerprint
18+
run: |
19+
mkdir -p ~/.ssh
20+
ssh-keyscan ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts
21+
22+
- name: Deploy to VPS
23+
run: |
24+
ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "
25+
cd /ruta/a/tu/bot &&
26+
git pull origin main &&
27+
# Si usas requirements.txt:
28+
pip install -r requirements.txt &&
29+
# Reiniciar el bot (ajusta según tu configuración)
30+
systemctl --user restart telegrambot.service
31+
"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Blind

agenda.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

blind/manager.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import argparse
2+
from watchdog.observers import Observer
3+
from watchdog.events import FileSystemEventHandler
4+
import subprocess
5+
import time
6+
7+
class BotHandler(FileSystemEventHandler):
8+
def __init__(self, script_name):
9+
self.script_name = script_name
10+
self.process = None
11+
self.start_bot()
12+
13+
def start_bot(self):
14+
if self.process:
15+
self.process.kill()
16+
self.process = subprocess.Popen(["python3", "-m", self.script_name])
17+
18+
def on_modified(self, event):
19+
if event.src_path.endswith(".py"):
20+
print(f"Cambio detectado en {event.src_path}. Reiniciando bot...")
21+
self.start_bot()
22+
23+
def stop_bot(self):
24+
if self.process:
25+
self.process.kill()
26+
27+
def main():
28+
parser = argparse.ArgumentParser()
29+
parser.add_argument("--dev", action="store_true", help="Modo desarrollo (auto-reload)")
30+
args = parser.parse_args()
31+
32+
script_name = "blind.src.main"
33+
bot_handler = BotHandler(script_name)
34+
35+
if args.dev:
36+
print("Modo desarrollo activado (con auto-reload)")
37+
observer = Observer()
38+
observer.schedule(bot_handler, path="./blind", recursive=True)
39+
observer.start()
40+
41+
try:
42+
while True:
43+
time.sleep(1)
44+
except KeyboardInterrupt:
45+
print("Deteniendo el bot...")
46+
bot_handler.stop_bot()
47+
observer.stop()
48+
observer.join()
49+
else:
50+
print("Modo producción activado")
51+
try:
52+
while True:
53+
time.sleep(1)
54+
except KeyboardInterrupt:
55+
print("Deteniendo el bot...")
56+
bot_handler.stop_bot()
File renamed without changes.

0 commit comments

Comments
 (0)