Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2021-155
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2021-155
2021-155
Commits
37cb3b82
Commit
37cb3b82
authored
Aug 09, 2021
by
Kamal Thennakoon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test running a python script inside node.js
parent
15030d1b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
0 deletions
+42
-0
backend/controllers/portfolio.js
backend/controllers/portfolio.js
+23
-0
backend/python/portfolio/scrapper.py
backend/python/portfolio/scrapper.py
+10
-0
backend/routes.js
backend/routes.js
+9
-0
No files found.
backend/controllers/portfolio.js
0 → 100644
View file @
37cb3b82
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
backend/python/portfolio/scrapper.py
0 → 100644
View file @
37cb3b82
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
()
backend/routes.js
View file @
37cb3b82
...
...
@@ -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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment