2024-11-14 03:38:44 +01:00
|
|
|
import time
|
|
|
|
import os
|
|
|
|
import threading
|
|
|
|
from threads.prompt import prompt
|
2024-11-15 22:39:49 +01:00
|
|
|
from run_command import run_command
|
|
|
|
from get_path import get_path
|
2024-11-14 03:38:44 +01:00
|
|
|
|
|
|
|
thread = threading.Thread(target=prompt)
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2024-11-15 22:39:49 +01:00
|
|
|
path = get_path()
|
|
|
|
docker_compose_file = os.getenv(
|
|
|
|
"DOCKER_COMPOSE_FILE", f"{path}/app/docker-compose.yaml"
|
|
|
|
)
|
2024-11-14 03:38:44 +01:00
|
|
|
print("Starting Docker Compose services...")
|
2024-11-15 22:39:49 +01:00
|
|
|
run_command(f"docker compose -f {docker_compose_file} up -d")
|
2024-11-14 03:38:44 +01:00
|
|
|
print("Composed!\n")
|
|
|
|
print("Running main.py...")
|
|
|
|
print(run_command("docker exec -it webscraper python main.py"))
|
|
|
|
print(
|
|
|
|
"\n\nWrite 'q' to stop program. Don't stop with 'Ctrl + C' otherwise docker container will be still on."
|
|
|
|
)
|
|
|
|
print("For help write 'h'.")
|
|
|
|
print("\nWatching for changes...")
|
|
|
|
thread.start()
|
|
|
|
|
|
|
|
before = {
|
2024-11-15 22:39:49 +01:00
|
|
|
f: os.stat(os.path.join(path, "app", f)).st_mtime
|
|
|
|
for f in os.listdir(os.path.join(path, "app"))
|
2024-11-14 03:38:44 +01:00
|
|
|
if f.endswith(".py")
|
|
|
|
}
|
|
|
|
|
|
|
|
while True:
|
|
|
|
if threading.active_count() == 1:
|
|
|
|
break
|
|
|
|
time.sleep(1)
|
|
|
|
after = {
|
2024-11-15 22:39:49 +01:00
|
|
|
f: os.stat(os.path.join(path, "app", f)).st_mtime
|
|
|
|
for f in os.listdir(os.path.join(path, "app"))
|
2024-11-14 03:38:44 +01:00
|
|
|
if f.endswith(".py")
|
|
|
|
}
|
|
|
|
for f in before:
|
|
|
|
if before[f] != after[f]:
|
|
|
|
print(f"\nDetected change in {f}")
|
|
|
|
print("Running main.py...")
|
|
|
|
print(run_command("docker exec -it webscraper python main.py"))
|
|
|
|
before[f] = after[f]
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|