forked from ntkhang03/Goat-Bot-V2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.py
47 lines (34 loc) · 1.24 KB
/
index.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
import os
import pyinotify
import subprocess
import time
current_directory = os.path.dirname(os.path.abspath(__file__))
subdirectory_path = f"{current_directory}"
class EventHandler(pyinotify.ProcessEvent):
def process_default(self, event):
if event.dir:
return
print(f"File {event.pathname} has been modified")
commit_and_push_changes(current_directory)
def execute_git_command(command, cwd):
subprocess.run(command, shell=True, cwd=cwd)
def commit_and_push_changes(file_path):
delay_in_seconds = 2
execute_git_command("git add .", cwd=f"{subdirectory_path}")
print("Changes added")
time.sleep(delay_in_seconds)
execute_git_command(f"git commit -m 'Updated {file_path}'", cwd=f"{subdirectory_path}")
print("Changes committed")
time.sleep(delay_in_seconds)
execute_git_command("git push", cwd=subdirectory_path)
print("Pushed successfully")
wm = pyinotify.WatchManager()
handler = EventHandler()
notifier = pyinotify.Notifier(wm, handler)
# Add a watch for the specified subdirectory
wm.add_watch(subdirectory_path, pyinotify.IN_MODIFY)
print(f"Watching directory: {subdirectory_path}")
try:
notifier.loop()
except KeyboardInterrupt:
notifier.stop()