-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
92 lines (76 loc) · 2.54 KB
/
main.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const subaru = require('./subaru.js');
const jeep = require('./jeep.js');
const jeepMfg = require('./jeep-mfg.js');
const fs = require('fs');
const moment = require('moment');
function makeDealerTable(allCars) {
let html = `
<table cellpadding="5px" border="1px">
<tr>
<th>Photo</th>
<th>MSRP</th>
<th>Final price</th>
<th>Location</th>
</tr>`;
for (const car of allCars) {
const googleMapsLink = `https://www.google.com/maps/place/${car.dealerAddress.replace(/\s/g, '+')}`;
html += `<tr>
<td><img src="${car.imgUrl}" height="120px"></td>
<td>${car.msrp}</td>
<td><a href="${car.url}" target="_blank">${car.finalPrice}</a></td>
<td><a href="${googleMapsLink}" target="_blank">${car.dealerName} - ${car.dealerCityState}</a><br />
<a href="${car.windowSticker}" target="_blank">${car.vin}</a><br />
${car.stockNo}<br />
${car.color}
</td>
</tr>`
}
html += `</table>`;
return html;
}
async function makeJeepMfgTable() {
const allCars = await jeep.run();
let html = `
<table cellpadding="5px" border="1px">
<tr>
<th>Photo</th>
<th>MSRP</th>
<th>Final price</th>
<th>Location</th>
</tr>`;
for (const car of allCars) {
const googleMapsLink = `https://www.google.com/maps/place/${car.dealer.address.replace(/\s/g, '+')}`;
html += `<tr>
<td>
<a href="${car.exteriorImageUrl}" target="_blank"><img src="${car.exteriorImageUrl}" height="120px">
<a href="${car.interiorImageUrl}" target="_blank"><img src="${car.interiorImageUrl}" height="120px">
</td>
<td>${car.msrp}</td>
<td><a href="${car.url}" target="_blank">${car.finalPrice}</a></td>
<td><a href="${googleMapsLink}" target="_blank">${car.dealer.name} - ${car.dealer.cityState}</a><br />
<a href="${car.windowSticker}" target="_blank">${car.vin}</a></td>
</tr>`
}
html += `</table>`;
return html;
}
async function makePage() {
let html = `
<body>
<p>Updated ${moment().format('YYYY-MM-DD HH:mm:ss')}</p>`
// html += `<table><tr><td valign="top">`;
let cars;
cars = await subaru.getCarsFromDealers();
html += makeDealerTable(cars);
// html += `</td>
// <td valign="top">`;
// cars = await jeepMfg.getCarsFromDealers();
// html += makeDealerTable(cars);
// html += `
// </td></tr></table>`;
html += `</body>`;
fs.writeFileSync('index.html', html, err => {
console.error(err);
});
}
makePage();