Add Rotate

This commit is contained in:
Evan Reichard 2022-11-17 09:01:38 -05:00
parent 8cfb792be9
commit f286b23f6a
2 changed files with 18 additions and 1 deletions

View File

@ -5,15 +5,21 @@ import time
from pathlib import Path from pathlib import Path
from threading import Thread from threading import Thread
import yaml
from PIL import Image
class ScreenshotManager: class ScreenshotManager:
def __init__(self): def __init__(self):
self.__config_path = os.environ.get("CONFIG_FILE", "/data/config.yml") self.__config_path = os.environ.get("CONFIG_FILE", "/data/config.yml")
self.data_path = tempfile.gettempdir()
if not Path(self.__config_path).is_file(): if not Path(self.__config_path).is_file():
raise ValueError("Invalid Configuration") raise ValueError("Invalid Configuration")
cf = open(self.__config_path, "r")
self.__config_yaml = yaml.safe_load(cf)
self.data_path = tempfile.gettempdir()
def stop(self): def stop(self):
self.__pending_shutdown = True self.__pending_shutdown = True
self.__loop_thread.join() self.__loop_thread.join()
@ -23,6 +29,12 @@ class ScreenshotManager:
self.__loop_thread = Thread(target=self.__loop) self.__loop_thread = Thread(target=self.__loop)
self.__loop_thread.start() self.__loop_thread.start()
def __rotate_file(self, filename):
fp = Path(self.data_path, filename)
img = Image.open(fp)
img = img.rotate(90, expand=True)
img.save(fp)
def __loop(self): def __loop(self):
counter = 0 counter = 0
while not self.__pending_shutdown: while not self.__pending_shutdown:
@ -30,5 +42,9 @@ class ScreenshotManager:
subprocess.run( subprocess.run(
["shot-scraper", "multi", self.__config_path], cwd=self.data_path ["shot-scraper", "multi", self.__config_path], cwd=self.data_path
) )
for ss in self.__config_yaml:
if ss.get("rotate", False) is True:
self.__rotate_file(ss.get("output"))
time.sleep(1) time.sleep(1)
counter += 1 counter += 1

View File

@ -10,6 +10,7 @@ setup(
include_package_data=True, include_package_data=True,
entry_points={"console_scripts": ["kiss = kiss:cli"]}, entry_points={"console_scripts": ["kiss = kiss:cli"]},
install_requires=[ install_requires=[
"Pillow",
"Flask>=2.2", "Flask>=2.2",
], ],
tests_require=["pytest"], tests_require=["pytest"],