-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheck_hotels.py
More file actions
48 lines (38 loc) · 1.31 KB
/
check_hotels.py
File metadata and controls
48 lines (38 loc) · 1.31 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
#!/usr/bin/env python3
"""
Script to check hotels in database
"""
import sqlite3
import sys
import os
def check_hotels():
"""Check hotels in database"""
db_path = "Tabble.db"
if not os.path.exists(db_path):
print(f"Database {db_path} not found!")
return False
try:
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
# Check if hotels table exists
cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='hotels'")
table_exists = cursor.fetchone()
if not table_exists:
print("Hotels table does not exist!")
return False
# Get all hotels
cursor.execute("SELECT id, hotel_name, password, phone_number FROM hotels")
hotels = cursor.fetchall()
print(f"Found {len(hotels)} hotels in database:")
for hotel_id, hotel_name, password, phone_number in hotels:
print(f" ID: {hotel_id}, Name: {hotel_name}, Password: {password}, Phone: {phone_number}")
return True
except Exception as e:
print(f"Error checking hotels: {e}")
return False
finally:
if conn:
conn.close()
if __name__ == "__main__":
success = check_hotels()
sys.exit(0 if success else 1)