Track first_seen/last_changed per property, add map filters and clickable legend
All checks were successful
Build and Push / build (push) Successful in 6s
All checks were successful
Build and Push / build (push) Successful in 6s
Scraper changes (all 6 sources): - Add first_seen: date the hash_id was first scraped, never overwritten - Add last_changed: date the price last changed (= first_seen when new) - PSN and CityHome load previous output as a lightweight cache to compute these fields - merge_and_map.py preserves earliest first_seen when deduplicating cross-source duplicates Map popup: - Show "Přidáno: YYYY-MM-DD" and "Změněno: YYYY-MM-DD" in each property popup - NOVÉ badge and pulsing marker now driven by first_seen == today (more accurate than scraped_at) Map filters (sidebar): - New "Přidáno / změněno" dropdown: 1, 2, 3, 4, 5, 7, 14, 30 days or all - Clickable price/m² legend bands: click to filter to that band, multi-select supported - "✕ Zobrazit všechny ceny" reset link appears when any band is active Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -353,6 +353,8 @@ def scrape(max_pages: int | None = None, max_properties: int | None = None):
|
||||
"url": sreality_url(hash_id, seo),
|
||||
"image": (estate.get("_links", {}).get("images", [{}])[0].get("href", "") if estate.get("_links", {}).get("images") else ""),
|
||||
"scraped_at": datetime.now().strftime("%Y-%m-%d"),
|
||||
"first_seen": cached.get("first_seen", datetime.now().strftime("%Y-%m-%d")) if cached else datetime.now().strftime("%Y-%m-%d"),
|
||||
"last_changed": datetime.now().strftime("%Y-%m-%d"),
|
||||
}
|
||||
results.append(result)
|
||||
details_fetched += 1
|
||||
@@ -429,11 +431,19 @@ def generate_map(estates: list[dict], output_path: str = "mapa_bytu.html"):
|
||||
]
|
||||
for bcolor, blabel in bands:
|
||||
price_legend_items += (
|
||||
f'<div style="display:flex;align-items:center;gap:6px;margin:2px 0;">'
|
||||
f'<div class="price-band" data-color="{bcolor}" onclick="toggleColorFilter(\'{bcolor}\')" '
|
||||
f'style="display:flex;align-items:center;gap:6px;margin:2px 0;padding:2px 4px;'
|
||||
f'border-radius:4px;border:2px solid transparent;">'
|
||||
f'<span style="width:14px;height:14px;border-radius:50%;background:{bcolor};'
|
||||
f'display:inline-block;border:2px solid white;box-shadow:0 1px 3px rgba(0,0,0,0.3);flex-shrink:0;"></span>'
|
||||
f'<span>{blabel}</span></div>'
|
||||
)
|
||||
price_legend_items += (
|
||||
'<div id="price-filter-reset" style="display:none;margin:3px 0 0 4px;">'
|
||||
'<a href="#" onclick="resetColorFilter();return false;" '
|
||||
'style="font-size:11px;color:#1976D2;text-decoration:none;">✕ Zobrazit všechny ceny</a>'
|
||||
'</div>'
|
||||
)
|
||||
# New marker indicator — bigger dot, no extra border
|
||||
price_legend_items += (
|
||||
'<div style="display:flex;align-items:center;gap:6px;margin:6px 0 0 0;'
|
||||
@@ -464,16 +474,28 @@ def generate_map(estates: list[dict], output_path: str = "mapa_bytu.html"):
|
||||
|
||||
hash_id = e.get("hash_id", "")
|
||||
|
||||
scraped_at = e.get("scraped_at", "")
|
||||
is_new = scraped_at == datetime.now().strftime("%Y-%m-%d")
|
||||
first_seen = e.get("first_seen", "")
|
||||
last_changed = e.get("last_changed", "")
|
||||
is_new = first_seen == datetime.now().strftime("%Y-%m-%d")
|
||||
|
||||
new_badge = (
|
||||
'<span style="margin-left:6px;font-size:11px;background:#FFD600;color:#333;'
|
||||
'padding:1px 6px;border-radius:3px;font-weight:bold;">NOVÉ</span>'
|
||||
if is_new else ""
|
||||
)
|
||||
|
||||
date_parts = []
|
||||
if first_seen:
|
||||
date_parts.append(f'Přidáno: {first_seen}')
|
||||
if last_changed and last_changed != first_seen:
|
||||
date_parts.append(f'Změněno: {last_changed}')
|
||||
date_row = (
|
||||
f'<span style="font-size:11px;color:#888;">{" · ".join(date_parts)}</span><br>'
|
||||
if date_parts else ""
|
||||
)
|
||||
|
||||
popup = (
|
||||
f'<div style="min-width:280px;font-family:system-ui,sans-serif;" data-hashid="{hash_id}">'
|
||||
f'<div style="min-width:280px;font-family:system-ui,sans-serif;" data-hashid="{hash_id}" data-first-seen="{first_seen}" data-last-changed="{last_changed}">'
|
||||
f'<b style="font-size:14px;">{format_price(e["price"])}</b>'
|
||||
f'<span style="margin-left:8px;font-size:11px;background:{source_color};color:white;'
|
||||
f'padding:1px 6px;border-radius:3px;">{source_label}</span>{new_badge}<br>'
|
||||
@@ -481,7 +503,9 @@ def generate_map(estates: list[dict], output_path: str = "mapa_bytu.html"):
|
||||
f'{floor_note}<br><br>'
|
||||
f'<b>{e["locality"]}</b><br>'
|
||||
f'Stavba: {building_text}<br>'
|
||||
f'Vlastnictví: {ownership_text}<br><br>'
|
||||
f'Vlastnictví: {ownership_text}<br>'
|
||||
f'{date_row}'
|
||||
f'<br>'
|
||||
f'<a href="{e["url"]}" target="_blank" '
|
||||
f'style="color:{source_color};text-decoration:none;font-weight:bold;">'
|
||||
f'→ Otevřít na {source_label}</a>'
|
||||
@@ -513,7 +537,7 @@ def generate_map(estates: list[dict], output_path: str = "mapa_bytu.html"):
|
||||
else:
|
||||
marker_fn = "addMarker"
|
||||
markers_js += (
|
||||
f" {marker_fn}({e['lat']}, {e['lon']}, '{color}', '{popup}', '{hash_id}');\n"
|
||||
f" {marker_fn}({e['lat']}, {e['lon']}, '{color}', '{popup}', '{hash_id}', '{first_seen}', '{last_changed}');\n"
|
||||
)
|
||||
|
||||
# Build legend — price per m² bands + disposition counts
|
||||
@@ -617,6 +641,10 @@ def generate_map(estates: list[dict], output_path: str = "mapa_bytu.html"):
|
||||
.info-panel .stats {{ color: #666; margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px solid #eee; }}
|
||||
.filter-section {{ margin-top: 10px; padding-top: 10px; border-top: 1px solid #eee; }}
|
||||
.filter-section label {{ display: flex; align-items: center; gap: 6px; margin: 3px 0; cursor: pointer; }}
|
||||
.price-band {{ cursor: pointer; transition: background 0.12s; }}
|
||||
.price-band:hover {{ background: #f0f0f0; }}
|
||||
.price-band.active {{ border-color: #333 !important; background: #e8f0fe; }}
|
||||
.price-band.dimmed {{ opacity: 0.35; }}
|
||||
.filter-section input[type="checkbox"] {{ accent-color: #1976D2; }}
|
||||
#floor-filter {{ margin-top: 8px; }}
|
||||
#floor-filter select {{ width: 100%; padding: 4px; border-radius: 4px; border: 1px solid #ccc; }}
|
||||
@@ -663,6 +691,21 @@ def generate_map(estates: list[dict], output_path: str = "mapa_bytu.html"):
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
<div style="margin-top:6px;">
|
||||
<label>Přidáno / změněno:
|
||||
<select id="days-filter" onchange="applyFilters()" style="width:100%;padding:4px;border-radius:4px;border:1px solid #ccc;">
|
||||
<option value="0">Vše</option>
|
||||
<option value="1">za 1 den</option>
|
||||
<option value="2">za 2 dny</option>
|
||||
<option value="3">za 3 dny</option>
|
||||
<option value="4">za 4 dny</option>
|
||||
<option value="5">za 5 dní</option>
|
||||
<option value="7">za 7 dní</option>
|
||||
<option value="14">za 14 dní</option>
|
||||
<option value="30">za 30 dní</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="filter-section">
|
||||
<div id="rating-counts" style="margin-bottom:6px;font-size:12px;color:#666;">
|
||||
@@ -693,9 +736,39 @@ L.tileLayer('https://{{s}}.basemaps.cartocdn.com/light_only_labels/{{z}}/{{x}}/{
|
||||
pane: 'shadowPane',
|
||||
}}).addTo(map);
|
||||
|
||||
var selectedColors = [];
|
||||
|
||||
function toggleColorFilter(color) {{
|
||||
var idx = selectedColors.indexOf(color);
|
||||
if (idx >= 0) selectedColors.splice(idx, 1);
|
||||
else selectedColors.push(color);
|
||||
document.querySelectorAll('.price-band').forEach(function(el) {{
|
||||
var c = el.getAttribute('data-color');
|
||||
if (selectedColors.length === 0) {{
|
||||
el.classList.remove('active', 'dimmed');
|
||||
}} else if (selectedColors.indexOf(c) >= 0) {{
|
||||
el.classList.add('active'); el.classList.remove('dimmed');
|
||||
}} else {{
|
||||
el.classList.add('dimmed'); el.classList.remove('active');
|
||||
}}
|
||||
}});
|
||||
document.getElementById('price-filter-reset').style.display =
|
||||
selectedColors.length > 0 ? 'block' : 'none';
|
||||
applyFilters();
|
||||
}}
|
||||
|
||||
function resetColorFilter() {{
|
||||
selectedColors = [];
|
||||
document.querySelectorAll('.price-band').forEach(function(el) {{
|
||||
el.classList.remove('active', 'dimmed');
|
||||
}});
|
||||
document.getElementById('price-filter-reset').style.display = 'none';
|
||||
applyFilters();
|
||||
}}
|
||||
|
||||
var allMarkers = [];
|
||||
|
||||
function addMarker(lat, lon, color, popup, hashId) {{
|
||||
function addMarker(lat, lon, color, popup, hashId, firstSeen, lastChanged) {{
|
||||
var marker = L.circleMarker([lat, lon], {{
|
||||
radius: 8,
|
||||
fillColor: color,
|
||||
@@ -704,12 +777,12 @@ function addMarker(lat, lon, color, popup, hashId) {{
|
||||
opacity: 1,
|
||||
fillOpacity: 0.85,
|
||||
}}).bindPopup(popup);
|
||||
marker._data = {{ lat: lat, lon: lon, color: color, hashId: hashId }};
|
||||
marker._data = {{ lat: lat, lon: lon, color: color, hashId: hashId, firstSeen: firstSeen || '', lastChanged: lastChanged || '' }};
|
||||
allMarkers.push(marker);
|
||||
marker.addTo(map);
|
||||
}}
|
||||
|
||||
function addNewMarker(lat, lon, color, popup, hashId) {{
|
||||
function addNewMarker(lat, lon, color, popup, hashId, firstSeen, lastChanged) {{
|
||||
var marker = L.circleMarker([lat, lon], {{
|
||||
radius: 12,
|
||||
fillColor: color,
|
||||
@@ -718,7 +791,7 @@ function addNewMarker(lat, lon, color, popup, hashId) {{
|
||||
opacity: 0.35,
|
||||
fillOpacity: 0.95,
|
||||
}}).bindPopup(popup);
|
||||
marker._data = {{ lat: lat, lon: lon, color: color, hashId: hashId, isNew: true }};
|
||||
marker._data = {{ lat: lat, lon: lon, color: color, hashId: hashId, isNew: true, firstSeen: firstSeen || '', lastChanged: lastChanged || '' }};
|
||||
allMarkers.push(marker);
|
||||
marker.addTo(map);
|
||||
marker.on('add', function() {{
|
||||
@@ -756,11 +829,11 @@ function starIcon() {{
|
||||
}});
|
||||
}}
|
||||
|
||||
function addHeartMarker(lat, lon, color, popup, hashId) {{
|
||||
function addHeartMarker(lat, lon, color, popup, hashId, firstSeen, lastChanged) {{
|
||||
var marker = L.marker([lat, lon], {{
|
||||
icon: heartIcon(color),
|
||||
}}).bindPopup(popup);
|
||||
marker._data = {{ lat: lat, lon: lon, color: color, hashId: hashId, isHeart: true }};
|
||||
marker._data = {{ lat: lat, lon: lon, color: color, hashId: hashId, isHeart: true, firstSeen: firstSeen || '', lastChanged: lastChanged || '' }};
|
||||
allMarkers.push(marker);
|
||||
marker.addTo(map);
|
||||
}}
|
||||
@@ -1018,9 +1091,17 @@ function applyFilters() {{
|
||||
var minFloor = parseInt(document.getElementById('min-floor').value);
|
||||
var maxPrice = parseInt(document.getElementById('max-price').value);
|
||||
var hideRejected = document.getElementById('hide-rejected').checked;
|
||||
var daysFilter = parseInt(document.getElementById('days-filter').value) || 0;
|
||||
var ratings = loadRatings();
|
||||
var visible = 0;
|
||||
|
||||
var cutoff = null;
|
||||
if (daysFilter > 0) {{
|
||||
cutoff = new Date();
|
||||
cutoff.setDate(cutoff.getDate() - daysFilter);
|
||||
cutoff.setHours(0, 0, 0, 0);
|
||||
}}
|
||||
|
||||
allMarkers.forEach(function(m) {{
|
||||
var popup = m.getPopup().getContent();
|
||||
var floorMatch = popup.match(/(\\d+)\\. NP/);
|
||||
@@ -1033,6 +1114,14 @@ function applyFilters() {{
|
||||
if (floor !== null && floor < minFloor) show = false;
|
||||
if (price > maxPrice) show = false;
|
||||
|
||||
if (cutoff) {{
|
||||
var fs = m._data.firstSeen ? new Date(m._data.firstSeen) : null;
|
||||
var lc = m._data.lastChanged ? new Date(m._data.lastChanged) : null;
|
||||
if (!((fs && fs >= cutoff) || (lc && lc >= cutoff))) show = false;
|
||||
}}
|
||||
|
||||
if (selectedColors.length > 0 && selectedColors.indexOf(m._data.color) < 0) show = false;
|
||||
|
||||
var r = ratings[m._data.hashId];
|
||||
if (hideRejected && r && r.status === 'reject') show = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user