import sqlite3a
import sqlite3a
# Connect to SQLite database (it will create a new file if it doesn't exist)
conn = sqlite3.connect('parking_lot.db')
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS parking_slots (
slot_id INTEGER PRIMARY KEY AUTOINCREMENT,
status TEXT DEFAULT 'available'
)
''')
cursor.execute('''
CREATE TABLE IF NOT EXISTS parking_records (
record_id INTEGER PRIMARY KEY AUTOINCREMENT,
vehicle_id INTEGER,
slot_id INTEGER,
entry_time TEXT,
exit_time TEXT,
FOREIGN KEY(vehicle_id) REFERENCES vehicles(vehicle_id),
FOREIGN KEY(slot_id) REFERENCES parking_slots(slot_id)
)
''')
conn.commit()
if vehicle
vehicle_id = vehicle[0]
cursor.execute('''
SELECT slot_id FROM parking_slots WHERE status = 'available' LIMIT 1
''')
slot = cursor.fetchone()
if slot
slot_id = slot[0]
entry_time = datetime.now().strftime('%Y-%m-%d %H%M%S')
cursor.execute('''
INSERT INTO parking_records (vehicle_id, slot_id, entry_time)
VALUES (, , )
''', (vehicle_id, slot_id, entry_time))
if vehicle
vehicle_id = vehicle[0]
cursor.execute('''
SELECT FROM parking_records WHERE vehicle_id = AND exit_time IS NULL
ORDER BY entry_time DESC LIMIT 1
''', (vehicle_id,))
record = cursor.fetchone()
if record
record_id = record[0]
exit_time = datetime.now().strftime('%Y-%m-%d %H%M%S')
cursor.execute('''
UPDATE parking_records SET exit_time = WHERE record_id =
''', (exit_time, record_id))
# Example usage
def main()
create_tables() # Set up the database and tables
# Vehicle entry
vehicle_entry(ABC123) # Vehicle ABC123 enters the parking lot
# Vehicle exit
vehicle_exit(ABC123) # Vehicle ABC123 exits the parking lot
if __name__ == __main__
main()
conn.close()