-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_real_api_validation.py
More file actions
164 lines (132 loc) · 5.02 KB
/
setup_real_api_validation.py
File metadata and controls
164 lines (132 loc) · 5.02 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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/env python3
"""
Real API Validation Study Setup Script
Helps you get started with the validation study
"""
import os
import sys
import subprocess
import shutil
from pathlib import Path
def print_header():
"""Print setup header"""
print("🚀 Real API Validation Study - Setup Script")
print("=" * 60)
print("This script will help you set up the real API validation study.")
print("Follow the steps to get your environment ready for testing.")
print()
def check_python_version():
"""Check if Python version is compatible"""
print("🐍 Checking Python version...")
if sys.version_info < (3, 7):
print("❌ Python 3.7+ required. Current version:", sys.version)
return False
print(f"✅ Python {sys.version.split()[0]} - Compatible")
return True
def install_requirements():
"""Install required Python packages"""
print("\n📦 Installing required packages...")
required_packages = [
"aiohttp",
"asyncio",
"python-dotenv",
"cryptography",
"numpy",
"pandas"
]
try:
for package in required_packages:
print(f" Installing {package}...")
subprocess.check_call([sys.executable, "-m", "pip", "install", package],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL)
print("✅ All packages installed successfully")
return True
except subprocess.CalledProcessError as e:
print(f"❌ Failed to install packages: {e}")
print("Please run: pip install aiohttp python-dotenv cryptography numpy pandas")
return False
def setup_environment_file():
"""Set up the .env file"""
print("\n🔧 Setting up environment file...")
if os.path.exists('.env'):
print("⚠️ .env file already exists")
response = input("Do you want to backup and replace it? (y/n): ").lower()
if response == 'y':
shutil.copy('.env', '.env.backup')
print("✅ Existing .env backed up to .env.backup")
else:
print("📝 Keeping existing .env file")
return True
# Copy template to .env
if os.path.exists('.env.real_api_template'):
shutil.copy('.env.real_api_template', '.env')
print("✅ Created .env file from template")
print("📝 Please edit .env and add your API keys")
return True
else:
print("❌ Template file not found")
return False
def create_directory_structure():
"""Create necessary directories"""
print("\n📁 Creating directory structure...")
directories = [
"results",
"results/raw_data",
"results/processed",
"results/comparisons",
"logs"
]
for directory in directories:
Path(directory).mkdir(parents=True, exist_ok=True)
print(f" ✅ Created: {directory}/")
print("✅ Directory structure created")
def print_next_steps():
"""Print next steps for the user"""
print("\n🎯 NEXT STEPS:")
print("=" * 60)
print("\n1. 🔑 GET API KEYS (Start with Tier 1):")
print(" • OpenWeatherMap: https://openweathermap.org/api")
print(" • WeatherAPI: https://www.weatherapi.com/signup.aspx")
print(" • NewsAPI: https://newsapi.org/register")
print(" • Guardian: https://open-platform.theguardian.com/access/")
print(" • Fixer.io: https://fixer.io/signup")
print("\n2. 📝 EDIT .env FILE:")
print(" • Open .env in your text editor")
print(" • Replace 'your_*_api_key_here' with actual API keys")
print(" • Save the file")
print("\n3. 🧪 TEST API ACCESS:")
print(" • Run: python quick_api_validation_test.py")
print(" • This will test all your API keys")
print(" • Make sure at least 3 APIs are working")
print("\n4. 🚀 START VALIDATION STUDY:")
print(" • Once APIs are working, proceed with the full study")
print(" • Follow the timeline in REAL_API_VALIDATION_ACTION_PLAN.md")
print("\n📚 HELPFUL FILES:")
print(" • IMMEDIATE_ACTION_CHECKLIST.md - Day-by-day guide")
print(" • api_provider_selection_matrix.md - All API details")
print(" • quick_api_validation_test.py - Test your setup")
def main():
"""Main setup function"""
print_header()
# Check Python version
if not check_python_version():
return False
# Install requirements
if not install_requirements():
return False
# Setup environment
if not setup_environment_file():
return False
# Create directories
create_directory_structure()
# Print next steps
print_next_steps()
print("\n🎉 SETUP COMPLETE!")
print("You're ready to start the real API validation study.")
print("Begin by getting your API keys and testing them.")
return True
if __name__ == "__main__":
success = main()
if not success:
sys.exit(1)