-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
74 lines (62 loc) · 2.68 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
const express = require('express')
const app = express()
const {PythonShell} =require('python-shell');
app.use(express.static( "assets" ))
app.set('view engine','ejs')
app.get("/", (req, res) =>{
res.render('index')
})
app.get("/get-solution/:state", (req,res) =>{
let state = req.params.state
let options = {
mode: 'text',
pythonOptions: ['-u'], // get print results in real-time
//scriptPath: 'calculate.py', //If you are having python_test.py script in same folder, then it's optional.
args: [state, 'findSolution'] //An argument which can be accessed in the script using sys.argv[1]
};
PythonShell.run('main.py', options, function (err, result){
if (err) throw err;
// result is an array consisting of messages collected
//during execution of script.
console.log(state, '=>', result.toString());
res.end(result.toString())
});
})
app.get("/is-completed/:state", (req, res)=>{
let state = req.params.state
//Here are the option object in which arguments can be passed for the python_test.js.
let options = {
mode: 'text',
pythonOptions: ['-u'], // get print results in real-time
//scriptPath: 'calculate.py', //If you are having python_test.py script in same folder, then it's optional.
args: [state, 'isCompleted'] //An argument which can be accessed in the script using sys.argv[1]
};
PythonShell.run('main.py', options, function (err, result){
if (err) throw err;
// result is an array consisting of messages collected
//during execution of script.
console.log(state, '=>', result.toString());
res.end(result.toString())
});
});
app.get("/is-safe/:state", (req, res)=>{
let state = req.params.state
//Here are the option object in which arguments can be passed for the python_test.js.
let options = {
mode: 'text',
pythonOptions: ['-u'], // get print results in real-time
//scriptPath: 'calculate.py', //If you are having python_test.py script in same folder, then it's optional.
args: [state, 'isSafe'] //An argument which can be accessed in the script using sys.argv[1]
};
PythonShell.run('main.py', options, function (err, result){
if (err) throw err;
// result is an array consisting of messages collected
//during execution of script.
console.log(state, '=>', result.toString());
res.end(result.toString())
});
});
let port = process.env.PORT || 3000
app.listen(port, () => {
console.log("App running...")
})