add support for motorcycles to the kbb.js script
This commit is contained in:
@@ -12,7 +12,7 @@ This is a collection of useful scripts to help you manage your Actual Budget.
|
|||||||
- [Loan Interest Calculator](#loan-interest-calculator)
|
- [Loan Interest Calculator](#loan-interest-calculator)
|
||||||
- [Tracking Home Prices (RentCast's Value Estimate)](#tracking-home-prices-rentcasts-value-estimate)
|
- [Tracking Home Prices (RentCast's Value Estimate)](#tracking-home-prices-rentcasts-value-estimate)
|
||||||
- [Tracking Home Prices (Zillow's Zestimate)](#tracking-home-prices-zillows-zestimate)
|
- [Tracking Home Prices (Zillow's Zestimate)](#tracking-home-prices-zillows-zestimate)
|
||||||
- [Tracking Car Prices (Kelley Blue Book)](#tracking-car-prices-kelley-blue-book)
|
- [Tracking Vehicle Prices (Kelley Blue Book)](#tracking-vehicle-prices-kelley-blue-book)
|
||||||
- [Tracking Investment Accounts](#tracking-investment-accounts)
|
- [Tracking Investment Accounts](#tracking-investment-accounts)
|
||||||
- [Tracking Bitcoin Price](#tracking-bitcoin-price)
|
- [Tracking Bitcoin Price](#tracking-bitcoin-price)
|
||||||
|
|
||||||
@@ -255,12 +255,12 @@ node zestimate.js
|
|||||||
|
|
||||||
It is recommended to run this script once per month.
|
It is recommended to run this script once per month.
|
||||||
|
|
||||||
### Tracking Car Prices (Kelley Blue Book)
|
### Tracking Vehicle Prices (Kelley Blue Book)
|
||||||
|
|
||||||
**Note: this script requires having a starting balance in the account**
|
**Note: this script requires having a starting balance in the account**
|
||||||
|
|
||||||
This script tracks the Kelley Blue Book value for a car. It adds new
|
This script tracks the Kelley Blue Book value for a car or motorcycle. It adds
|
||||||
transactions to keep the account balance equal to the latest KBB value.
|
new transactions to keep the account balance equal to the latest KBB value.
|
||||||
|
|
||||||
To use this script, first you need to use the KBB website to find the value of
|
To use this script, first you need to use the KBB website to find the value of
|
||||||
your car. Be sure to select "Private Party" for the value. It should show
|
your car. Be sure to select "Private Party" for the value. It should show
|
||||||
@@ -285,6 +285,15 @@ on the values in the URL.
|
|||||||
- `kbbVehicleid:XXXXXX`
|
- `kbbVehicleid:XXXXXX`
|
||||||
- `kbbOptions:XXX,XXX,XXX,...`
|
- `kbbOptions:XXX,XXX,XXX,...`
|
||||||
|
|
||||||
|
If you are tracking a motorcycle, use these settings:
|
||||||
|
|
||||||
|
```
|
||||||
|
kbbURL:https://www.kbb.com/motorcycles/suzuki/dr650s/2018/?
|
||||||
|
kbbPriceType:tradein (or retail)
|
||||||
|
```
|
||||||
|
|
||||||
|
Be sure to find the correct URL for your specific motorcycle and year.
|
||||||
|
|
||||||
You can optionally change the payee used for the transactions by setting
|
You can optionally change the payee used for the transactions by setting
|
||||||
`KBB_PAYEE_NAME` in the `.env` file.
|
`KBB_PAYEE_NAME` in the `.env` file.
|
||||||
|
|
||||||
|
|||||||
@@ -18,8 +18,15 @@ async function getKBB(URL) {
|
|||||||
const html = await response.text();
|
const html = await response.text();
|
||||||
const dom = new jsdom.JSDOM(html);
|
const dom = new jsdom.JSDOM(html);
|
||||||
|
|
||||||
const kbbText = dom.window.document.getElementById('PriceAdvisor').getElementsByTagName('text')[3].textContent;
|
const advisor = dom.window.document.getElementById('PriceAdvisor');
|
||||||
return parseInt(kbbText.replace('$', '').replaceAll(',', '')) * 100;
|
if (advisor) {
|
||||||
|
const kbbText = advisor.getElementsByTagName('text')[3].textContent;
|
||||||
|
return parseInt(kbbText.replace('$', '').replaceAll(',', '')) * 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
const regex = /"value":\s*(\d+)/;
|
||||||
|
const match = html.match(regex);
|
||||||
|
return parseInt(match[1]) * 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
(async function() {
|
(async function() {
|
||||||
@@ -49,6 +56,9 @@ async function getKBB(URL) {
|
|||||||
const options = getTagValue(note, 'kbbOptions');
|
const options = getTagValue(note, 'kbbOptions');
|
||||||
if (options) URL += `&optionids=${options}`;
|
if (options) URL += `&optionids=${options}`;
|
||||||
|
|
||||||
|
const pricetype = getTagValue(note, 'kbbPriceType');
|
||||||
|
if (pricetype) URL += `&pricetype=${pricetype}`;
|
||||||
|
|
||||||
console.log('Fetching KBB for account:', account.name);
|
console.log('Fetching KBB for account:', account.name);
|
||||||
|
|
||||||
const kbb = await getKBB(URL);
|
const kbb = await getKBB(URL);
|
||||||
|
|||||||
Reference in New Issue
Block a user