forked from rotemweiss57/gpt-newspaper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate_env.py
More file actions
67 lines (55 loc) · 2.31 KB
/
validate_env.py
File metadata and controls
67 lines (55 loc) · 2.31 KB
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
#!/usr/bin/env python3
"""
Environment Variables Validation Script for GPT Newspaper
This script validates that all required environment variables are properly set.
"""
import os
def load_env_file():
"""Load environment variables from .env file if it exists."""
env_file = '.env'
if os.path.exists(env_file):
with open(env_file, 'r') as f:
for line in f:
line = line.strip()
if line and not line.startswith('#') and '=' in line:
key, value = line.split('=', 1)
os.environ[key] = value
def validate_env_vars():
"""Validate that all required environment variables are set."""
# Load environment variables from .env file
load_env_file()
required_vars = {
'TAVILY_API_KEY': 'Tavily API key for web search functionality',
'OPENAI_API_KEY': 'OpenAI API key for article generation'
}
print("🔍 Validating environment variables...\n")
all_valid = True
for var_name, description in required_vars.items():
value = os.getenv(var_name)
if not value:
print(f"❌ {var_name}: Not set")
print(f" Description: {description}")
all_valid = False
elif value.strip() in ['your_tavily_api_key_here', 'your_openai_api_key_here', '<your-tavily-api-key>', '<your-openai-api-key>']:
print(f"⚠️ {var_name}: Contains placeholder value")
print(f" Description: {description}")
print(f" Current value: {value}")
all_valid = False
else:
print(f"✅ {var_name}: Set correctly")
print()
if all_valid:
print("🎉 All environment variables are properly configured!")
print("You can now run the GPT Newspaper application.")
else:
print("❌ Some environment variables need attention.")
print("\nTo fix this:")
print("1. Edit the .env file in the project root")
print("2. Replace placeholder values with your actual API keys")
print("3. Save the file and run this script again")
print("\nAPI key sources:")
print("- Tavily: https://tavily.com/")
print("- OpenAI: https://platform.openai.com/")
return all_valid
if __name__ == "__main__":
validate_env_vars()