File size: 3,520 Bytes
b610d23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""

Demo script showing the configurable date range functionality.

"""

import sys
from pathlib import Path
from datetime import datetime

# Add src to Python path
sys.path.insert(0, str(Path(__file__).parent / "src"))

from src.downloader.url_generator import URLGenerator
from src.scheduler.monitoring_loop import MonitoringLoop
from src.storage.storage_organizer import StorageOrganizer
from src.downloader.image_fetcher import ImageFetcher, DownloadManager


def demo_date_range_configuration():
    """Demonstrate the configurable date range functionality."""
    print("πŸš€ NASA Solar Image Downloader - Date Range Configuration Demo")
    print("=" * 60)
    
    # Initialize components
    url_gen = URLGenerator()
    storage = StorageOrganizer("demo_data")
    fetcher = ImageFetcher(rate_limit_delay=1.0)
    manager = DownloadManager(fetcher, storage)
    
    print("βœ… Components initialized")
    
    # Test different date ranges
    end_date = datetime.now()
    
    print(f"\nπŸ“… Testing different date ranges (end date: {end_date.strftime('%Y-%m-%d')})")
    print("-" * 60)
    
    # Test 1 day (new default)
    urls_1_day = url_gen.generate_default_urls(end_date)
    print(f"πŸ“Š Default (1 day):  {len(urls_1_day):4d} URLs")
    
    # Test custom ranges
    for days in [1, 3, 7, 14, 30]:
        urls = url_gen.generate_date_range_urls(days, end_date)
        print(f"πŸ“Š {days:2d} day{'s' if days > 1 else ' '}:       {len(urls):4d} URLs")
    
    # Test monitoring loop configuration
    print(f"\nπŸ”„ Monitoring Loop Configuration")
    print("-" * 60)
    
    # Create monitoring loop with default 1 day
    monitoring = MonitoringLoop(url_gen, manager, storage, 
                               check_interval_minutes=5, 
                               monitoring_range_days=1)  # Default 1 day
    
    print(f"πŸ“Š Initial monitoring range: {monitoring.get_monitoring_range()} day(s)")
    
    # Test changing the range
    for days in [1, 3, 7, 30]:
        monitoring.set_monitoring_range(days)
        status = monitoring.get_status()
        print(f"πŸ“Š Set to {days:2d} day{'s' if days > 1 else ' '}:           {status['monitoring_range_days']} day(s)")
    
    # Show status report
    print(f"\nπŸ“‹ Status Report")
    print("-" * 60)
    
    from src.scheduler.monitoring_loop import StatusReporter
    reporter = StatusReporter(monitoring)
    reporter.print_status()
    
    print(f"\nπŸ’‘ Key Changes:")
    print(f"   β€’ Default date range changed from 30 days to 1 day")
    print(f"   β€’ Date range is now user-configurable via set_monitoring_range()")
    print(f"   β€’ URL generation supports custom date ranges")
    print(f"   β€’ Status reports show current monitoring range")
    
    print(f"\n🎯 Usage Examples:")
    print(f"   β€’ monitoring.set_monitoring_range(1)   # Check last 1 day")
    print(f"   β€’ monitoring.set_monitoring_range(7)   # Check last 7 days")
    print(f"   β€’ monitoring.set_monitoring_range(30)  # Check last 30 days")
    
    print(f"\n✨ This makes the system more efficient by default (1 day)")
    print(f"   while still allowing users to configure longer ranges as needed!")


if __name__ == "__main__":
    try:
        demo_date_range_configuration()
    except Exception as e:
        print(f"❌ Demo failed: {e}")
        import traceback
        traceback.print_exc()
        sys.exit(1)