Add Streamlit Docker auto-sync deployment
This commit is contained in:
32
app.py
32
app.py
@@ -7,6 +7,7 @@ import streamlit as st
|
||||
from pathlib import Path
|
||||
import spotipy
|
||||
|
||||
from spotify_to_tidal import auto_sync as _auto_sync
|
||||
from spotify_to_tidal import auth as _auth
|
||||
from spotify_to_tidal import sync as _sync
|
||||
from spotify_to_tidal.tidalapi_patch import get_all_playlists
|
||||
@@ -14,6 +15,7 @@ from spotify_to_tidal.tidalapi_patch import get_all_playlists
|
||||
# ── Constants ─────────────────────────────────────────────────────────────────
|
||||
SESSION_FILE = Path("session.json")
|
||||
NOT_FOUND_FILE = Path("songs not found.txt")
|
||||
AUTO_SYNC_STATUS_FILE = Path("auto_sync_status.json")
|
||||
|
||||
# ── Session persistence ───────────────────────────────────────────────────────
|
||||
def load_session() -> dict:
|
||||
@@ -38,6 +40,14 @@ def save_watched(ids: set):
|
||||
def load_external_playlists() -> list:
|
||||
return load_session().get("external_playlists", [])
|
||||
|
||||
def load_auto_sync_status() -> dict:
|
||||
if AUTO_SYNC_STATUS_FILE.exists():
|
||||
try:
|
||||
return json.loads(AUTO_SYNC_STATUS_FILE.read_text())
|
||||
except Exception:
|
||||
pass
|
||||
return {}
|
||||
|
||||
def upsert_external_playlist(info: dict):
|
||||
data = load_session()
|
||||
ext = [p for p in data.get("external_playlists", []) if p.get("id") != info["id"]]
|
||||
@@ -93,6 +103,28 @@ def get_sessions():
|
||||
|
||||
config, spotify_session, tidal_session = get_sessions()
|
||||
|
||||
@st.cache_resource
|
||||
def start_auto_sync_scheduler(config: dict):
|
||||
return _auto_sync.start_scheduler(
|
||||
config,
|
||||
session_file=SESSION_FILE,
|
||||
status_file=AUTO_SYNC_STATUS_FILE,
|
||||
)
|
||||
|
||||
start_auto_sync_scheduler(config)
|
||||
|
||||
if (config.get("auto_sync") or {}).get("enabled", False):
|
||||
auto_status = load_auto_sync_status()
|
||||
with st.sidebar:
|
||||
st.caption("Daily auto-sync")
|
||||
st.write(auto_status.get("state", "starting"))
|
||||
if auto_status.get("next_run_at"):
|
||||
st.caption(f"Next: {auto_status['next_run_at']}")
|
||||
if auto_status.get("last_run_at"):
|
||||
st.caption(f"Last: {auto_status['last_run_at']}")
|
||||
if auto_status.get("error"):
|
||||
st.error(auto_status["error"])
|
||||
|
||||
# ── Data fetchers ─────────────────────────────────────────────────────────────
|
||||
@st.cache_data
|
||||
def fetch_my_playlists():
|
||||
|
||||
Reference in New Issue
Block a user