Files
damir 007825acee Bug hunt V7:
DB:
- Aggressive je_klub=false flag for programs/treninzi/totals (>100K€ no klub_id)
- 53 ne-klubovi flagged false (RSS Rijeka ukupni, Stručni rad, Potpora loptačkim, etc)

Frontend (sport2.html):
- Panel back button (← Natrag) + history stack
- window._panelHistory + pushPanelState + panelBack functions
- closePanel resets history
2026-05-05 14:56:53 +02:00

70 lines
2.7 KiB
Python

#!/usr/bin/env python3
"""TZ Kvarner + sve TZ PGZ."""
import sys, json, time
sys.path.insert(0, "/opt/pgz-sport/scrapers/harvesters")
from _common import (fetch, extract_text, extract_title, chunk_text,
upsert_facts, find_internal_links, DSN)
from urllib.parse import urlparse
import psycopg2
TZ_SITES = {
"tz_kvarner": ["https://www.kvarner.hr/"],
"tz_rijeka": ["https://www.visitrijeka.hr/"],
"tz_opatija": ["https://www.visitopatija.com/"],
"tz_crikvenica": ["https://www.tz-crikvenica.hr/"],
"tz_krk": ["https://www.krk.hr/"],
"tz_rab": ["https://www.rab-visit.com/"],
"tz_cres": ["https://www.tzg-cres.hr/"],
"tz_losinj": ["https://www.visitlosinj.hr/"],
"tz_gorski_kotar": ["https://www.gorskikotar.hr/"],
"tz_baska": ["https://www.tz-baska.hr/"],
"tz_lovran": ["https://www.tz-lovran.hr/"],
"tz_kastav": ["https://www.tz-kastav.hr/"],
}
def crawl(name, urls, max_pages=20):
conn = psycopg2.connect(DSN); conn.autocommit = True
visited = set(); queue = list(urls); facts = 0
while queue and len(visited) < max_pages:
url = queue.pop(0)
if url in visited: continue
visited.add(url)
html, status = fetch(url, timeout=15)
if not html or status != 200: continue
title = extract_title(html); text = extract_text(html)
if not text or len(text) < 200: continue
ff = []
if title and len(title) > 8:
ff.append({"fact": f"{name} - {title}", "url": url, "title": title})
for c in chunk_text(text, 800):
if len(c) > 100:
ff.append({"fact": c, "url": url, "title": title})
facts += upsert_facts(conn, ff, source_name=name,
category="turizam_pgz", confidence=0.85)
base = urlparse(url).hostname
for link in find_internal_links(html, url):
if link not in visited and (urlparse(link).hostname or "") == base and len(queue) < 80:
queue.append(link)
time.sleep(0.4)
conn.close()
return {"name": name, "visited": len(visited), "facts": facts}
def main():
results = []
for name, urls in TZ_SITES.items():
try:
r = crawl(name, urls, max_pages=20)
print(f" {name:25} {r['visited']:>3}p {r['facts']:>5}f")
results.append(r)
except Exception as e:
print(f" {name:25} FAIL: {str(e)[:60]}")
total = sum(r.get("facts", 0) for r in results)
print(f"=== TOTAL: {total} ===")
print(json.dumps({"tz_count": len(results), "total_facts": total}))
if __name__ == "__main__":
main()