Commit 37cb3b82 authored by Kamal Thennakoon's avatar Kamal Thennakoon

test running a python script inside node.js

parent 15030d1b
const { spawn } = require('child_process');
const path=require('path');
exports.testPortfolio=async(req,res,next)=>{
try{
const {title,tag,id}=req.body;
const pythonScript=spawn('python',[
path.join(__dirname,'..','python','portfolio','scrapper.py'),
title,
tag,
id
]);
pythonScript.stdout.on('data',(data)=>{
console.log('Python test output',data.toString());
});
pythonScript.stdout.on('end',()=>{
console.log('Python script has finshed executing')
})
}catch(error){
next(error);
}
res.status(201).json({msg:"success"});
}
\ No newline at end of file
import sys
if __name__ == "__main__":
# title = input("Enter question title: ")
title = sys.argv[1] # "python django or flask for web development"
tags = sys.argv[2] # ["react"]
AUTO_ANS_ID = sys.argv[3] # "60dc9a5f84692f001569d7ab"
print('title: ',title)
sys.stdout.flush()
......@@ -30,6 +30,8 @@ const requireAuth = require('./middlewares/requireAuth');
const questionAuth = require('./middlewares/questionAuth');
const commentAuth = require('./middlewares/commentAuth');
const answerAuth = require('./middlewares/answerAuth');
const { requestAutomatedAnswer, getAutomatedAnswer } = require('./controllers/automated-answer');
const { testPortfolio } = require('./controllers/portfolio');
const router = require('express').Router();
......@@ -72,6 +74,13 @@ router.post('/comment/:question/:answer?', [requireAuth, validate], createCommen
router.delete('/comment/:question/:comment', [requireAuth, commentAuth], removeComment);
router.delete('/comment/:question/:answer/:comment', [requireAuth, commentAuth], removeComment);
//automate-answer
router.post('/automatedanswer', requireAuth, requestAutomatedAnswer);
router.get('/automatedanswer/:qid', getAutomatedAnswer);
//portfolio
router.post('/portfolio/test',testPortfolio);
module.exports = (app) => {
app.use('/api', router);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment