-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
142 lines (120 loc) · 4.13 KB
/
setup.py
File metadata and controls
142 lines (120 loc) · 4.13 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
#!/usr/bin/env python3
"""
setup.py - Automated setup script for Room Finder AI Bot (Cross-platform)
Works on Windows, macOS, and Linux
"""
import os
import sys
import subprocess
import shutil
from pathlib import Path
def check_python_version():
"""Check if Python version is 3.8 or higher"""
version = sys.version_info
if version.major < 3 or (version.major == 3 and version.minor < 8):
print(f"✗ Python 3.8+ required. Found: {version.major}.{version.minor}")
return False
print(f"✓ Python {version.major}.{version.minor} detected")
return True
def create_venv():
"""Create virtual environment"""
venv_path = Path("venv")
if venv_path.exists():
print("✓ Virtual environment already exists")
return True
print("✓ Creating virtual environment...")
try:
subprocess.check_call([sys.executable, "-m", "venv", "venv"])
print("✓ Virtual environment created")
return True
except subprocess.CalledProcessError:
print("✗ Failed to create virtual environment")
return False
def get_pip_executable():
"""Get the pip executable for the virtual environment"""
if sys.platform == "win32":
return Path("venv/Scripts/pip.exe")
else:
return Path("venv/bin/pip")
def install_dependencies():
"""Install required dependencies"""
print("✓ Installing dependencies...")
pip_exe = get_pip_executable()
if not pip_exe.exists():
print("✗ Could not find pip executable")
return False
try:
# Upgrade pip first
subprocess.check_call([str(pip_exe), "install", "--upgrade", "pip"])
# Install requirements
subprocess.check_call([str(pip_exe), "install", "-r", "requirements.txt"])
print("✓ Dependencies installed")
return True
except subprocess.CalledProcessError:
print("✗ Failed to install dependencies")
return False
def setup_env_file():
"""Create .env file from template if it doesn't exist"""
env_path = Path(".env")
env_example = Path(".env.example")
if env_path.exists():
print("✓ .env file already exists")
return True
if not env_example.exists():
print("✗ .env.example not found")
return False
print("✓ Creating .env file from .env.example...")
try:
shutil.copy(env_example, env_path)
# Set secure permissions on Unix-like systems
if sys.platform != "win32":
os.chmod(env_path, 0o600)
print("✓ .env file created")
print("⚠️ IMPORTANT: Edit .env with your credentials:")
print(" - TELEGRAM_API_ID")
print(" - TELEGRAM_API_HASH")
print(" - DEEPSEEK_API_KEY")
print(" - WAHA_API_KEY (if using WhatsApp)")
return True
except Exception as e:
print(f"✗ Failed to create .env: {e}")
return False
def get_activation_command():
"""Get the virtual environment activation command"""
if sys.platform == "win32":
return "venv\\Scripts\\activate"
else:
return "source venv/bin/activate"
def main():
"""Run the setup process"""
print("🏠 Room Finder AI Bot - Setup Script")
print("=" * 50)
print("")
# Check Python version
if not check_python_version():
sys.exit(1)
# Create virtual environment
print("")
if not create_venv():
sys.exit(1)
# Install dependencies
print("")
if not install_dependencies():
sys.exit(1)
# Setup .env file
print("")
if not setup_env_file():
print("⚠️ Warning: Could not set up .env file automatically")
# Success message
print("")
print("✅ Setup complete!")
print("")
print("Next steps:")
print(f"1. Edit .env with your credentials")
print(f"2. Activate virtual environment: {get_activation_command()}")
print(f"3. Run Telegram bot: python telegram_bot.py")
print(f"4. Or run WhatsApp bot: python whatsapp_bot.py")
print("")
print("For detailed setup instructions, see SETUP.md")
if __name__ == "__main__":
main()