This commit is contained in:
Andrey Kondratev
2025-09-09 15:39:28 +05:00
parent 3b2d5ece24
commit d4debf9b63
33 changed files with 1274 additions and 9585 deletions

91
setup.py Normal file
View File

@@ -0,0 +1,91 @@
#!/usr/bin/env python3
"""
Setup script for Quixotic Python Backend
"""
import os
import sys
import subprocess
def run_command(cmd, description):
"""Run a command and handle errors"""
print(f"📦 {description}...")
try:
subprocess.run(cmd, shell=True, check=True)
print(f"{description} completed successfully")
except subprocess.CalledProcessError as e:
print(f"{description} failed: {e}")
return False
return True
def main():
"""Main setup function"""
print("🚀 Setting up Quixotic Python Backend...")
# Check Python version
if sys.version_info < (3, 8):
print("❌ Python 3.8 or higher is required")
return False
print(f"✅ Python {sys.version.split()[0]} detected")
# Create virtual environment if it doesn't exist
if not os.path.exists("venv"):
if not run_command("python -m venv venv", "Creating virtual environment"):
return False
# Activate virtual environment and install dependencies
if os.name == 'nt': # Windows
activate_cmd = "venv\\Scripts\\activate && "
else: # Unix/Linux/Mac
activate_cmd = "source venv/bin/activate && "
if not run_command(f"{activate_cmd}pip install -r requirements.txt", "Installing Python dependencies"):
return False
# Create necessary directories
directories = ["downloads", "database"]
for directory in directories:
if not os.path.exists(directory):
os.makedirs(directory)
print(f"📁 Created directory: {directory}")
# Check for environment variables
print("\n🔧 Environment Setup:")
required_vars = [
("DATABASE_URL", "postgresql://user:password@localhost:5432/quixotic"),
("VK_LOGIN", "your_vk_login"),
("VK_PASSWORD", "your_vk_password"),
("TELEGRAM_BOT_TOKEN", "your_telegram_bot_token"),
("WEB_APP_URL", "http://localhost:8000")
]
env_file_content = []
for var_name, example in required_vars:
if not os.getenv(var_name):
print(f"⚠️ {var_name} not set (example: {example})")
env_file_content.append(f"{var_name}={example}")
else:
print(f"{var_name} is configured")
# Create .env file if needed
if env_file_content and not os.path.exists(".env"):
with open(".env", "w") as f:
f.write("# Quixotic Python Backend Environment Variables\n")
f.write("# Copy this file and update with your actual values\n\n")
f.write("\n".join(env_file_content))
print("📝 Created .env file with example values")
print("\n🎉 Setup completed successfully!")
print("\n📋 Next steps:")
print("1. Update .env file with your actual credentials")
print("2. Set up PostgreSQL database")
print("3. Run: python main.py")
print("4. Access the API at: http://localhost:8000")
return True
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)