File size: 2,535 Bytes
6ce20d9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
FRED ML - Setup Script
Help users set up their FRED API key and test the connection
"""

import os
import sys
from pathlib import Path

def create_env_file():
    """Create a .env file with FRED API key template"""
    env_file = Path(".env")
    
    if env_file.exists():
        print("πŸ“„ .env file already exists")
        return False
    
    env_content = """# FRED ML Environment Configuration
# Get your free API key from: https://fred.stlouisfed.org/docs/api/api_key.html

FRED_API_KEY=your-fred-api-key-here

# AWS Configuration (optional)
AWS_REGION=us-east-1
AWS_ACCESS_KEY_ID=your-access-key
AWS_SECRET_ACCESS_KEY=your-secret-key

# Application Settings
LOG_LEVEL=INFO
ENVIRONMENT=development
"""
    
    try:
        with open(env_file, 'w') as f:
            f.write(env_content)
        print("βœ… Created .env file with template")
        return True
    except Exception as e:
        print(f"❌ Failed to create .env file: {e}")
        return False

def check_dependencies():
    """Check if required dependencies are installed"""
    required_packages = ['requests', 'pandas', 'streamlit']
    missing_packages = []
    
    for package in required_packages:
        try:
            __import__(package)
        except ImportError:
            missing_packages.append(package)
    
    if missing_packages:
        print(f"❌ Missing packages: {', '.join(missing_packages)}")
        print("Install them with: pip install -r requirements.txt")
        return False
    else:
        print("βœ… All required packages are installed")
        return True

def main():
    """Main setup function"""
    print("=" * 60)
    print("FRED ML - Setup Wizard")
    print("=" * 60)
    
    # Check dependencies
    print("\nπŸ” Checking dependencies...")
    if not check_dependencies():
        return False
    
    # Create .env file
    print("\nπŸ“„ Setting up environment file...")
    create_env_file()
    
    # Instructions
    print("\nπŸ“‹ Next Steps:")
    print("1. Get a free FRED API key from: https://fred.stlouisfed.org/docs/api/api_key.html")
    print("2. Edit the .env file and replace 'your-fred-api-key-here' with your actual API key")
    print("3. Test your API key: python frontend/test_fred_api.py")
    print("4. Run the application: cd frontend && streamlit run app.py")
    
    print("\n" + "=" * 60)
    print("πŸŽ‰ Setup complete!")
    print("=" * 60)
    
    return True

if __name__ == "__main__":
    success = main()
    sys.exit(0 if success else 1)