Kaynağa Gözat

fix next song validation + add auto_print_infomail.py script

Noah Vogt 4 hafta önce
ebeveyn
işleme
4f7a716007

+ 47 - 0
auto_print_infomail.py

@@ -0,0 +1,47 @@
+#!/usr/bin/env python3
+
+# Copyright © 2023 Noah Vogt <noah@noahvogt.com>
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+from os import system
+from datetime import datetime
+from re import match
+
+import colorama
+
+from utils import make_sure_file_exists, get_current_yyyy_mm_dd_date
+from input import validate_autoprint_infomail_config, get_cachefile_content
+import config as const
+
+
+def is_sunday() -> bool:
+    today = datetime.today()
+    return today.weekday() == 6
+
+
+def already_printed_today() -> bool:
+    cachefile_content = get_cachefile_content(const.AUTOPRINT_INFOMAIL_DATEFILE)
+    return bool(
+        match(r"[0-9]{4}-[0-9]{2}-[0-9]{2}$", cachefile_content[0])
+        and cachefile_content[0].strip() == get_current_yyyy_mm_dd_date()
+    )
+
+
+if __name__ == "__main__":
+    colorama.init()
+    validate_autoprint_infomail_config()
+    make_sure_file_exists(const.AUTOPRINT_INFOMAIL_DATEFILE, gui_error_out=True)
+    if is_sunday() and not already_printed_today():
+        system(const.AUTOPRINT_INFOMAIL_CMD)

+ 7 - 2
config/default_config.py

@@ -89,8 +89,10 @@ OBS_SUBDIR_NAMING = ""
 OBS_MIN_SUBDIRS = 7
 
 NEXTSONG_CACHE_FILE = ""
-OBS_SWITCH_TO_SCENE_HOTKEY_PREFIX = ["ctrl", "shift"]
-OBS_TRANSITION_HOTKEY = ["ctrl", "shift", "f12"]
+OBS_WEBSOCKET_HOSTNAME = "localhost"
+OBS_WEBSOCKET_PORT = 4444
+OBS_WEBSOCKET_PASSWORD = ""
+OBS_SONG_SCENE_PREFIX = "song "
 
 CD_RECORD_CACHEFILE = ""
 CD_RECORD_OUTPUT_BASEDIR = ""
@@ -111,3 +113,6 @@ SERMON_UPLOAD_FTP_USER = ""
 SERMON_UPLOAD_FTP_PASSWORD = ""
 SERMON_UPLOAD_FTP_UPLOAD_DIR = ""
 SERMON_UPLOAD_SUITABLE_SEGMENT_FRAMES = 90000  # 75 * 60 * 20
+
+AUTOPRINT_INFOMAIL_CMD = ""
+AUTOPRINT_INFOMAIL_DATEFILE = ""

+ 1 - 0
input/__init__.py

@@ -31,5 +31,6 @@ from .validate_config import (
     validate_sermon_upload_config,
     validate_cd_burn_config,
     validate_manual_filedrop_sermon_upload_config,
+    validate_autoprint_infomail_config,
 )
 from .slide_selection_iterator import slide_selection_iterator

+ 12 - 2
input/validate_config.py

@@ -43,8 +43,18 @@ def validate_obs_song_scene_switcher_config() -> None:
     needed_constants: dict = {
         "NEXTSONG_CACHE_FILE": const.NEXTSONG_CACHE_FILE,
         "OBS_MIN_SUBDIRS": const.OBS_MIN_SUBDIRS,
-        "OBS_TRANSITION_HOTKEY": const.OBS_TRANSITION_HOTKEY,
-        "OBS_SWITCH_TO_SCENE_HOTKEY_PREFIX": const.OBS_SWITCH_TO_SCENE_HOTKEY_PREFIX,
+        "OBS_WEBSOCKET_HOSTNAME": const.OBS_WEBSOCKET_HOSTNAME,
+        "OBS_WEBSOCKET_PORT": const.OBS_WEBSOCKET_PORT,
+        "OBS_WEBSOCKET_PASSWORD": const.OBS_WEBSOCKET_PASSWORD,
+        "OBS_SONG_SCENE_PREFIX": const.OBS_SONG_SCENE_PREFIX,
+    }
+    general_config_validator(needed_constants, gui_error_out=True)
+
+
+def validate_autoprint_infomail_config() -> None:
+    needed_constants: dict = {
+        "AUTOPRINT_INFOMAIL_CMD": const.AUTOPRINT_INFOMAIL_CMD,
+        "AUTOPRINT_INFOMAIL_DATEFILE": const.AUTOPRINT_INFOMAIL_DATEFILE,
     }
     general_config_validator(needed_constants, gui_error_out=True)