stock_fundamentals/tools/trigger_batch_collection.py

35 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import requests
import json
def trigger_batch_stock_price_collection():
"""
一个简单的工具函数用于触发批量采集A股行情的调度器接口并打印响应。
"""
# 目标URL
url = "http://192.168.16.214:5089/scheduler/batch_stock_price/collection"
print(f"正在向以下地址发送GET请求:\n{url}\n")
try:
# 发送GET请求可以设置一个超时时间例如10秒
response = requests.get(url, timeout=30)
# 检查响应状态码
print(f"请求完成HTTP状态码: {response.status_code}\n")
# 尝试将响应体解析为JSON格式并打印
try:
response_json = response.json()
print("服务器响应内容 (JSON格式):")
# 使用json.dumps美化输出
print(json.dumps(response_json, indent=2, ensure_ascii=False))
except json.JSONDecodeError:
print("服务器响应内容 (非JSON格式):")
print(response.text)
except requests.exceptions.RequestException as e:
# 处理请求过程中可能出现的异常(如网络问题、超时等)
print(f"请求失败,发生异常: {e}")
if __name__ == '__main__':
trigger_batch_stock_price_collection()