You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
695 B
25 lines
695 B
#coding:utf8
|
|
import json
|
|
from jsonpath_ng import jsonpath, parse
|
|
import logging
|
|
import traceback
|
|
# 初始化日志
|
|
logger = logging.getLogger(__name__)
|
|
def get_value(data,formula):
|
|
'''
|
|
根据公式获取数据
|
|
:param data: 数据源
|
|
:param formula: 公式
|
|
:return:
|
|
'''
|
|
try:
|
|
datas = str(formula).split(':')
|
|
# 创建 JsonPath 表达式
|
|
expr = parse(datas[1])
|
|
# 使用表达式来选择 JSON 元素
|
|
match = [match.value for match in expr.find(json.loads(data[datas[0]]))]
|
|
return match[0]
|
|
except Exception as e:
|
|
traceback.print_exc()
|
|
logger.error(f"动态获取数据失败: {e}")
|
|
return None
|