-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_setup.py
More file actions
163 lines (141 loc) Β· 4.59 KB
/
Copy pathtest_setup.py
File metadata and controls
163 lines (141 loc) Β· 4.59 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
"""
API Resource Availability Bot - Test Script
Run this to verify your setup before starting the bot
"""
import os
import sys
def check_python_version():
"""Check Python version"""
print("π Checking Python version...")
version = sys.version_info
if version.major >= 3 and version.minor >= 9:
print(f" β
Python {version.major}.{version.minor}.{version.micro}")
return True
else:
print(f" β Python {version.major}.{version.minor} (requires 3.9+)")
return False
def check_dependencies():
"""Check if all dependencies are installed"""
print("\nπ¦ Checking dependencies...")
required = [
'telegram',
'httpx',
'dns.resolver',
'aiosqlite',
'loguru',
'bs4',
'tabulate'
]
missing = []
for module in required:
try:
if module == 'dns.resolver':
__import__('dns.resolver')
elif module == 'bs4':
__import__('bs4')
else:
__import__(module)
print(f" β
{module}")
except ImportError:
print(f" β {module} (missing)")
missing.append(module)
if missing:
print("\n Install missing packages: pip install -r requirements.txt")
return False
return True
def check_env_file():
"""Check if .env file exists"""
print("\nβοΈ Checking configuration...")
if os.path.exists('.env'):
print(" β
.env file found")
# Check if token is set
with open('.env', 'r') as f:
content = f.read()
if 'TELEGRAM_BOT_TOKEN=' in content and 'your_bot_token_here' not in content:
print(" β
Bot token configured")
return True
else:
print(" β οΈ Bot token not configured")
print(" Edit .env and add your Telegram bot token")
return False
else:
print(" β .env file not found")
print(" Run: copy .env.example .env")
return False
def check_database():
"""Check if database can be initialized"""
print("\nπΎ Checking database...")
try:
import sqlite3
# Try to create a test database
conn = sqlite3.connect(':memory:')
conn.close()
print(" β
SQLite working")
return True
except Exception as e:
print(f" β Database error: {e}")
return False
def test_scanners():
"""Test if scanner modules can be imported"""
print("\nπ Checking scanner modules...")
try:
# Test imports without using the classes
from scanners import (
AvailabilityChecker,
DNSChecker,
PaywallChecker,
ProtocolChecker,
SecurityChecker,
)
# Mark as used
_ = (AvailabilityChecker, DNSChecker, ProtocolChecker,
PaywallChecker, SecurityChecker)
print(" β
All scanner modules found")
return True
except ImportError as e:
print(f" β Scanner import error: {e}")
return False
def test_bot_import():
"""Test if bot can be imported"""
print("\nπ€ Checking bot module...")
try:
import config # noqa: F401
from aggregator import ResultAggregator # noqa: F401
from database import Database # noqa: F401
# Mark as used to satisfy linter
_ = (config, ResultAggregator, Database)
print(" β
Bot modules working")
return True
except Exception as e:
print(f" β Bot import error: {e}")
return False
def main():
"""Run all checks"""
print("=" * 50)
print(" API Bot - Setup Verification")
print("=" * 50)
checks = [
check_python_version(),
check_dependencies(),
check_env_file(),
check_database(),
test_scanners(),
test_bot_import()
]
print("\n" + "=" * 50)
if all(checks):
print("β
All checks passed! Your bot is ready to run!")
print("\nStart the bot with:")
print(" python bot.py")
print(" or")
print(" run_bot.bat (Windows)")
print(" ./run_bot.sh (Linux/Mac)")
else:
print("β Some checks failed. Please fix the issues above.")
print("\nQuick fixes:")
print(" 1. Install dependencies: pip install -r requirements.txt")
print(" 2. Create .env file: copy .env.example .env")
print(" 3. Add bot token to .env file")
print("=" * 50)
if __name__ == '__main__':
main()