-
Notifications
You must be signed in to change notification settings - Fork 4
/
predict.js
39 lines (33 loc) · 834 Bytes
/
predict.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
const { spawn } = require("child_process");
module.exports =
{
// execute the python script to get a list of passes
getPasses: async (tleData, lon, lat) =>
{
const numDays = 10;
const scriptName = "predict.py";
const pyPredict = spawn("python3", ["predict.py", JSON.stringify(tleData), lon, lat, numDays]);
return new Promise((resolve, reject) =>
{
let dataString = "";
pyPredict.stdout.on("data", data =>
{
dataString += data.toString("utf8");
});
pyPredict.stderr.on("data", data =>
{
console.log(`ERROR in ${scriptName}: `, data.toString("utf8"));
reject();
});
pyPredict.on("error", err =>
{
console.log(`ERROR in ${scriptName}: `, err.toString("utf8"));
reject();
});
pyPredict.on("close", code =>
{
resolve(JSON.parse(dataString));
});
});
}
}