Last active
May 27, 2021 13:01
-
-
Save aarmora/12bc47542abf2756cfd5f44c4eda6a8d to your computer and use it in GitHub Desktop.
Get tax auction properties from King county WA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Run this function at the following url: | |
// https://kingcounty.gov/depts/finance-business-operations/treasury/foreclosure/current-foreclosure-action/foreclosure-properties.aspx | |
async function getAllProperties(copy) { | |
const data = await fetch("https://data.kingcounty.gov/api/views/nx4x-daw6/rows.json", { | |
"headers": { | |
"accept": "application/json, text/javascript, */*; q=0.01", | |
"sec-ch-ua": "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"90\", \"Google Chrome\";v=\"90\"", | |
"sec-ch-ua-mobile": "?0" | |
}, | |
"referrer": "https://kingcounty.gov/", | |
"referrerPolicy": "strict-origin-when-cross-origin", | |
"body": null, | |
"method": "GET", | |
"mode": "cors", | |
"credentials": "omit" | |
}); | |
const body = await data.json(); | |
const properties = body.data.map(property => property[8]); | |
copy(properties); | |
} | |
// Pass in dev tools copy function | |
await getAllProperties(copy); | |
// Quotas exceeded | |
// https://i.imgur.com/LkU2Tuk.png | |
// Paste these into the following url: | |
// https://payment.kingcounty.gov/Home/Index?app=PropertyTaxes&Search=0012600030 | |
async function getAllTaxes(startingIndex) { | |
const formattedProperties = []; | |
const end = startingIndex + 75; | |
console.log('properties', properties.length); | |
for (let i = startingIndex; i < end; i++) { | |
const property = properties[i]; | |
const taxData = await getTaxes(property); | |
console.log('tax data', taxData.data[0].taxYears[0]); | |
for (let taxYearIndex = 0; taxYearIndex < taxData.data[0].taxYears.length; taxYearIndex++) { | |
const taxYear = taxData.data[0].taxYears[taxYearIndex]; | |
formattedProperties.push({ | |
name: taxData.data[0].accountName.trim(), | |
address1: taxData.data[0].address1.trim(), | |
address2: taxData.data[0].address2.trim(), | |
address3: taxData.data[0].address3.trim(), | |
taxYear: taxYear.year, | |
amountDue: taxYear.amountDue, | |
apn: property, | |
assessorUrl: `https://blue.kingcounty.com/Assessor/eRealProperty/Dashboard.aspx?ParcelNbr=${property}` | |
}); | |
} | |
// Pause for a second between each request | |
await timeout(1000); | |
} | |
return formattedProperties; | |
} | |
// Get tax data for an individual property | |
async function getTaxes(apn) { | |
const data = await fetch("https://payment.kingcounty.gov/Home/TenantCall?app=PropertyTaxes", { | |
"headers": { | |
"accept": "application/json, text/plain, */*", | |
"accept-language": "en-US,en;q=0.9,pt-BR;q=0.8,pt;q=0.7", | |
"content-type": "application/json", | |
"sec-ch-ua": "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"90\", \"Google Chrome\";v=\"90\"", | |
"sec-ch-ua-mobile": "?0", | |
"sec-fetch-dest": "empty", | |
"sec-fetch-mode": "cors", | |
"sec-fetch-site": "same-origin" | |
}, | |
"referrer": "https://payment.kingcounty.gov/Home/Index?app=PropertyTaxes&Search=0012600030", | |
"referrerPolicy": "no-referrer-when-downgrade", | |
"body": `{\"path\":\"RealProperty/${apn}\",\"captchatoken\":\"\"}`, | |
"method": "POST", | |
"mode": "cors", | |
"credentials": "include" | |
}); | |
const body = await data.json(); | |
const json = JSON.parse(body); | |
return json; | |
} | |
function timeout(ms) { | |
return new Promise(res => setTimeout(res, ms)); | |
} | |
copy(await getAllTaxes(0)); | |
// Paste into json to csv converter | |
// https://json-csv.com/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment