Files
conjurer/watch_script_params.py
T
Michal Tuszowski ef6eb84921 Preserve backup_old_docker bot variant at root (for comparison)
Snapshot of the dockerisation-era bot code laid out at the repository
root so it can be diffed directly against the working-copy baseline
(restructure/working-copy-root) to see how the variant differed:

- thin_client.py asyncio entrypoint (vs working_copy bot.py)
- constants.py env-var/credential refactor, communication auth, etc.
- extra gpt_interface/ service, sync.py, watch_script_params.py
- conanjurer_* modules absent in this variant

Docker infrastructure (docker/, docker-compose.yml, .dockerignore)
intentionally omitted - this branch is for code comparison only and is
not intended to be merged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-28 22:55:53 +02:00

64 lines
1.9 KiB
Python
Executable File

import os
import time
import shutil
from datetime import datetime, date
import hashlib
import subprocess
# File paths
SOURCE_FILE = "/home/pi/Conjurer/script.params"
BACKUP_DIR = "/home/pi/Conjurer"
GIT_REPO_DIR = "/home/pi/conjurer/conjurer_musician"
LAST_HASH_FILE = "/home/pi/Conjurer/.last_hash"
LAST_GIT_COMMIT_FILE = "/home/pi/Conjurer/.last_git_commit"
def compute_file_hash(filepath):
with open(filepath, 'rb') as f:
return hashlib.sha256(f.read()).hexdigest()
def backup_file():
timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
backup_path = os.path.join(BACKUP_DIR, f"{timestamp}_script.params")
shutil.copy2(SOURCE_FILE, backup_path)
def commit_to_git():
try:
subprocess.run(["cp", SOURCE_FILE, os.path.join(GIT_REPO_DIR, "script.params")], check=True)
subprocess.run(["git", "-C", GIT_REPO_DIR, "add", "script.params"], check=True)
subprocess.run(["git", "-C", GIT_REPO_DIR, "commit", "-m", f"Daily update: {datetime.now()}"], check=True)
subprocess.run(["git", "-C", GIT_REPO_DIR, "push"], check=True)
except subprocess.CalledProcessError as e:
print(f"Git operation failed: {e}")
def main():
if not os.path.exists(SOURCE_FILE):
return
current_hash = compute_file_hash(SOURCE_FILE)
# Detect change
last_hash = None
if os.path.exists(LAST_HASH_FILE):
with open(LAST_HASH_FILE, 'r') as f:
last_hash = f.read().strip()
if current_hash != last_hash:
backup_file()
with open(LAST_HASH_FILE, 'w') as f:
f.write(current_hash)
# Daily git commit
today = str(date.today())
last_commit_date = ""
if os.path.exists(LAST_GIT_COMMIT_FILE):
with open(LAST_GIT_COMMIT_FILE, 'r') as f:
last_commit_date = f.read().strip()
if today != last_commit_date:
commit_to_git()
with open(LAST_GIT_COMMIT_FILE, 'w') as f:
f.write(today)
if __name__ == "__main__":
main()