"""
mark_colddata_junk.py — Označí jasně odpadní podsložky v Tower1/#ColdData
jako nechceme. NEoznačuje SynologyMaly, Honza, VladkoSoubory, Qnap, Tatinek,
DedupPhotos (ty se zkoumají zvlášť).

Kategorie:
  Porno*, MadelineIsWicked            -> 'Porno'
  000 TORENT OBRAZKY, MoMA, Dali,
  hudební alba, eBooky                -> 'Odpad-torrent'
"""
import sys
import psycopg2

sys.stdout.reconfigure(encoding="utf-8")

DB = dict(host="192.168.1.76", port=5432, user="vladimir.buzalka",
          password="Vlado7309208104++", database="fotky_buzalkovi")

BASE = "/mnt/user/ZalohaVsechObrazku/Tower1/#ColdData/"

# (popis, LIKE vzor, kategorie)
RULES = [
    ("Porno",             BASE + "Porno/%",             "Porno"),
    ("Porno1",            BASE + "Porno1/%",            "Porno"),
    ("MadelineIsWicked",  BASE + "MadelineIsWicked/%",  "Porno"),
    ("000 TORENT OBRAZKY",BASE + "000 TORENT OBRAZKY/%","Odpad-torrent"),
    ("Museum of Modern Art NY", BASE + "Museum of Modern Art NY/%", "Odpad-torrent"),
]

conn = psycopg2.connect(**DB)
conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
cur = conn.cursor()

total = 0
for popis, like, kat in RULES:
    cur.execute("""
        UPDATE photos p
        SET wanted = FALSE, category = %s
        FROM zaloha_obrazku z
        WHERE p.zaloha_id = z.id
          AND z.cesta_zalohy LIKE %s
          AND p.category IS DISTINCT FROM %s
    """, (kat, like, kat))
    print(f"  {popis:28s} -> {kat:14s}: {cur.rowcount:,}")
    total += cur.rowcount

print(f"\nHotovo. Celkem: {total:,} řádků označeno jako odpad.")
conn.close()
