KISS/kiss/ssmanager.py

35 lines
949 B
Python
Raw Normal View History

2022-11-17 02:52:37 +00:00
import os
import subprocess
import tempfile
import time
from pathlib import Path
from threading import Thread
class ScreenshotManager:
def __init__(self):
self.__config_path = os.environ.get("CONFIG_FILE", "/data/config.conf")
self.data_path = tempfile.gettempdir()
if not Path(self.__config_path).is_file():
raise ValueError("Invalid Configuration")
def stop(self):
self.__pending_shutdown = True
self.__loop_thread.join()
def start(self):
self.__pending_shutdown = False
self.__loop_thread = Thread(target=self.__loop)
self.__loop_thread.start()
def __loop(self):
counter = 0
while not self.__pending_shutdown:
if counter % 900 == 0:
subprocess.run(
["shot-scraper", "multi", self.__config_path], cwd=self.data_path
)
time.sleep(1)
counter += 1