/
cli.js
46 lines (42 loc) · 1.7 KB
/
cli.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
/*
Sample usage of SolixE1600 class
will write schedule.json and homepage.json to the current directory
or pushes schedule to device if json file is specified as first parameter
*/
const fs = require("fs");
const SolixE1600 = require("./SolixE1600.js");
const app = async() => {
let configuration = {
}
if(typeof process.env.ANKER_USERNAME == 'undefined') {
console.log("SET ANKER_USERNAME=your@mail.com");
process.exit(1);
} else {
configuration.username = process.env.ANKER_USERNAME;
}
if(typeof process.env.ANKER_PASSWORD == 'undefined') {
console.log("SET ANKER_PASSWORD=yourAppPassword");
process.exit(2);
} else {
configuration.password = process.env.ANKER_PASSWORD;
}
if(typeof process.env.ANKER_COUNTRY == 'undefined') {
console.log("SET ANKER_COUNTRY=2-LETT-CODE");
process.exit(3);
} else {
configuration.country = process.env.ANKER_COUNTRY;
}
const mysolix = new SolixE1600(configuration);
let homepage = await mysolix.getSitehomepage();
console.log(process.argv);
if(typeof process.argv[2] !== 'undefined') {
console.log("Writing new Schedule");
const schedule = JSON.parse(fs.readFileSync(process.argv[2]));
await mysolix.setSchedule(schedule);
} else {
fs.writeFileSync("homepage.json", JSON.stringify(homepage));
const schedule = await mysolix.getSchedule();
fs.writeFileSync("schedule.json", JSON.stringify(schedule));
}
}
app();