-
Notifications
You must be signed in to change notification settings - Fork 0
/
subaru.js
60 lines (51 loc) · 2.01 KB
/
subaru.js
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
const fs = require('fs');
const moment = require('moment');
const { fetchFromDealer } = require('./dealer-common.js');
async function getCarsFromDealers() {
const dealers = [
'https://www.fairfieldsubaru.com/',
'https://www.diablosubaru.com/',
'https://www.hanleesnapasubaru.com/',
'https://www.hanselsubaru.com/',
'https://www.maitasubaru.com/',
'https://www.livermoresubaru.com/',
'https://www.premiersubaruoffremont.com/',
'https://www.putnamsubaruofburlingame.com/',
'https://www.serramontesubaru.com/',
'https://www.carlsensubaru.com/',
'https://www.subaruofoakland.com/',
'https://www.albanysubaru.com/',
'https://www.marinsubaru.net/',
'https://www.stevenscreeksubaru.com/',
'https://www.capitolsubarusj.com/',
'https://www.santacruzsubaru.com/',
'https://www.modestosubaru.com/',
'https://www.subaruofsonora.com/'
// 'https://www.gillmansubaru.com/',
// 'https://www.westhoustonsubaru.com/',
// 'https://www.gillmansubarunorth.com/',
// 'https://www.superiorsubaruofhouston.com/'
]
const carsByDealer = await Promise.all(dealers.map(dealer => fetchFromDealer(dealer, 'subaru')));
const allCars = [];
carsByDealer.map(cars => allCars.push(...cars));
// allCars.sort(function (a, b) {
// if (a.finalPrice < b.finalPrice) return -1;
// if (a.finalPrice > b.finalPrice) return 1;
// return 0;
// });
allCars.sort(function (a, b) {
if (a.color < b.color) return -1;
if (a.color > b.color) return 1;
return 0;
});
const archive = `archive/subaru_${moment().format('YYYY-MM-DD_HH-mm-ss')}.json`;
fs.writeFileSync(archive, JSON.stringify(allCars, null, 2), err => {
console.error(err);
});
fs.writeFileSync('subaru.json', JSON.stringify(allCars, null, 2), err => {
console.error(err);
});
return allCars;
}
module.exports = {getCarsFromDealers};