#!/usr/bin/env python3 # -*- coding: utf-8 -*- import sys import os # 添加src目录到Python路径 sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src')) from ui.word_style_ui import daily_sentence_API from services.network_service import NetworkService def test_daily_sentence_api(): print("测试 daily_sentence_API 类...") try: # 使用与Ribbon界面相同的API获取每日一言 quote_api = daily_sentence_API("https://api.nxvav.cn/api/yiyan") quote_data = quote_api.get_sentence('json') print("API返回的数据:") print(quote_data) # 处理获取到的数据 if quote_data and isinstance(quote_data, dict): quote_text = quote_data.get('yiyan', '暂无每日一言') print(f"解析后的每日一言: {quote_text}") else: print("获取每日一言失败") except Exception as e: print(f"测试 daily_sentence_API 类时出错: {e}") def test_network_service_quote(): print("\n测试 NetworkService 类的 get_daily_quote 方法...") try: network_service = NetworkService() quote = network_service.get_daily_quote() print(f"NetworkService 获取的每日一言: {quote}") except Exception as e: print(f"测试 NetworkService 类时出错: {e}") if __name__ == "__main__": test_daily_sentence_api() test_network_service_quote()