Download index.html from Kkeane/scraper: direct link, hf CLI and curl.
- Browser
- Download file 43.1 kB
-
https://huggingface.co/spaces/Kkeane/scraper/resolve/main/index.html
- Command line
-
hf download hf://spaces/Kkeane/scraper/index.html
-
curl -L -o index.html https://huggingface.co/spaces/Kkeane/scraper/resolve/main/index.html
43.1 kB
| <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> |