git
This commit is contained in:
+1
Submodule .claude/worktrees/reverent-murdock-bb6043 added at 090bf62bd6
@@ -23,11 +23,16 @@ import urllib.parse as urlparse
|
|||||||
# CONFIG
|
# CONFIG
|
||||||
# ============================================================
|
# ============================================================
|
||||||
|
|
||||||
|
# -1 = zastavit při prvním nalezeném v DB (původní chování)
|
||||||
|
# 0 = zkontrolovat všechny torrenty (projít vše)
|
||||||
|
# N = zkontrolovat posledních N torrentů zpětně
|
||||||
|
HOW_MANY_TO_CHECK = 0
|
||||||
|
|
||||||
COOKIE_FILE = Path("sktorrent_cookies.json")
|
COOKIE_FILE = Path("sktorrent_cookies.json")
|
||||||
|
|
||||||
BASE_URL = (
|
BASE_URL = (
|
||||||
"https://sktorrent.eu/torrent/torrents.php"
|
"https://sktorrent.eu/torrent/torrents.php"
|
||||||
"?active=0&category=24&order=data&by=DESC"
|
"?active=0&category=23&order=data&by=DESC"
|
||||||
)
|
)
|
||||||
|
|
||||||
SLEEP_BETWEEN_PAGES = 2.0 # pauza mezi stránkami
|
SLEEP_BETWEEN_PAGES = 2.0 # pauza mezi stránkami
|
||||||
@@ -209,7 +214,13 @@ def main():
|
|||||||
print("=" * 60)
|
print("=" * 60)
|
||||||
print("INCREMENTAL IMPORT — sktorrent.eu")
|
print("INCREMENTAL IMPORT — sktorrent.eu")
|
||||||
print(f"Spuštěno: {datetime.now():%Y-%m-%d %H:%M:%S}")
|
print(f"Spuštěno: {datetime.now():%Y-%m-%d %H:%M:%S}")
|
||||||
print("Pořadí: nejnovější → nejstarší | stop při první shodě")
|
if HOW_MANY_TO_CHECK == -1:
|
||||||
|
mode_desc = "stop při první shodě"
|
||||||
|
elif HOW_MANY_TO_CHECK == 0:
|
||||||
|
mode_desc = "kontrola VŠECH torrentů"
|
||||||
|
else:
|
||||||
|
mode_desc = f"kontrola posledních {HOW_MANY_TO_CHECK} torrentů"
|
||||||
|
print(f"Pořadí: nejnovější → nejstarší | {mode_desc}")
|
||||||
print("=" * 60)
|
print("=" * 60)
|
||||||
|
|
||||||
session = build_session()
|
session = build_session()
|
||||||
@@ -217,17 +228,27 @@ def main():
|
|||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
|
|
||||||
new_count = 0
|
new_count = 0
|
||||||
|
checked_count = 0
|
||||||
|
skipped_count = 0
|
||||||
page = 0
|
page = 0
|
||||||
stop = False
|
stop = False
|
||||||
|
|
||||||
while not stop:
|
while not stop:
|
||||||
|
|
||||||
url = f"{BASE_URL}&page={page}"
|
url = f"{BASE_URL}&page={page}"
|
||||||
|
r = None
|
||||||
|
for attempt in range(1, 6):
|
||||||
try:
|
try:
|
||||||
r = session.get(url, timeout=15)
|
r = session.get(url, timeout=15)
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
|
break
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"⚠️ Stránka {page} — chyba: {e}")
|
if attempt < 5:
|
||||||
|
print(f"⚠️ Stránka {page} — pokus {attempt}/5 selhal: {e} — čekám 10s")
|
||||||
|
time.sleep(10)
|
||||||
|
else:
|
||||||
|
print(f"⚠️ Stránka {page} — všech 5 pokusů selhalo: {e}")
|
||||||
|
if r is None or not r.ok:
|
||||||
break
|
break
|
||||||
|
|
||||||
if "login.php" in r.url or "Prihlas sa" in r.text:
|
if "login.php" in r.url or "Prihlas sa" in r.text:
|
||||||
@@ -244,7 +265,13 @@ def main():
|
|||||||
|
|
||||||
for item in rows:
|
for item in rows:
|
||||||
|
|
||||||
# Zkontroluj DB
|
if HOW_MANY_TO_CHECK > 0 and checked_count >= HOW_MANY_TO_CHECK:
|
||||||
|
print(f" ⏹ Zkontrolováno {checked_count} torrentů — limit dosažen.")
|
||||||
|
stop = True
|
||||||
|
break
|
||||||
|
|
||||||
|
checked_count += 1
|
||||||
|
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
"SELECT 1 FROM torrents WHERE torrent_hash = %s",
|
"SELECT 1 FROM torrents WHERE torrent_hash = %s",
|
||||||
(item["torrent_hash"],)
|
(item["torrent_hash"],)
|
||||||
@@ -252,11 +279,15 @@ def main():
|
|||||||
exists = cursor.fetchone()
|
exists = cursor.fetchone()
|
||||||
|
|
||||||
if exists:
|
if exists:
|
||||||
|
if HOW_MANY_TO_CHECK == -1:
|
||||||
print(f" ⏹ Již v DB: {item['title_visible']} → zastavuji import.")
|
print(f" ⏹ Již v DB: {item['title_visible']} → zastavuji import.")
|
||||||
stop = True
|
stop = True
|
||||||
break
|
break
|
||||||
|
else:
|
||||||
|
skipped_count += 1
|
||||||
|
print(f" ⏭ Již v DB: {item['title_visible']} — přeskakuji")
|
||||||
|
continue
|
||||||
|
|
||||||
# Nový torrent — stáhni .torrent soubor
|
|
||||||
print(f" ⬇️ Nový: {item['title_visible']}")
|
print(f" ⬇️ Nový: {item['title_visible']}")
|
||||||
time.sleep(SLEEP_BEFORE_DOWNLOAD)
|
time.sleep(SLEEP_BEFORE_DOWNLOAD)
|
||||||
|
|
||||||
@@ -281,6 +312,8 @@ def main():
|
|||||||
print("=" * 60)
|
print("=" * 60)
|
||||||
print(f"Hotovo: {datetime.now():%Y-%m-%d %H:%M:%S}")
|
print(f"Hotovo: {datetime.now():%Y-%m-%d %H:%M:%S}")
|
||||||
print(f"Nových torrentů uloženo : {new_count}")
|
print(f"Nových torrentů uloženo : {new_count}")
|
||||||
|
print(f"Zkontrolováno celkem : {checked_count}")
|
||||||
|
print(f"Přeskočeno (v DB) : {skipped_count}")
|
||||||
print(f"Stránek prošlo : {page}")
|
print(f"Stránek prošlo : {page}")
|
||||||
print("=" * 60)
|
print("=" * 60)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user