-
Notifications
You must be signed in to change notification settings - Fork 0
/
crawlAllVehiclesToMongo.js
65 lines (59 loc) · 1.71 KB
/
crawlAllVehiclesToMongo.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
61
62
63
64
65
const axios = require('axios');
// Search For
radius = 350
zip = 48331
yearStart = 2019
yearEnd = 2020
minPrice = 75000
maxPrice = 100000
// Export this stuff
exportFromVehicle =
['name',
'vin',
'totalMsrp',
'dealer.businessName',
'dealer.phone',
'dealer.url',
'dealer.city',
'dealer.state',
'dealer.zipCode',]
const url = 'https://www.bmwusa.com/api/inventory/filter/search/'
vehicles = ''
axios.post(url + zip + '?page=1&resultsPerPage=5000&sortBy=PRICE&sortOrder=ASC',
{
//selectedSeries: ["M"],
//selectedModels: ["M5"],
selectedSeries: ["5"],
selectedModels: ["M550i"],
selectedMinPrice: minPrice,
selectedMaxPrice: maxPrice,
selectedLocatorRange: radius,
selectedMinModelYear: yearStart,
selectedMaxModelYear: yearEnd,
selectedModelYears: [yearStart]
})
.then((response) => {
vehicles = response.data;
pipedHeaders = ''
exportFromVehicle.forEach(element => pipedHeaders += element + '|')
console.log(pipedHeaders)
for (let step = 0; step < vehicles.totalVehicleCount; step++) {
x = vehicles.vehicles[step];
u = exportFromVehicle.map(exportFunk)
function exportFunk(value, index, array) {
return pathIndex(x, value)
}
function multiIndex(obj,is) {
return is.length ? multiIndex(obj[is[0]],is.slice(1)) : obj
}
function pathIndex(obj,is) {
return multiIndex(obj,is.split('.'))
}
pipedResults = ''
u.forEach(element => pipedResults += element + '|')
console.log(pipedResults)
}
console.log('Total number of vehicles|' + vehicles.totalVehicleCount);
}, (error) => {
console.log(error);
});