git
This commit is contained in:
@@ -6,7 +6,7 @@ from datetime import datetime
|
|||||||
# CONFIG
|
# CONFIG
|
||||||
# ============================================================
|
# ============================================================
|
||||||
|
|
||||||
DRY_RUN = False # ← změň na True pokud chceš test
|
DRY_RUN = False # ← change to True for testing
|
||||||
|
|
||||||
QBT_URL = "https://vladob.zen.usbx.me/qbittorrent"
|
QBT_URL = "https://vladob.zen.usbx.me/qbittorrent"
|
||||||
QBT_USER = "vladob"
|
QBT_USER = "vladob"
|
||||||
@@ -22,7 +22,6 @@ DB_CONFIG = {
|
|||||||
"autocommit": True,
|
"autocommit": True,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# ============================================================
|
# ============================================================
|
||||||
# CONNECT
|
# CONNECT
|
||||||
# ============================================================
|
# ============================================================
|
||||||
@@ -49,6 +48,8 @@ def connect_db():
|
|||||||
def main():
|
def main():
|
||||||
|
|
||||||
print("🚀 UltraCC completed torrent cleanup")
|
print("🚀 UltraCC completed torrent cleanup")
|
||||||
|
print(f"DRY_RUN = {DRY_RUN}")
|
||||||
|
print("------------------------------------------------")
|
||||||
|
|
||||||
qbt = connect_qbt()
|
qbt = connect_qbt()
|
||||||
db = connect_db()
|
db = connect_db()
|
||||||
@@ -58,11 +59,12 @@ def main():
|
|||||||
|
|
||||||
removed_count = 0
|
removed_count = 0
|
||||||
skipped_count = 0
|
skipped_count = 0
|
||||||
|
updated_db_count = 0
|
||||||
|
|
||||||
for t in torrents:
|
for t in torrents:
|
||||||
|
|
||||||
# ----------------------------------------------------
|
# ----------------------------------------------------
|
||||||
# Test completed via completion_on
|
# Only completed torrents
|
||||||
# ----------------------------------------------------
|
# ----------------------------------------------------
|
||||||
if not t.completion_on:
|
if not t.completion_on:
|
||||||
continue
|
continue
|
||||||
@@ -70,11 +72,10 @@ def main():
|
|||||||
thash = t.hash.lower()
|
thash = t.hash.lower()
|
||||||
name = t.name
|
name = t.name
|
||||||
state = t.state
|
state = t.state
|
||||||
|
|
||||||
completion_dt = datetime.fromtimestamp(t.completion_on)
|
completion_dt = datetime.fromtimestamp(t.completion_on)
|
||||||
|
|
||||||
# ----------------------------------------------------
|
# ----------------------------------------------------
|
||||||
# Skip pokud už DB má completion
|
# Check DB
|
||||||
# ----------------------------------------------------
|
# ----------------------------------------------------
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
SELECT qb_completed_datetime
|
SELECT qb_completed_datetime
|
||||||
@@ -84,40 +85,64 @@ def main():
|
|||||||
|
|
||||||
row = cursor.fetchone()
|
row = cursor.fetchone()
|
||||||
|
|
||||||
if row and row[0]:
|
# ====================================================
|
||||||
skipped_count += 1
|
# CASE 1 — Torrent completed in qBittorrent but NOT in DB
|
||||||
|
# → Update DB + Remove torrent
|
||||||
|
# ====================================================
|
||||||
|
if not row or not row[0]:
|
||||||
|
|
||||||
|
print(f"✔ COMPLETED (DB update required): {name}")
|
||||||
|
print(f" Completion time: {completion_dt}")
|
||||||
|
|
||||||
|
if not DRY_RUN:
|
||||||
|
cursor.execute("""
|
||||||
|
UPDATE torrents
|
||||||
|
SET
|
||||||
|
qb_state = %s,
|
||||||
|
qb_progress = 1,
|
||||||
|
qb_completed_datetime = %s,
|
||||||
|
qb_last_update = NOW()
|
||||||
|
WHERE torrent_hash = %s
|
||||||
|
""", (f"completed_removed ({state})", completion_dt, thash))
|
||||||
|
|
||||||
|
updated_db_count += 1
|
||||||
|
|
||||||
|
# Remove torrent
|
||||||
|
if DRY_RUN:
|
||||||
|
print(" [DRY] Would remove torrent")
|
||||||
|
else:
|
||||||
|
qbt.torrents_delete(delete_files=False, torrent_hashes=thash)
|
||||||
|
removed_count += 1
|
||||||
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
print(f"✔ COMPLETED: {name}")
|
# ====================================================
|
||||||
print(f" Completion time: {completion_dt}")
|
# CASE 2 — Torrent completed in qBittorrent AND already completed in DB
|
||||||
|
# → Just remove torrent
|
||||||
|
# ====================================================
|
||||||
|
if row and row[0]:
|
||||||
|
|
||||||
# ----------------------------------------------------
|
print(f"✔ COMPLETED (Already in DB → removing): {name}")
|
||||||
# UPDATE DB
|
|
||||||
# ----------------------------------------------------
|
|
||||||
if not DRY_RUN:
|
|
||||||
cursor.execute("""
|
|
||||||
UPDATE torrents
|
|
||||||
SET
|
|
||||||
qb_state = %s,
|
|
||||||
qb_progress = 1,
|
|
||||||
qb_completed_datetime = %s,
|
|
||||||
qb_last_update = NOW()
|
|
||||||
WHERE torrent_hash = %s
|
|
||||||
""", (f"completed_removed ({state})", completion_dt, thash))
|
|
||||||
|
|
||||||
# ----------------------------------------------------
|
if DRY_RUN:
|
||||||
# REMOVE TORRENT
|
print(" [DRY] Would remove torrent")
|
||||||
# ----------------------------------------------------
|
else:
|
||||||
if DRY_RUN:
|
qbt.torrents_delete(delete_files=False, torrent_hashes=thash)
|
||||||
print(" [DRY] Would remove torrent")
|
removed_count += 1
|
||||||
else:
|
|
||||||
qbt.torrents_delete(delete_files=False, torrent_hashes=thash)
|
|
||||||
removed_count += 1
|
|
||||||
|
|
||||||
|
continue
|
||||||
|
|
||||||
|
skipped_count += 1
|
||||||
|
|
||||||
|
# =========================================================
|
||||||
|
# SUMMARY
|
||||||
|
# =========================================================
|
||||||
|
print("------------------------------------------------")
|
||||||
|
print(f"Removed torrents : {removed_count}")
|
||||||
|
print(f"DB updated : {updated_db_count}")
|
||||||
|
print(f"Skipped torrents : {skipped_count}")
|
||||||
|
print(f"DRY_RUN : {DRY_RUN}")
|
||||||
print("------------------------------------------------")
|
print("------------------------------------------------")
|
||||||
print(f"Removed torrents : {removed_count}")
|
|
||||||
print(f"Skipped torrents : {skipped_count}")
|
|
||||||
print(f"DRY_RUN = {DRY_RUN}")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
124
Seedbox/41 ČištěníOneTimeTest.py
Normal file
124
Seedbox/41 ČištěníOneTimeTest.py
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
import pymysql
|
||||||
|
import qbittorrentapi
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# CONFIG
|
||||||
|
# ============================================================
|
||||||
|
|
||||||
|
QBT_URL = "https://vladob.zen.usbx.me/qbittorrent"
|
||||||
|
QBT_USER = "vladob"
|
||||||
|
QBT_PASS = "jCni3U6d#y4bfcm"
|
||||||
|
|
||||||
|
DB_CONFIG = {
|
||||||
|
"host": "192.168.1.50",
|
||||||
|
"port": 3306,
|
||||||
|
"user": "root",
|
||||||
|
"password": "Vlado9674+",
|
||||||
|
"database": "torrents",
|
||||||
|
"charset": "utf8mb4",
|
||||||
|
"autocommit": True,
|
||||||
|
}
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# CONNECT
|
||||||
|
# ============================================================
|
||||||
|
|
||||||
|
def connect_qbt():
|
||||||
|
qbt = qbittorrentapi.Client(
|
||||||
|
host=QBT_URL,
|
||||||
|
username=QBT_USER,
|
||||||
|
password=QBT_PASS,
|
||||||
|
VERIFY_WEBUI_CERTIFICATE=False
|
||||||
|
)
|
||||||
|
qbt.auth_log_in()
|
||||||
|
return qbt
|
||||||
|
|
||||||
|
|
||||||
|
def connect_db():
|
||||||
|
return pymysql.connect(**DB_CONFIG)
|
||||||
|
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# MAIN AUDIT
|
||||||
|
# ============================================================
|
||||||
|
|
||||||
|
def main():
|
||||||
|
|
||||||
|
print("🔎 UltraCC → DB COMPLETION AUDIT")
|
||||||
|
print("READ ONLY MODE")
|
||||||
|
print("------------------------------------------------")
|
||||||
|
|
||||||
|
qbt = connect_qbt()
|
||||||
|
db = connect_db()
|
||||||
|
cursor = db.cursor()
|
||||||
|
|
||||||
|
torrents = qbt.torrents_info()
|
||||||
|
|
||||||
|
total_completed = 0
|
||||||
|
not_in_db = 0
|
||||||
|
db_no_completion = 0
|
||||||
|
db_completed = 0
|
||||||
|
|
||||||
|
for t in torrents:
|
||||||
|
|
||||||
|
# Only completed torrents
|
||||||
|
if not t.completion_on:
|
||||||
|
continue
|
||||||
|
|
||||||
|
total_completed += 1
|
||||||
|
|
||||||
|
thash = t.hash.lower()
|
||||||
|
name = t.name
|
||||||
|
completion_dt = datetime.fromtimestamp(t.completion_on)
|
||||||
|
|
||||||
|
# ---------------------------------------------
|
||||||
|
# Query DB
|
||||||
|
# ---------------------------------------------
|
||||||
|
cursor.execute("""
|
||||||
|
SELECT qb_completed_datetime
|
||||||
|
FROM torrents
|
||||||
|
WHERE torrent_hash = %s
|
||||||
|
""", (thash,))
|
||||||
|
|
||||||
|
row = cursor.fetchone()
|
||||||
|
|
||||||
|
# ---------------------------------------------
|
||||||
|
# Status classification
|
||||||
|
# ---------------------------------------------
|
||||||
|
if not row:
|
||||||
|
status = "❌ NOT_IN_DB"
|
||||||
|
not_in_db += 1
|
||||||
|
|
||||||
|
elif row[0] is None:
|
||||||
|
status = "⚠ DB_NO_COMPLETION"
|
||||||
|
db_no_completion += 1
|
||||||
|
|
||||||
|
else:
|
||||||
|
status = "✅ DB_COMPLETED"
|
||||||
|
db_completed += 1
|
||||||
|
|
||||||
|
# ---------------------------------------------
|
||||||
|
# Output
|
||||||
|
# ---------------------------------------------
|
||||||
|
print(f"{status} | {name}")
|
||||||
|
print(f" Hash: {thash}")
|
||||||
|
print(f" UltraCC completion: {completion_dt}")
|
||||||
|
if row and row[0]:
|
||||||
|
print(f" DB completion : {row[0]}")
|
||||||
|
print()
|
||||||
|
|
||||||
|
# =================================================
|
||||||
|
# SUMMARY
|
||||||
|
# =================================================
|
||||||
|
print("------------------------------------------------")
|
||||||
|
print("📊 SUMMARY")
|
||||||
|
print(f"Completed torrents in UltraCC : {total_completed}")
|
||||||
|
print(f"NOT IN DB : {not_in_db}")
|
||||||
|
print(f"DB WITHOUT COMPLETION : {db_no_completion}")
|
||||||
|
print(f"DB COMPLETED : {db_completed}")
|
||||||
|
print("------------------------------------------------")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Reference in New Issue
Block a user