-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
executable file
·83 lines (56 loc) · 2.35 KB
/
index.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
#!/usr/bin/node
const { Command } = require('commander');
const { getAllLocations, getLocations, panic, getDataFromBooli, calculateAggregates } = require('./lib');
const debug = require('debug')('command')
const program = new Command();
program.version('0.0.1');
program
.description("This command lets you check price of proprties")
.option('-A, --list_locations', 'list supported locations')
.option('-l, --location <location_id...>', 'Show statistics for <location_id>. Multiple')
.option("-a, --all_locations", "all supported locations. (Takes a while)")
.option("-p, --pages <number>", "Number of pages to check (more means better precision but slower)")
.option("--per_month", "Break down statistics per month")
.option("-F, --flats", "Pick flats (default flats + houses)")
.option("-H, --houses", "Pick houses (default flats + houses)")
// .option("-f, --area_from <xx m^2>", "Area from")
// .option("-t, --area_to <xx m^2>", "Area to");
program.parse(process.argv);
const main = async () => {
const options = program.opts();
if (!options.flats && !options.houses) {
options.flats = true;
options.houses = true;
}
if (options.list_locations && !options.location) {
options.all_locations = true;
}
debug("finished procesing params", options);
const locations = options.all_locations ? getAllLocations() : getLocations(options.location);
debug("Locations to be cheked ", locations)
if ((!locations) || (!options.all_locations) && locations.length !== options.location.length) {
panic("Failed to fetch locations")
}
if (options.list_locations) {
printLocations(locations);
process.exit();
}
const locationsWithData = await getDataFromBooli(locations, options);
const locationsaWithAggregates = locationsWithData.map(location => ({
...location,
aggregates: calculateAggregates(location.data, options.per_month)
}))
printResults(locationsaWithAggregates);
}
const printLocations = (locations) => {
console.log(JSON.stringify(locations));
}
const printResults = (locationsaWithAggregates) => {
const printOnlyData = locationsaWithAggregates.map(location => ({
id: location.id,
name: location.name,
...location.aggregates
}));
console.log(JSON.stringify(printOnlyData));
}
main();