ae9c4e2bfd
DB: pgz_sport.sportski_objekti (103 objekti, 103 s geo, 60 s adresom, 31 tip) API: - /api/v2/sportski-objekti (filter: tip, grad, sport, q) - /api/v2/sportski-objekti/meta (tipovi, gradovi, sportovi, ukupno) Frontend: - /static/objekti.html — Leaflet (OpenStreetMap) interactive map - 3 dropdown filter (tip, grad, sport) + search - Side panel s listom + map markers s ikonama (🏟️⚽🏊⛵🎿🎳⛸️🎯🥌🏃) - Popup: naziv, tip, kapacitet, adresa, upravitelj, izgradeno, sportovi, web link, Google Maps link - /objekti, /sport/objekti, /sport/api/v2/sportski-objekti routes Sidebar app.html: +Sportski objekti link Background: scripts/objekti_enrich_address.py (Nominatim reverse-geocode 60 objekata bez adrese)
67 lines
2.6 KiB
Python
67 lines
2.6 KiB
Python
#!/usr/bin/env python3
|
|
"""NGO i udruge PGŽ — mladi, veterani, humanitarne."""
|
|
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
|
|
|
|
NGO = {
|
|
"mladi_pgz": ["https://www.pgz.hr/mladi/"],
|
|
"udruge_pgz": ["https://www.udruge.hr/pgz"],
|
|
"humanitarne_pgz": ["https://www.volonterski-centar-ri.hr/"],
|
|
"crveni_kriz_full": ["https://www.crveni-kriz-rijeka.hr/"],
|
|
"veterani_pgz": ["https://www.veterani.hr/pgz"],
|
|
"umirovljenici_pgz": ["https://www.savez-umirovljenika.hr/"],
|
|
"invalidi_pgz": ["https://www.invalidi-rijeka.hr/"],
|
|
"zivotrodi_pgz": ["https://www.zivotrodi.hr/"],
|
|
"omladina_ri": ["https://www.omladina-rijeka.hr/"],
|
|
}
|
|
|
|
|
|
def crawl(name, urls, max_pages=10):
|
|
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="ngo_pgz", confidence=0.84)
|
|
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) < 25:
|
|
queue.append(link)
|
|
time.sleep(0.5)
|
|
conn.close()
|
|
return {"name": name, "visited": len(visited), "facts": facts}
|
|
|
|
|
|
def main():
|
|
results = []
|
|
for name, urls in NGO.items():
|
|
try:
|
|
r = crawl(name, urls, max_pages=8)
|
|
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({"ngo_count": len(results), "total_facts": total}))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|