-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfastag.py
More file actions
47 lines (42 loc) · 1.27 KB
/
fastag.py
File metadata and controls
47 lines (42 loc) · 1.27 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
import sqlite3
# Connect to the database
conn = sqlite3.connect("fastag.db")
cursor = conn.cursor()
# Create the table for storing Fastag account information
cursor.execute("""
CREATE TABLE IF NOT EXISTS fastag (
vehicle_number TEXT PRIMARY KEY,
balance REAL NOT NULL
)
""")
conn.commit()
# Recharge a Fastag account
def recharge(vehicle_number, amount):
cursor.execute("""
UPDATE fastag
SET balance = balance + ?
WHERE vehicle_number = ?
""", (amount, vehicle_number))
conn.commit()
# Deduct a toll charge from a Fastag account
def deduct_toll_charge(vehicle_number, toll_charge):
cursor.execute("""
UPDATE fastag
SET balance = balance - ?
WHERE vehicle_number = ? AND balance >= ?
""", (toll_charge, vehicle_number, toll_charge))
if cursor.rowcount == 0:
print("Insufficient balance in Fastag account for vehicle number {}".format(vehicle_number))
conn.commit()
# Get the balance for a Fastag account
def get_balance(vehicle_number):
cursor.execute("""
SELECT balance
FROM fastag
WHERE vehicle_number = ?
""", (vehicle_number,))
result = cursor.fetchone()
if result is None:
print("No Fastag account found for vehicle number {}".format(vehicle_number))
return None
return result[0]