File size: 43,076 Bytes
41c648b a31848d 41c648b a31848d 1ed9393 41c648b 1ed9393 41c648b 1ed9393 41c648b a31848d 41c648b 1ed9393 a31848d 1ed9393 a31848d 1ed9393 a31848d 1ed9393 a31848d 1ed9393 a31848d 41c648b 1ed9393 a31848d 1ed9393 a31848d 41c648b a31848d 41c648b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Multifamily Apartment Scraper</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
.loading-spinner {
border: 4px solid rgba(0, 0, 0, 0.1);
border-radius: 50%;
border-top: 4px solid #3b82f6;
width: 40px;
height: 40px;
animation: spin 1s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.fade-in {
animation: fadeIn 0.3s ease-in;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
.card-hover:hover {
transform: translateY(-5px);
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
}
.transition-all {
transition: all 0.3s ease;
}
</style>
</head>
<body class="bg-gray-50 min-h-screen">
<div class="container mx-auto px-4 py-8">
<!-- Header -->
<header class="mb-10">
<div class="flex justify-between items-center">
<h1 class="text-3xl font-bold text-indigo-700">
<i class="fas fa-building mr-2"></i> Multifamily Scraper
</h1>
<div class="flex items-center space-x-4">
<button id="exportBtn" class="bg-green-600 hover:bg-green-700 text-white px-4 py-2 rounded-lg flex items-center">
<i class="fas fa-file-export mr-2"></i> Export Data
</button>
<button id="clearBtn" class="bg-red-500 hover:bg-red-600 text-white px-4 py-2 rounded-lg flex items-center">
<i class="fas fa-trash-alt mr-2"></i> Clear DB
</button>
</div>
</div>
<p class="text-gray-600 mt-2">Scrape and manage a database of multifamily apartment buildings</p>
</header>
<!-- Main Content -->
<div class="grid grid-cols-1 lg:grid-cols-3 gap-8">
<!-- Scraper Controls -->
<div class="bg-white p-6 rounded-xl shadow-md lg:col-span-1">
<h2 class="text-xl font-semibold text-gray-800 mb-4 flex items-center">
<i class="fas fa-cogs mr-2 text-indigo-500"></i> Scraper Settings
</h2>
<div class="space-y-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Target Website</label>
<select id="targetSite" class="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500">
<option value="apartments.com">Apartments.com</option>
<option value="zillow">Zillow Multifamily</option>
<option value="rentcafe">RentCafe</option>
<option value="realtor">Realtor.com</option>
<option value="redfin">Redfin</option>
<option value="loopnet">LoopNet</option>
<option value="crexi">CREXi</option>
<option value="cityfeet">CityFeet</option>
<option value="costar">CoStar</option>
<option value="reonomy">Reonomy</option>
<option value="custom">Custom URL</option>
</select>
</div>
<div id="customUrlContainer" class="hidden">
<label class="block text-sm font-medium text-gray-700 mb-1">Custom URL</label>
<input type="text" id="customUrl" placeholder="https://example.com" class="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Location</label>
<input type="text" id="location" placeholder="City, State or ZIP" class="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500">
</div>
<div class="grid grid-cols-2 gap-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Min Units</label>
<input type="number" id="minUnits" placeholder="5" class="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Max Units</label>
<input type="number" id="maxUnits" placeholder="100" class="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500">
</div>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Max Pages to Scrape</label>
<input type="number" id="maxPages" value="5" min="1" max="20" class="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500">
</div>
<div class="pt-2">
<button id="scrapeBtn" class="w-full bg-indigo-600 hover:bg-indigo-700 text-white py-3 px-4 rounded-lg font-medium flex items-center justify-center transition-all">
<span id="scrapeBtnText"><i class="fas fa-spider mr-2"></i> Start Scraping</span>
<div id="scrapeBtnSpinner" class="loading-spinner hidden"></div>
</button>
</div>
</div>
<div id="scrapingProgress" class="mt-6 hidden">
<div class="flex justify-between mb-1">
<span class="text-sm font-medium text-gray-700">Scraping Progress</span>
<span id="progressPercent" class="text-sm font-medium text-gray-700">0%</span>
</div>
<div class="w-full bg-gray-200 rounded-full h-2.5">
<div id="progressBar" class="bg-indigo-600 h-2.5 rounded-full" style="width: 0%"></div>
</div>
<div id="scrapingStatus" class="text-sm text-gray-500 mt-2">Preparing to scrape...</div>
</div>
</div>
<!-- Results Section -->
<div class="bg-white p-6 rounded-xl shadow-md lg:col-span-2">
<div class="flex justify-between items-center mb-6">
<h2 class="text-xl font-semibold text-gray-800 flex items-center">
<i class="fas fa-database mr-2 text-indigo-500"></i> Apartment Database
</h2>
<div class="relative">
<input type="text" id="searchInput" placeholder="Search properties..." class="pl-10 pr-4 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500">
<i class="fas fa-search absolute left-3 top-3 text-gray-400"></i>
</div>
</div>
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider cursor-pointer sortable" data-column="name">
Property <i class="fas fa-sort ml-1"></i>
</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider cursor-pointer sortable" data-column="units">
Units <i class="fas fa-sort ml-1"></i>
</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider cursor-pointer sortable" data-column="location">
Location <i class="fas fa-sort ml-1"></i>
</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider cursor-pointer sortable" data-column="price">
Avg. Rent <i class="fas fa-sort ml-1"></i>
</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Actions
</th>
</tr>
</thead>
<tbody id="resultsTable" class="bg-white divide-y divide-gray-200">
<!-- Results will be inserted here by JavaScript -->
<tr id="noResultsRow">
<td colspan="5" class="px-6 py-4 text-center text-gray-500">
No properties found. Start scraping to populate the database.
</td>
</tr>
</tbody>
</table>
</div>
<div id="pagination" class="flex items-center justify-between mt-4 hidden">
<div>
<p class="text-sm text-gray-700">
Showing <span id="startItem">1</span> to <span id="endItem">10</span> of <span id="totalItems">0</span> results
</p>
</div>
<div class="flex space-x-2">
<button id="prevPage" class="px-3 py-1 border border-gray-300 rounded-md text-sm font-medium text-gray-700 bg-white hover:bg-gray-50 disabled:opacity-50">
Previous
</button>
<button id="nextPage" class="px-3 py-1 border border-gray-300 rounded-md text-sm font-medium text-gray-700 bg-white hover:bg-gray-50 disabled:opacity-50">
Next
</button>
</div>
</div>
</div>
</div>
<!-- Property Details Modal -->
<div id="propertyModal" class="fixed inset-0 z-50 overflow-y-auto hidden">
<div class="flex items-center justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0">
<div class="fixed inset-0 transition-opacity" aria-hidden="true">
<div class="absolute inset-0 bg-gray-500 opacity-75"></div>
</div>
<span class="hidden sm:inline-block sm:align-middle sm:h-screen" aria-hidden="true">​</span>
<div class="inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-3xl sm:w-full">
<div class="bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4">
<div class="sm:flex sm:items-start">
<div class="mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left w-full">
<div class="flex justify-between items-start">
<h3 id="modalTitle" class="text-2xl leading-6 font-bold text-gray-900 mb-2">
Property Details
</h3>
<button id="closeModal" class="text-gray-400 hover:text-gray-500">
<i class="fas fa-times"></i>
</button>
</div>
<div class="mt-4 grid grid-cols-1 md:grid-cols-2 gap-6">
<div>
<h4 class="font-medium text-gray-900 mb-2 flex items-center">
<i class="fas fa-info-circle mr-2 text-indigo-500"></i> Basic Info
</h4>
<div class="space-y-2">
<p><span class="font-medium">Name:</span> <span id="modalName">-</span></p>
<p><span class="font-medium">Address:</span> <span id="modalAddress">-</span></p>
<p><span class="font-medium">Units:</span> <span id="modalUnits">-</span></p>
<p><span class="font-medium">Built:</span> <span id="modalYearBuilt">-</span></p>
<p><span class="font-medium">Type:</span> <span id="modalType">-</span></p>
</div>
</div>
<div>
<h4 class="font-medium text-gray-900 mb-2 flex items-center">
<i class="fas fa-dollar-sign mr-2 text-indigo-500"></i> Financials
</h4>
<div class="space-y-2">
<p><span class="font-medium">Avg. Rent:</span> <span id="modalAvgRent">-</span></p>
<p><span class="font-medium">Price Range:</span> <span id="modalPriceRange">-</span></p>
<p><span class="font-medium">Occupancy:</span> <span id="modalOccupancy">-</span></p>
</div>
</div>
<div>
<h4 class="font-medium text-gray-900 mb-2 flex items-center">
<i class="fas fa-map-marker-alt mr-2 text-indigo-500"></i> Location
</h4>
<div class="space-y-2">
<p><span class="font-medium">City:</span> <span id="modalCity">-</span></p>
<p><span class="font-medium">State:</span> <span id="modalState">-</span></p>
<p><span class="font-medium">ZIP:</span> <span id="modalZip">-</span></p>
<p><span class="font-medium">County:</span> <span id="modalCounty">-</span></p>
</div>
</div>
<div>
<h4 class="font-medium text-gray-900 mb-2 flex items-center">
<i class="fas fa-star mr-2 text-indigo-500"></i> Amenities
</h4>
<div id="modalAmenities" class="flex flex-wrap gap-2">
<!-- Amenities will be added here -->
</div>
</div>
</div>
<div class="mt-6">
<h4 class="font-medium text-gray-900 mb-2 flex items-center">
<i class="fas fa-link mr-2 text-indigo-500"></i> Links
</h4>
<div class="flex space-x-4">
<a id="modalSourceLink" href="#" target="_blank" class="text-indigo-600 hover:text-indigo-800 flex items-center">
<i class="fas fa-external-link-alt mr-1"></i> Source
</a>
<a id="modalMapLink" href="#" target="_blank" class="text-indigo-600 hover:text-indigo-800 flex items-center">
<i class="fas fa-map-marked-alt mr-1"></i> View on Map
</a>
</div>
</div>
</div>
</div>
</div>
<div class="bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse">
<button type="button" id="saveChangesBtn" class="w-full inline-flex justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-indigo-600 text-base font-medium text-white hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 sm:ml-3 sm:w-auto sm:text-sm">
Save Changes
</button>
<button type="button" id="cancelModalBtn" class="mt-3 w-full inline-flex justify-center rounded-md border border-gray-300 shadow-sm px-4 py-2 bg-white text-base font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 sm:mt-0 sm:ml-3 sm:w-auto sm:text-sm">
Cancel
</button>
</div>
</div>
</div>
</div>
<!-- Confirmation Modal -->
<div id="confirmModal" class="fixed inset-0 z-50 overflow-y-auto hidden">
<div class="flex items-center justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0">
<div class="fixed inset-0 transition-opacity" aria-hidden="true">
<div class="absolute inset-0 bg-gray-500 opacity-75"></div>
</div>
<span class="hidden sm:inline-block sm:align-middle sm:h-screen" aria-hidden="true">​</span>
<div class="inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full">
<div class="bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4">
<div class="sm:flex sm:items-start">
<div class="mx-auto flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-full bg-red-100 sm:mx-0 sm:h-10 sm:w-10">
<i class="fas fa-exclamation-triangle text-red-600"></i>
</div>
<div class="mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left">
<h3 class="text-lg leading-6 font-medium text-gray-900" id="confirmModalTitle">
Confirm Action
</h3>
<div class="mt-2">
<p class="text-sm text-gray-500" id="confirmModalMessage">
Are you sure you want to perform this action?
</p>
</div>
</div>
</div>
</div>
<div class="bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse">
<button type="button" id="confirmActionBtn" class="w-full inline-flex justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-red-600 text-base font-medium text-white hover:bg-red-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-red-500 sm:ml-3 sm:w-auto sm:text-sm">
Confirm
</button>
<button type="button" id="cancelConfirmBtn" class="mt-3 w-full inline-flex justify-center rounded-md border border-gray-300 shadow-sm px-4 py-2 bg-white text-base font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 sm:mt-0 sm:ml-3 sm:w-auto sm:text-sm">
Cancel
</button>
</div>
</div>
</div>
</div>
</div>
<script>
// Sample database (in a real app, this would be server-side)
let apartmentDatabase = [];
let currentPage = 1;
const itemsPerPage = 10;
let currentSortColumn = 'name';
let currentSortDirection = 'asc';
// DOM Elements
const scrapeBtn = document.getElementById('scrapeBtn');
const targetSite = document.getElementById('targetSite');
const customUrlContainer = document.getElementById('customUrlContainer');
const customUrl = document.getElementById('customUrl');
const scrapingProgress = document.getElementById('scrapingProgress');
const progressBar = document.getElementById('progressBar');
const progressPercent = document.getElementById('progressPercent');
const scrapingStatus = document.getElementById('scrapingStatus');
const resultsTable = document.getElementById('resultsTable');
const noResultsRow = document.getElementById('noResultsRow');
const pagination = document.getElementById('pagination');
const prevPage = document.getElementById('prevPage');
const nextPage = document.getElementById('nextPage');
const startItem = document.getElementById('startItem');
const endItem = document.getElementById('endItem');
const totalItems = document.getElementById('totalItems');
const searchInput = document.getElementById('searchInput');
const propertyModal = document.getElementById('propertyModal');
const closeModal = document.getElementById('closeModal');
const cancelModalBtn = document.getElementById('cancelModalBtn');
const saveChangesBtn = document.getElementById('saveChangesBtn');
const confirmModal = document.getElementById('confirmModal');
const confirmActionBtn = document.getElementById('confirmActionBtn');
const cancelConfirmBtn = document.getElementById('cancelConfirmBtn');
const exportBtn = document.getElementById('exportBtn');
const clearBtn = document.getElementById('clearBtn');
// Event Listeners
targetSite.addEventListener('change', function() {
if (this.value === 'custom') {
customUrlContainer.classList.remove('hidden');
} else {
customUrlContainer.classList.add('hidden');
}
});
scrapeBtn.addEventListener('click', startScraping);
prevPage.addEventListener('click', () => {
if (currentPage > 1) {
currentPage--;
displayResults();
}
});
nextPage.addEventListener('click', () => {
const totalPages = Math.ceil(apartmentDatabase.length / itemsPerPage);
if (currentPage < totalPages) {
currentPage++;
displayResults();
}
});
searchInput.addEventListener('input', () => {
currentPage = 1;
displayResults();
});
document.querySelectorAll('.sortable').forEach(header => {
header.addEventListener('click', function() {
const column = this.getAttribute('data-column');
if (currentSortColumn === column) {
currentSortDirection = currentSortDirection === 'asc' ? 'desc' : 'asc';
} else {
currentSortColumn = column;
currentSortDirection = 'asc';
}
sortDatabase();
displayResults();
// Update sort icons
document.querySelectorAll('.sortable i').forEach(icon => {
icon.className = 'fas fa-sort ml-1';
});
const icon = this.querySelector('i');
icon.className = currentSortDirection === 'asc'
? 'fas fa-sort-up ml-1'
: 'fas fa-sort-down ml-1';
});
});
closeModal.addEventListener('click', hideModal);
cancelModalBtn.addEventListener('click', hideModal);
saveChangesBtn.addEventListener('click', savePropertyChanges);
cancelConfirmBtn.addEventListener('click', hideConfirmModal);
exportBtn.addEventListener('click', exportData);
clearBtn.addEventListener('click', confirmClearDatabase);
// Functions
async function startScraping() {
const [city, state] = document.getElementById('location').value.split(',').map(v => v.trim());
const minUnits = document.getElementById('minUnits').value || 5;
const maxUnits = document.getElementById('maxUnits').value || 100;
const maxPages = parseInt(document.getElementById('maxPages').value) || 5;
if (!city || !state) {
alert('Please enter a location in "City, State" format');
return;
}
scrapeBtn.disabled = true;
document.getElementById('scrapeBtnText').classList.add('hidden');
document.getElementById('scrapeBtnSpinner').classList.remove('hidden');
scrapingProgress.classList.remove('hidden');
apartmentDatabase = [];
displayResults();
try {
for (let page = 1; page <= maxPages; page++) {
scrapingStatus.textContent = `Loading page ${page}/${maxPages}...`;
const resp = await fetch(`/api/scrape?city=${encodeURIComponent(city)}&state=${encodeURIComponent(state)}&type=multifamily&page=${page}&limit=20`);
if (!resp.ok) throw new Error('Network response was not ok');
const data = await resp.json();
// Process API response
if (data.homes && data.homes.length > 0) {
data.homes.forEach(item => {
// Only include properties within the unit range
if (item.units >= minUnits && item.units <= maxUnits) {
apartmentDatabase.push({
id: item.id,
name: item.property_name || 'Unnamed Property',
address: item.address?.full || 'Address not available',
city: item.address?.city || city,
state: item.address?.state || state,
zip: item.address?.zip || '',
units: item.units,
yearBuilt: item.year_built,
type: item.property_type || 'Multifamily',
avgRent: item.rent_average,
minRent: item.rent_min,
maxRent: item.rent_max,
occupancy: item.occupancy_rate,
amenities: item.amenities || [],
source: item.url || '#',
lastUpdated: item.last_updated || new Date().toISOString()
});
}
});
}
// Update progress
const progress = Math.round((page / maxPages) * 100);
progressBar.style.width = `${progress}%`;
progressPercent.textContent = `${progress}%`;
// Small delay to avoid rate limiting
await new Promise(r => setTimeout(r, 500));
}
scrapingStatus.textContent = `Completed. Found ${apartmentDatabase.length} listings.`;
if (apartmentDatabase.length === 0) {
scrapingStatus.textContent += ' (No properties matched your unit range filters)';
}
} catch (error) {
console.error('Scraping error:', error);
scrapingStatus.textContent = `Error: ${error.message}`;
progressBar.style.width = '0%';
progressPercent.textContent = '0%';
} finally {
scrapeBtn.disabled = false;
document.getElementById('scrapeBtnText').classList.remove('hidden');
document.getElementById('scrapeBtnSpinner').classList.add('hidden');
}
}
function displayResults() {
const searchTerm = searchInput.value.toLowerCase();
let filteredData = apartmentDatabase;
if (searchTerm) {
filteredData = apartmentDatabase.filter(property =>
property.name.toLowerCase().includes(searchTerm) ||
property.address.toLowerCase().includes(searchTerm) ||
property.city.toLowerCase().includes(searchTerm)
);
}
totalItems.textContent = filteredData.length;
if (filteredData.length === 0) {
noResultsRow.classList.remove('hidden');
pagination.classList.add('hidden');
return;
}
noResultsRow.classList.add('hidden');
pagination.classList.remove('hidden');
const startIndex = (currentPage - 1) * itemsPerPage;
const endIndex = Math.min(startIndex + itemsPerPage, filteredData.length);
const paginatedData = filteredData.slice(startIndex, endIndex);
startItem.textContent = startIndex + 1;
endItem.textContent = endIndex;
prevPage.disabled = currentPage === 1;
nextPage.disabled = endIndex >= filteredData.length;
// Clear existing rows
while (resultsTable.children.length > 1) {
resultsTable.removeChild(resultsTable.lastChild);
}
// Add new rows
paginatedData.forEach(property => {
const row = document.createElement('tr');
row.className = 'hover:bg-gray-50 transition-all';
row.innerHTML = `
<td class="px-6 py-4 whitespace-nowrap">
<div class="flex items-center">
<div class="flex-shrink-0 h-10 w-10 bg-indigo-100 rounded-full flex items-center justify-center">
<i class="fas fa-building text-indigo-600"></i>
</div>
<div class="ml-4">
<div class="text-sm font-medium text-gray-900">${property.name}</div>
<div class="text-sm text-gray-500">${property.city}, ${property.state}</div>
</div>
</div>
</td>
<td class="px-6 py-4 whitespace-nowrap">
<div class="text-sm text-gray-900">${property.units}</div>
</td>
<td class="px-6 py-4 whitespace-nowrap">
<div class="text-sm text-gray-900">${property.address}</div>
</td>
<td class="px-6 py-4 whitespace-nowrap">
<div class="text-sm text-gray-900">$${property.avgRent}</div>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
<button class="text-indigo-600 hover:text-indigo-900 mr-3 view-btn" data-id="${property.id}">
<i class="fas fa-eye mr-1"></i> View
</button>
<button class="text-red-600 hover:text-red-900 delete-btn" data-id="${property.id}">
<i class="fas fa-trash-alt mr-1"></i> Delete
</button>
</td>
`;
resultsTable.appendChild(row);
});
// Add event listeners to new buttons
document.querySelectorAll('.view-btn').forEach(btn => {
btn.addEventListener('click', function() {
const id = parseInt(this.getAttribute('data-id'));
showPropertyDetails(id);
});
});
document.querySelectorAll('.delete-btn').forEach(btn => {
btn.addEventListener('click', function() {
const id = parseInt(this.getAttribute('data-id'));
confirmDeleteProperty(id);
});
});
}
function sortDatabase() {
apartmentDatabase.sort((a, b) => {
let valueA = a[currentSortColumn];
let valueB = b[currentSortColumn];
// Handle different data types
if (typeof valueA === 'string') valueA = valueA.toLowerCase();
if (typeof valueB === 'string') valueB = valueB.toLowerCase();
if (valueA < valueB) {
return currentSortDirection === 'asc' ? -1 : 1;
}
if (valueA > valueB) {
return currentSortDirection === 'asc' ? 1 : -1;
}
return 0;
});
}
function showPropertyDetails(id) {
const property = apartmentDatabase.find(p => p.id === id);
if (!property) return;
// Set modal content
document.getElementById('modalName').textContent = property.name;
document.getElementById('modalAddress').textContent = property.address;
document.getElementById('modalUnits').textContent = property.units;
document.getElementById('modalYearBuilt').textContent = property.yearBuilt || 'Unknown';
document.getElementById('modalType').textContent = property.type || 'Unknown';
document.getElementById('modalAvgRent').textContent = `$${property.avgRent}`;
document.getElementById('modalPriceRange').textContent = `$${property.minRent || 'N/A'} - $${property.maxRent || 'N/A'}`;
document.getElementById('modalOccupancy').textContent = `${property.occupancy || 'Unknown'}%`;
document.getElementById('modalCity').textContent = property.city;
document.getElementById('modalState').textContent = property.state;
document.getElementById('modalZip').textContent = property.zip;
document.getElementById('modalCounty').textContent = property.county || 'Unknown';
// Set amenities
const amenitiesContainer = document.getElementById('modalAmenities');
amenitiesContainer.innerHTML = '';
if (property.amenities && property.amenities.length > 0) {
property.amenities.forEach(amenity => {
const badge = document.createElement('span');
badge.className = 'bg-green-100 text-green-800 text-xs font-medium px-2.5 py-0.5 rounded';
badge.textContent = amenity;
amenitiesContainer.appendChild(badge);
});
} else {
amenitiesContainer.textContent = 'None listed';
}
// Set links
document.getElementById('modalSourceLink').href = property.source;
document.getElementById('modalMapLink').href = `https://www.google.com/maps?q=${encodeURIComponent(property.address)}`;
// Store current property ID
propertyModal.setAttribute('data-current-id', id);
// Show modal
propertyModal.classList.remove('hidden');
}
function hideModal() {
propertyModal.classList.add('hidden');
}
function savePropertyChanges() {
const id = parseInt(propertyModal.getAttribute('data-current-id'));
const propertyIndex = apartmentDatabase.findIndex(p => p.id === id);
if (propertyIndex !== -1) {
// In a real app, you would update the property with form values
// For now, we'll just update the lastUpdated field
apartmentDatabase[propertyIndex].lastUpdated = new Date().toISOString();
// Show success message
alert('Property updated successfully!');
hideModal();
displayResults();
}
}
function confirmDeleteProperty(id) {
const property = apartmentDatabase.find(p => p.id === id);
if (!property) return;
document.getElementById('confirmModalTitle').textContent = 'Delete Property';
document.getElementById('confirmModalMessage').textContent = `Are you sure you want to delete "${property.name}"? This action cannot be undone.`;
confirmActionBtn.onclick = function() {
deleteProperty(id);
hideConfirmModal();
};
confirmModal.classList.remove('hidden');
}
function deleteProperty(id) {
apartmentDatabase = apartmentDatabase.filter(p => p.id !== id);
displayResults();
}
function hideConfirmModal() {
confirmModal.classList.add('hidden');
}
function exportData() {
try {
if (apartmentDatabase.length === 0) {
throw new Error('No data to export');
}
// Convert to CSV
const headers = Object.keys(apartmentDatabase[0]);
let csv = headers.join(',') + '\n';
apartmentDatabase.forEach(property => {
const row = headers.map(header => {
let value = property[header];
if (Array.isArray(value)) {
value = value.join('; ');
}
if (value === null || value === undefined) {
value = '';
}
return `"${value.toString().replace(/"/g, '""')}"`;
}).join(',');
csv += row + '\n';
});
// Create download link
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = `multifamily-properties-${new Date().toISOString().slice(0, 10)}.csv`;
document.body.appendChild(link);
link.click();
// Clean up
setTimeout(() => {
document.body.removeChild(link);
URL.revokeObjectURL(url);
}, 100);
} catch (error) {
alert(`Export failed: ${error.message}`);
}
}
function confirmClearDatabase() {
if (apartmentDatabase.length === 0) {
alert('Database is already empty');
return;
}
document.getElementById('confirmModalTitle').textContent = 'Clear Database';
document.getElementById('confirmModalMessage').textContent = 'Are you sure you want to clear the entire database? This action cannot be undone.';
confirmActionBtn.onclick = function() {
clearDatabase();
hideConfirmModal();
};
confirmModal.classList.remove('hidden');
}
function clearDatabase() {
apartmentDatabase = [];
currentPage = 1;
displayResults();
}
// Initialize
displayResults();
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Kkeane/scraper" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html> |