"""
mark_synology_rodina.py — #Synology fotoarchivy potvrzené uživatelem -> Rodina:
  #SERVER/Y/HD02#FOTKY        (~30 789)
  #SERVER/Y/HD02#FOTKY MAMKA  (~1 167)
  DropboxFotky                (~14 882)
  HD02#DVD OSOBNI             (~5 834)
  Fotky                       (~2 138)
"""
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")

S = "/mnt/user/ZalohaVsechObrazku/Tower1/#Synology/Public/"
LIKES = [
    ("HD02#FOTKY",       S + "#SERVER/Y/HD02#FOTKY/%"),
    ("HD02#FOTKY MAMKA", S + "#SERVER/Y/HD02#FOTKY MAMKA/%"),
    ("DropboxFotky",     S + "DropboxFotky/%"),
    ("HD02#DVD OSOBNI",  S + "HD02#DVD OSOBNI/%"),
    ("Fotky",            S + "Fotky/%"),
]

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

total = 0
for popis, like in LIKES:
    cur.execute("""
        UPDATE photos p SET wanted=TRUE, category='Rodina'
        FROM zaloha_obrazku z
        WHERE p.zaloha_id=z.id AND z.cesta_zalohy LIKE %s
          AND (p.wanted=FALSE OR p.category IS DISTINCT FROM 'Rodina')
    """, (like,))
    print(f"  {popis:18s}: {cur.rowcount:,}")
    total += cur.rowcount

print(f"\nHotovo. Celkem nově/změněno na Rodina: {total:,}")
conn.close()
