12345678910111213141516171819202122232425 |
- """
- @author: luojunhui
- """
- import json
- import subprocess
- from config import toutiao_js_path
- def call_js_function(arguments_list):
- """
- call js function
- """
- # 将参数转换为JSON字符串
- args_json = json.dumps(arguments_list)
- # 调用Node.js执行脚本
- result = subprocess.run(
- ['node', toutiao_js_path, args_json],
- capture_output=True,
- text=True
- )
- if result.returncode == 0:
- return result.stdout.strip()
- else:
- raise Exception(f"Error: {result.stderr}")
|