行运盘API文档
接口说明
本接口用于生成行运盘,需要提供本命盘数据和行运时间。行运盘显示特定时刻的实际天象与本命盘的关系,是占星预测中最基础和重要的技术之一。
基本信息
- 接口URL:
/onechart
- 请求方式: POST
- Content-Type: application/json
请求参数
参数名 | 类型 | 必选 | 说明 |
---|---|---|---|
chart_type | string | 是 | 固定值:"transit" |
data1.date | string | 是 | 本命盘日期,格式:YYYY-MM-DD |
data1.time | string | 是 | 本命盘时间,格式:HH:mm:ss |
data1.lat | number | 是 | 本命盘地点纬度 |
data1.lon | number | 是 | 本命盘地点经度 |
data1.tz | string | 是 | 本命盘地点时区 |
data2.date | string | 是 | 行运时间日期,格式:YYYY-MM-DD |
data2.time | string | 是 | 行运时间时间,格式:HH:mm:ss |
data2.lat | number | 是 | 行运地点纬度 |
data2.lon | number | 是 | 行运地点经度 |
data2.tz | string | 是 | 行运地点时区 |
house_system | string | 否 | 宫位系统,默认为占星安宫(P) |
use_chinese_font | boolean | 否 | 是否使用中文字体,默认false |
请求示例
{
"chart_type": "transit",
"data": {
"datetime": "2024-01-01 12:00:00",
"lat": 39.9042,
"lon": 116.4074,
"tz": "8.0"
},
"house_system": "P",
"use_chinese_font": true
}
返回参数
参数名 | 类型 | 说明 |
---|---|---|
success | boolean | 请求是否成功 |
data | object | 星盘数据,包含行星位置、宫位等信息 |
svg | string | 星盘SVG图形数据 |
返回示例
{
"success": true,
"data": {
"chart_type": "transit",
"planets": [
{"name": "sun", "degree": 280.5, ...},
{"name": "moon", "degree": 125.3, ...},
...
],
"houses": [
{"house": 1, "degree": 45.2, ...},
{"house": 2, "degree": 75.8, ...},
...
]
},
"svg": "..."
}
Python测试代码示例
import requests
import json
import os
from datetime import datetime, timezone
class TransitChartAPITest:
def __init__(self, base_url="http://localhost:5000"):
self.base_url = base_url
self.endpoint = f"{base_url}/onechart"
# 创建输出目录
self.output_dir = "test_chart_outputs"
if not os.path.exists(self.output_dir):
os.makedirs(self.output_dir)
def test_transit_chart(self):
"""测试行运盘API"""
# 使用当前时间作为行运时间
now_utc = datetime.now(timezone.utc)
current_time = now_utc.strftime('%Y-%m-%d %H:%M:%S')
payload = {
"chart_type": "transit",
"data": {
"datetime": current_time,
"lat": 39.9042,
"lon": 116.4074,
"tz": "8.0"
},
"house_system": "P",
"use_chinese_font": True
}
try:
print(f"正在测试行运盘API: {self.endpoint}")
print(f"请求数据: {json.dumps(payload, indent=2, ensure_ascii=False)}")
response = requests.post(
self.endpoint,
json=payload,
headers={'Content-Type': 'application/json'}
)
print(f"响应状态码: {response.status_code}")
if response.status_code == 200:
result = response.json()
print("行运盘API测试成功!")
print(f"返回数据包含: {list(result.keys())}")
# 保存SVG文件
if 'svg' in result and result['svg']:
svg_filename = os.path.join(self.output_dir, 'transit_chart_test.svg')
with open(svg_filename, 'w', encoding='utf-8') as f:
f.write(result['svg'])
print(f"SVG文件已保存: {svg_filename}")
else:
print("警告: 响应中没有SVG数据")
return result
else:
print(f"API请求失败: {response.status_code}")
print(f"错误信息: {response.text}")
return None
except requests.exceptions.RequestException as e:
print(f"请求错误: {e}")
return None
except json.JSONDecodeError as e:
print(f"JSON解析错误: {e}")
return None
except Exception as e:
print(f"未知错误: {e}")
return None
def test_transit_for_specific_date(self, target_date="2024-12-25 12:00:00"):
"""测试指定日期的行运盘"""
payload = {
"chart_type": "transit",
"data": {
"datetime": target_date,
"lat": 39.9042,
"lon": 116.4074,
"tz": "8.0"
},
"house_system": "P",
"use_chinese_font": True
}
try:
print(f"\n正在测试指定日期行运盘: {target_date}")
response = requests.post(
self.endpoint,
json=payload,
headers={'Content-Type': 'application/json'}
)
if response.status_code == 200:
result = response.json()
print(f"✓ 指定日期行运盘测试成功")
# 保存SVG文件
if 'svg' in result and result['svg']:
date_str = target_date.replace(' ', '_').replace(':', '-')
svg_filename = os.path.join(self.output_dir, f'transit_chart_{date_str}.svg')
with open(svg_filename, 'w', encoding='utf-8') as f:
f.write(result['svg'])
print(f" SVG已保存: {svg_filename}")
return result
else:
print(f"✗ 指定日期行运盘测试失败: {response.status_code}")
print(f"错误信息: {response.text}")
return None
except Exception as e:
print(f"✗ 指定日期行运盘测试出错: {e}")
return None
def test_transit_different_locations(self):
"""测试不同地点的行运盘"""
locations = {
"北京": {"lat": 39.9042, "lon": 116.4074, "tz": "8.0"},
"纽约": {"lat": 40.7128, "lon": -74.0060, "tz": "-5.0"},
"伦敦": {"lat": 51.5074, "lon": -0.1278, "tz": "0.0"},
"东京": {"lat": 35.6762, "lon": 139.6503, "tz": "9.0"}
}
current_time = datetime.now(timezone.utc).strftime('%Y-%m-%d %H:%M:%S')
for city_name, location in locations.items():
print(f"\n测试{city_name}的行运盘")
payload = {
"chart_type": "transit",
"data": {
"datetime": current_time,
"lat": location["lat"],
"lon": location["lon"],
"tz": location["tz"]
},
"house_system": "P",
"use_chinese_font": True
}
try:
response = requests.post(
self.endpoint,
json=payload,
headers={'Content-Type': 'application/json'}
)
if response.status_code == 200:
result = response.json()
print(f"✓ {city_name}行运盘测试成功")
# 保存SVG文件
if 'svg' in result and result['svg']:
svg_filename = os.path.join(self.output_dir, f'transit_chart_{city_name}.svg')
with open(svg_filename, 'w', encoding='utf-8') as f:
f.write(result['svg'])
print(f" SVG已保存: {svg_filename}")
else:
print(f"✗ {city_name}行运盘测试失败: {response.status_code}")
except Exception as e:
print(f"✗ {city_name}行运盘测试出错: {e}")
# 使用示例
if __name__ == "__main__":
base_url = "http://localhost:5000"
tester = TransitChartAPITest(base_url)
print("=== 行运盘API基本测试 ===")
result = tester.test_transit_chart()
print("\n=== 指定日期行运盘测试 ===")
tester.test_transit_for_specific_date("2024-12-25 12:00:00")
print("\n=== 不同地点行运盘测试 ===")
tester.test_transit_different_locations()
print("\n测试完成!")
注意事项
- 行运盘显示当前天象与本命盘的关系
- 使用data参数传递行运时间和地点信息
- 时间格式必须严格遵循YYYY-MM-DD HH:MM:SS的格式
- 经纬度使用小数格式,东经北纬为正,西经南纬为负
- 时区格式为数字字符串,如"8.0"表示UTC+8,"-5.0"表示UTC-5
- 行运盘是最基础的预测技术,可显示当前天象对本命盘的影响
- API已通过完整测试,确保参数格式正确
WEIXIN:ALWENLAU