-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspritmonitor_cmd.js
116 lines (103 loc) · 3.41 KB
/
spritmonitor_cmd.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
var sm = require('./spritmonitor.js')
function errorHandler(_err)
{
console.log("ERROR: " + JSON.stringify(_err));
process.exit(1);
}
function exitUsage()
{
console.log('Usage:');
console.log('node spritmonitor_cmd.js username password addFueling|listCars|listFuelings');
console.log(' addFueling required options:');
console.log(' quantity=56.78');
console.log(' price=67.89');
console.log(' fuelsort=Diesel|Super gasoline|Electricity|... (see fueltypes.json)');
console.log(' Either:');
console.log(' odometer=67890 for total mileage/kilometers of the car');
console.log(' Or:');
console.log(' trip=678 for distance of trip since last refueling');
console.log(' addFueling additional options (all optional):');
console.log(' quantityunit=l|US.gal|kg|kWh|... (see quantityunits.json)');
console.log(' currency=EUR|USD|... (see currencies.json)');
console.log(' "note=Your custom message"');
console.log(' streets=autobahn,city,land (any combination of these, separated by comma)');
console.log(' attributes=summertires,normal (any of summertires|wintertires,normal|slow|fast,ac,trailer,heating)');
console.log(' bc_consumption=7.65 (consumption as indicated by the board computer)');
console.log(' bc_quantity=47.65 (quantity as indicated by the board computer)');
console.log(' bc_speed=76 (average trip speed as indicated by the board computer)');
console.log(' stationname=Aral|Shell|... (see fuelingcompanies.json)');
console.log(' position=55.555,7.7777 (position as latitude,longitude)');
console.log(' country=D (two letters country code)');
console.log(' location=Hamburg (location name, for example city name)');
console.log(' tank=1|2 (fuel tank id, regular cars only have 1, hybrid cars 1=gasoline, 2=electricity)');
console.log(' date=03/21/2019|21.03.2019 (any date that can be parsed, note that hour/min/sec is not supported');
console.log(' by the API and will be ignored)');
console.log(' listCars: no options required, returns json of all cars available');
console.log(' listFuelings: carId [limit=number] returns last limit fuelings as json');
}
var cmd = process.argv[4];
if(cmd == 'addFueling')
{
var params = {}
var car = process.argv[5];
for(var i=6; i<process.argv.length; ++i)
{
var args = process.argv[i].split('=');
if(args.length != 2)
{
console.log('Invalid argument ' + process.argv[i] + ', needs to be key=value');
continue;
}
var key = args[0];
var val = args[1];
if(key == 'position')
{
var latlon = val.split(',');
params.position = {
lat: latlon[0],
lon: latlon[1]
};
}
else if(key == 'date')
params.date = new Date(Date.parse(val));
else
params[key] = val;
}
if(!params.date)
params.date = new Date();
console.log(JSON.stringify(params, null, 4));
sm.addFueling(car, params, (_success) =>
{
console.log("Success: " + _success);
process.exit(0);
}, errorHandler);
}
else if(cmd == 'listCars')
{
sm.getCars((_cars) =>
{
console.log(JSON.stringify(_cars, null, 4));
}, errorHandler);
}
else if(cmd == 'listFuelings')
{
if(process.argv.length < 6)
{
exitUsage();
}
else
{
var carId = process.argv[5];
var limit = 5;
if(process.argv.length > 6)
limit = process.argv[6];
sm.getFuelings(carId, limit, (_fuelings) =>
{
console.log(JSON.stringify(_fuelings, null, 4));
}, errorHandler);
}
}
else
{
exitUsage();
}