-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpoe.js
More file actions
30 lines (25 loc) · 832 Bytes
/
Copy pathpoe.js
File metadata and controls
30 lines (25 loc) · 832 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
import fs from 'fs/promises';
import { exec } from 'child_process';
import { promisify } from 'util';
const newsContentFile = './poe-query/_input_content.txt';
const newsReportFile = './poe-query/_output.txt';
const execPromise = promisify(exec);
export async function queryNewsToPoe(content) {
try {
await fs.writeFile(newsContentFile, content);
const command = 'cd poe-query && python3 poe.py';
const { stdout, stderr } = await Promise.race([
execPromise(command),
]);
// console.log(`stdout: ${stdout}`);
// console.error(`stderr: ${stderr}`);
const data = await fs.readFile(newsReportFile, 'utf8');
return data;
} catch (err) {
console.error(err);
}
}
// const report = await queryNewsToPoe('this is a sample news.');
// if(report){
// console.log(JSON.parse(report));
// }