Spaces:
TDN-M
/
Running on Zero

File size: 3,932 Bytes
36d7d16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env python3
"""
Test script cho tính năng tin thể thao
Kiểm tra việc lấy tin từ các nguồn RSS
"""

import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))

from sports_news import get_sports_news_content, SportsNewsAggregator
import asyncio

def test_basic_functionality():
    """Test cơ bản cho tính năng tin thể thao"""
    print("🏃‍♂️ Testing Sports News Functionality...")
    print("=" * 50)
    
    try:
        # Test lấy tin thể thao tiếng Việt
        print("📰 Testing Vietnamese sports news...")
        vi_content = get_sports_news_content('all', 'vi', 3)
        print("Vietnamese Content:")
        print(vi_content[:500] + "..." if len(vi_content) > 500 else vi_content)
        print("\n" + "-" * 30 + "\n")
        
        # Test lấy tin bóng đá
        print("⚽ Testing football news...")
        football_content = get_sports_news_content('football', 'vi', 2)
        print("Football Content:")
        print(football_content[:500] + "..." if len(football_content) > 500 else football_content)
        print("\n" + "-" * 30 + "\n")
        
        # Test lấy tin tiếng Anh
        print("🌍 Testing English sports news...")
        en_content = get_sports_news_content('all', 'en', 2)
        print("English Content:")
        print(en_content[:500] + "..." if len(en_content) > 500 else en_content)
        print("\n" + "-" * 30 + "\n")
        
        print("✅ All tests completed successfully!")
        return True
        
    except Exception as e:
        print(f"❌ Error during testing: {str(e)}")
        return False

def test_aggregator_directly():
    """Test trực tiếp SportsNewsAggregator class"""
    print("🔧 Testing SportsNewsAggregator directly...")
    print("=" * 50)
    
    try:
        aggregator = SportsNewsAggregator()
        
        # Test lấy tin từ một nguồn cụ thể
        print("📡 Testing individual RSS sources...")
        
        # Test với VnExpress
        vnexpress_config = {
            'url': 'https://vnexpress.net/rss/the-thao.rss',
            'type': 'rss',
            'language': 'vi',
            'name': 'vnexpress_sport'
        }
        
        news_items = aggregator.get_rss_news(vnexpress_config)
        print(f"VnExpress Sports: Found {len(news_items)} articles")
        
        if news_items:
            print("Sample article:")
            print(f"Title: {news_items[0]['title']}")
            print(f"Summary: {news_items[0]['summary'][:200]}...")
        
        print("\n" + "-" * 30 + "\n")
        
        # Test format cho TTS
        print("🎤 Testing TTS formatting...")
        formatted = aggregator.format_news_for_tts(news_items[:2], 'vi')
        print("Formatted for TTS:")
        print(formatted[:300] + "..." if len(formatted) > 300 else formatted)
        
        print("✅ Aggregator test completed successfully!")
        return True
        
    except Exception as e:
        print(f"❌ Error during aggregator testing: {str(e)}")
        import traceback
        traceback.print_exc()
        return False

def main():
    """Chạy tất cả các test"""
    print("🚀 Starting Sports News Tests...")
    print("=" * 60)
    
    # Test cơ bản
    basic_success = test_basic_functionality()
    
    print("\n" + "=" * 60 + "\n")
    
    # Test aggregator
    aggregator_success = test_aggregator_directly()
    
    print("\n" + "=" * 60)
    print("📊 TEST SUMMARY:")
    print(f"Basic functionality: {'✅ PASS' if basic_success else '❌ FAIL'}")
    print(f"Aggregator test: {'✅ PASS' if aggregator_success else '❌ FAIL'}")
    
    if basic_success and aggregator_success:
        print("🎉 All tests passed! Sports news feature is ready to use.")
    else:
        print("⚠️  Some tests failed. Please check the errors above.")

if __name__ == "__main__":
    main()