start real time simulation api
This commit is contained in:
@@ -17,7 +17,7 @@ def convert_to_beijing_time(utc_time_str):
|
||||
return beijing_time
|
||||
|
||||
|
||||
def get_realValue(ids):
|
||||
def get_realValue(ids)->dict[str,float]:
|
||||
# 数据接口的地址
|
||||
url = 'http://183.64.62.100:9057/loong/api/mpoints/realValue'
|
||||
|
||||
@@ -25,7 +25,7 @@ def get_realValue(ids):
|
||||
params = {
|
||||
'ids': ids
|
||||
}
|
||||
|
||||
lst_data={}
|
||||
try:
|
||||
# 发送GET请求获取数据
|
||||
response = requests.get(url, params=params)
|
||||
@@ -34,25 +34,27 @@ def get_realValue(ids):
|
||||
if response.status_code == 200:
|
||||
# 解析响应的JSON数据
|
||||
data = response.json()
|
||||
|
||||
|
||||
# 只打印'id'、'datadt'和'realValue'数据
|
||||
for realValue in data:
|
||||
print("id:", realValue['id'])
|
||||
print("mpointName:",realValue['mpointName'])
|
||||
#print("id:", realValue['id'])
|
||||
#print("mpointName:",realValue['mpointName'])
|
||||
# print("datadt:", realValue['datadt'])
|
||||
# 转换datadt字段为北京时间
|
||||
beijing_time = convert_to_beijing_time(realValue['datadt'])
|
||||
print("datadt (Beijing Time):", beijing_time.strftime('%Y-%m-%d %H:%M:%S'))
|
||||
print("realValue:", realValue['realValue'])
|
||||
print() # 打印空行分隔不同条目
|
||||
#beijing_time = convert_to_beijing_time(realValue['datadt'])
|
||||
#print("datadt (Beijing Time):", beijing_time.strftime('%Y-%m-%d %H:%M:%S'))
|
||||
#print("realValue:", realValue['realValue'])
|
||||
#print() # 打印空行分隔不同条目
|
||||
r=float(realValue['value'])
|
||||
lst_data[str(realValue['id'])]=r
|
||||
else:
|
||||
# 如果请求不成功,打印错误信息
|
||||
print("请求失败,状态码:", response.status_code)
|
||||
|
||||
return lst_data
|
||||
except Exception as e:
|
||||
# 捕获异常
|
||||
print("发生异常:", e)
|
||||
|
||||
|
||||
# 使用示例
|
||||
get_realValue(ids='2498,2500')
|
||||
#get_realValue(ids='2498,2500')
|
||||
Reference in New Issue
Block a user