forked from p9o3yklam/Curriculum_Design
parent
c1d1ebdec6
commit
c23347f7f9
@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
测试天气生活提示功能
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
|
||||
# 添加src目录到路径
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
|
||||
|
||||
from services.network_service import NetworkService
|
||||
|
||||
def test_weather_with_lifetips():
|
||||
"""测试包含生活提示的天气功能"""
|
||||
print("🌤 测试天气生活提示功能")
|
||||
print("=" * 50)
|
||||
|
||||
# 创建网络服务实例
|
||||
network_service = NetworkService()
|
||||
|
||||
# 获取天气信息
|
||||
print("正在获取天气信息...")
|
||||
weather_info = network_service.get_weather_info()
|
||||
|
||||
if weather_info:
|
||||
print(f"✅ 成功获取天气数据:")
|
||||
print(f"城市: {weather_info['city']}")
|
||||
print(f"温度: {weather_info['temperature']}°C")
|
||||
print(f"天气: {weather_info['description']}")
|
||||
print(f"湿度: {weather_info['humidity']}%")
|
||||
print(f"风速: {weather_info['wind_speed']}m/s")
|
||||
|
||||
# 显示生活提示
|
||||
lifetips = weather_info.get('lifetips', [])
|
||||
if lifetips:
|
||||
print(f"\n🌟 生活提示 ({len(lifetips)}条):")
|
||||
for i, tip in enumerate(lifetips, 1):
|
||||
print(f" {i}. {tip}")
|
||||
else:
|
||||
print("⚠️ 未获取到生活提示")
|
||||
|
||||
# 模拟显示详细信息格式
|
||||
print(f"\n📋 详细信息显示格式:")
|
||||
weather_text = f"{weather_info['city']}: {weather_info['temperature']}°C, {weather_info['description']}"
|
||||
weather_text += f"\n湿度: {weather_info['humidity']}%"
|
||||
weather_text += f"\n风速: {weather_info['wind_speed']}m/s"
|
||||
|
||||
if lifetips:
|
||||
weather_text += "\n\n🌟 生活提示:"
|
||||
for tip in lifetips:
|
||||
weather_text += f"\n• {tip}"
|
||||
|
||||
print(weather_text)
|
||||
|
||||
else:
|
||||
print("❌ 获取天气信息失败")
|
||||
|
||||
print("\n" + "=" * 50)
|
||||
print("测试完成!")
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_weather_with_lifetips()
|
||||
Loading…
Reference in new issue