-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrigger.js
More file actions
31 lines (26 loc) · 804 Bytes
/
trigger.js
File metadata and controls
31 lines (26 loc) · 804 Bytes
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
const { spawn } = require('child_process');
let data = [];
let scraper = (psearch) => {
return new Promise((resolve, reject) => {
const childProcess = spawn('python',['./pythonScraperModule/flipkartScraper.py',psearch]);
childProcess.stdout.on('data', function(data) {
resolve(data);
});
childProcess.stderr.on('data',(data)=>{
reject(data);
});
});
};
let callWebhook = async (app) => {
return await app.post('/getScrapedData/:search',async (req,res)=>{
await scraper(req.params.search).then((scrapedData)=>{
data.push(scrapedData.toString());
res !== undefined ? res.redirect('/postTwiResWebhook') : null;
})
.catch((err) => {
console.log('Error occured: ' +err);
});
});
};
module.exports.callWebhook = callWebhook;
module.exports.dataWebhook = data;