Files

123 lines
3.8 KiB
Python

#!/usr/bin/env python3
"""
BDFR Web Interface OAuth Setup Helper
This script helps you set up Reddit OAuth for the BDFR web interface.
Run this script to configure your OAuth credentials and redirect URI.
"""
import os
import sys
from pathlib import Path
def create_env_file():
"""Create .env file from template"""
env_example = Path(__file__).parent / ".env.example"
env_file = Path(__file__).parent / ".env"
if not env_example.exists():
print("❌ Error: .env.example not found")
return False
if env_file.exists():
print("⚠️ .env file already exists")
response = input("Do you want to overwrite it? (y/N): ").lower().strip()
if response != 'y':
print("Setup cancelled")
return False
# Copy .env.example to .env
with open(env_example, 'r') as src, open(env_file, 'w') as dst:
dst.write(src.read())
print("✅ Created .env file from template")
return True
def get_oauth_instructions():
"""Display OAuth setup instructions"""
print("\n" + "="*60)
print("🔐 REDDIT OAUTH SETUP INSTRUCTIONS")
print("="*60)
print()
print("To use the BDFR Web Interface authentication features, you need to:")
print()
print("1. 📱 CREATE OR UPDATE REDDIT OAUTH APP:")
print(" • Go to: https://www.reddit.com/prefs/apps")
print(" • Find your app or click 'Create App'")
print(" • Set the redirect URI to: http://localhost:8000/auth/callback")
print()
print("2. 📝 COPY YOUR CREDENTIALS:")
print(" • After creating/editing the app, copy the client ID and secret")
print(" • These are the values that look like: 7CZHY6AmKweZME5s50SfDGylaPg")
print()
print("3. ✏️ EDIT YOUR CONFIGURATION:")
print(" • Open the .env file that was just created")
print(" • Update BDFR_REDIRECT_URI if using a different port/domain")
print(" • Update BDFR_CLIENT_ID with your OAuth client ID")
print(" • Update BDFR_CLIENT_SECRET with your OAuth client secret")
print(" • OR update bdfr/default_config.cfg with your OAuth credentials")
print()
print("💡 TIP: Use the .env file for web interface configuration")
print(" and bdfr/default_config.cfg for CLI tool configuration")
print()
print("="*60)
print()
input("Press Enter to open the .env file for editing...")
return True
def open_env_file():
"""Open .env file in default editor"""
env_file = Path(__file__).parent / ".env"
if not env_file.exists():
print("❌ Error: .env file not found")
return False
print(f"📝 Opening {env_file} for editing...")
# Try to open with default editor
editor = os.getenv('EDITOR', 'notepad' if os.name == 'nt' else 'nano')
try:
if os.name == 'nt': # Windows
os.startfile(env_file)
else: # Unix-like
os.system(f"{editor} {env_file}")
return True
except Exception as e:
print(f"❌ Error opening editor: {e}")
print(f"📍 Please manually edit the file: {env_file}")
return False
def main():
"""Main setup function"""
print("🚀 BDFR Web Interface OAuth Setup")
print("=" * 40)
# Create .env file
if not create_env_file():
return 1
# Show instructions
if not get_oauth_instructions():
return 1
# Open .env file for editing
if not open_env_file():
print("📝 Please manually edit the .env file with your OAuth settings")
print("📍 File location:", Path(__file__).parent / ".env")
print("\n✅ OAuth setup initiated!")
print("📖 Check STARTUP.md for detailed setup instructions")
print("🚀 Run 'python start.py' to start the web interface after configuration")
return 0
if __name__ == "__main__":
sys.exit(main())