import random as ran
import mysql.connector as msc
pwd='edward'
db='traffic'
con=msc.connect(host='localhost',user='root',passwd=pwd,database=db)
cur=con.cursor()
"""print(""Downlaod SQL setup?
[1]. Yes
[2]. No
"")
op=int(input("Enter the operation number = "))
if op==1:
cur.execute("create table vehicleno(Vehicle_no varchar(12) primary key,Owner_name varchar(40),regd_authority varchar(30),fuel_type varchar(20), Emission Norm int);")
cur.execute("insert into vehicleno values('DL12CM6390','Rakesh Kumar','Janak Puri','Petrol',5);")
con.commit()
cur.execute("insert into vehicleno values('DL15SN6289','Saksham Singh','Bali nagar','Diesel',6);")
con.commit()
cur.execute("insert into vehicleno values('DL9SCA7383','krish sharma','Uttam nagar','Petrol',6);")
con.commit()
cur.execute("insert into vehicleno values('DL18CQ7392','Satish Bajaj','Tilak nagar','Petrol',6);")
con.commit()
cur.execute("insert into vehicleno values('DL5SAM2345','Mahinder Tanwar','Rajouri Garden','Diesel',5);")
con.commit()
cur.execute("create table roadfine(sno int primary key,offence_name varchar(100),MVA varchar(40),Offence_1 int,Offence_2 int);")
cur.execute("insert into roadfine values(1,'Obstrcutive Driving','125/177 MVA',500,1500);")
con.commit()
cur.execute("insert into roadfine values(2,'Triple riding on two wheeler','194C MVA',1000,1000);")
con.commit()
cur.execute("insert into roadfine values(3,'Driving in NMV lanes','115/194(1) MVA',20000,20000);")
con.commit()
cur.execute("create table challan(sno int primary key,vehicle_no varchar(12),offence_MVA varchar(40),repetition int,amount int);")
cur.execute("insert into challan values(1,'DL9SCA6180','125/177 MVA',1,500);")
con.commit()
cur.execute("insert into challan values(2,'DL9SCA6180','194C MVA',1,1000);")"""
def traffic_rulesfunc():
traffic_rules = {
"1. Regulatory Rules": [
"1. Always stop at a red light.",
"2. Obey speed limits according to road type (e.g., 50 km/h in urban areas, 120 km/h on highways).",
"3. Stop completely at all stop signs before proceeding.",
"4. Yield the right of way to vehicles and pedestrians as indicated by signs.",
"5. Do not drive in lanes marked for buses, taxis, or emergency vehicles.",
"6. Always drive on the correct side of the road according to local laws (e.g., right-hand or left-hand driving).",
"7. Do not park in no-parking zones, including in front of fire hydrants or driveways.",
"8. Use turn signals when changing lanes or making turns.",
"9. Do not block intersections, even if the traffic light is green.",
"10. Follow posted restrictions on vehicle weight, height, or width when crossing bridges or tunnels."
],
"2. Warning or Cautionary Rules": [
"1. Slow down when approaching a pedestrian crossing, and stop if pedestrians are present.",
"2. Reduce speed in areas marked with “School Zone” during specific hours.",
"3. Be cautious when driving on roads with 'Slippery When Wet' signs, especially during rain.",
"4. Slow down before sharp turns marked with curve signs.",
"5. Pay attention to deer or wildlife crossing signs in rural areas.",
"6. Watch for roadwork or construction signs and follow posted speed limits in these zones.",
"7. Be cautious when approaching areas with falling rocks or avalanche warnings.",
"8. Drive slowly over speed bumps or humps marked with cautionary signs.",
"9. Observe reduced speed limits on narrow bridges or roads marked as hazardous.",
"10. Be alert for trains when you see railroad crossing warnings, and stop when required."
],
"3. Informational or Guide Rules": [
"1. Follow exit signs to leave highways or motorways safely.",
"2. Pay attention to road number signs to stay on the correct route.",
"3. Follow signs that indicate gas stations or rest areas.",
"4. Observe signs indicating the distance to the next town or city.",
"5. Use airport or bus station signs to find the correct entrances.",
"6. Pay attention to highway markers showing directions to tourist attractions or landmarks.",
"7. Follow hospital or emergency room signs to navigate safely in an emergency.",
"8. Observe hotel or accommodation information signs for nearby lodging.",
"9. Use parking signs to identify public parking lots or garages.",
"10. Follow signs directing you to scenic viewpoints or rest stops along tourist routes."
],
"4. Road Markings": [
"1. Stay within your lane, and do not cross solid white or yellow lines.",
"2. Use crosswalks when walking or stop for pedestrians at marked pedestrian crossings.",
"3. Stop at the stop line at intersections controlled by traffic lights or signs.",
"4. Do not park in areas marked with diagonal lines or hatching.",
"5. Follow arrows painted on the road indicating turn-only lanes.",
"6. Observe double yellow lines, which typically indicate no passing or overtaking zones.",
"7. Park only in spaces marked for parking, and avoid loading zones or handicapped spots without a permit.",
"8. Yield to traffic at intersections marked with yield triangles.",
"9. Follow bike lane markings and avoid driving in them.",
"10. Be aware of broken white lines indicating that lane changes are permitted, but with caution."
],
"5. Priority Rules": [
"1. Yield to pedestrians at marked or unmarked crosswalks.",
"2. Give way to traffic coming from the right at uncontrolled intersections (where applicable).",
"3. Yield to vehicles already in a roundabout.",
"4. Give priority to emergency vehicles (ambulances, police, fire trucks) with flashing lights or sirens.",
"5. Yield to buses re-entering traffic in some urban areas (where local laws apply).",
"6. Allow vehicles to merge into traffic when entering highways or motorways.",
"7. Yield to cyclists in bike lanes or when turning across a bicycle path.",
"8. Give priority to vehicles going straight or turning right at traffic signals.",
"9. Yield to trains at railroad crossings.",
"10. Give priority to school buses when they are stopped for children to board or disembark."
],
"6. Miscellaneous Rules": [
"1. All passengers must wear seat belts while the vehicle is in motion.",
"2. Do not use a handheld mobile phone while driving unless using a hands-free device.",
"3. Motorcycle riders and passengers must wear helmets at all times.",
"4. Do not drive under the influence of alcohol or drugs.",
"5. Keep headlights on during low visibility conditions such as fog, rain, or nighttime.",
"6. Use child car seats for children below a certain age or height (as required by local law).",
"7. Always stop for school buses with flashing red lights indicating that children are boarding or disembarking.",
"8. Do not litter or throw objects from the vehicle while driving.",
"9. Keep the vehicle in good condition, including proper tire pressure and functioning brakes.",
"10. Follow local regulations regarding vehicle modifications and accessories."
]}
while True:
for key in traffic_rules:
print(key)
choice = input("\nEnter the number of your chosen category (1-6), or 'q' to quit: ")
if choice.lower() == 'q':
break
elif choice in ['1', '2', '3', '4', '5','6']:
print ("----"*30)
print("\n".join(traffic_rules[list(traffic_rules.keys())[int(choice) - 1]]))
print("----"*30)
else:
print("Invalid choice. Please try again.")
def road_signs():
categories = {
"1. Regulatory Signs": ["Stop", "Yield", "Speed Limit", "No Entry", "No Parking", "No U-Turn", "One Way", "Pedestrian Crossing", "Turn Left Only", "No Overtaking"],
"2. Warning Signs": ["Sharp Turn Ahead", "Pedestrian Crossing", "School Zone", "Slippery Road", "Animal Crossing", "Railroad Crossing", "Falling Rocks", "Road Narrows", "Speed Bumps", "Traffic Signal Ahead"],
"3. Guide Signs": ["Highway Exit", "Route Marker", "Distance Sign", "Rest Area", "Hospital", "Gas Station", "City Name", "Airport", "Tourist Attraction", "Parking Information"],
"4. Informational Signs": ["Hospital", "Gas Station", "Restaurant", "Rest Area", "Hotel/Motel", "Telephone", "Bus Stop", "Emergency Shelter", "Police Station", "Tourist Information"],
"5. Temporary Traffic Control Signs": ["Detour", "Road Work Ahead", "Lane Closed", "Flagman Ahead", "Temporary Traffic Light", "Men at Work", "Uneven Road", "Construction Ahead", "End of Road Work", "Speed Limit in Construction Zone"]
}
while True:
for key in categories:
print(key)
choice = input("\nEnter the number of your chosen category (1-5), or 'q' to quit: ")
if choice.lower() == 'q':
break
elif choice in ['1', '2', '3', '4', '5']:
print ("────"*15)
print("\n".join(categories[list(categories.keys())[int(choice) - 1]]))
print("────"*15)
else:
print("Invalid choice. Please try again.")
def capmaker():
a='abcdefghijklmnopqrstuvwxyz'
A='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
c='@#_'
ccap=''
for i in range(0,6):
cs=ran.randint(0,2)
if cs==0:
xa=ran.randint(0,25)
ccap+=a[xa]
elif cs==1:
xA=ran.randint(0,25)
ccap+=A[xA]
elif cs==2:
xc=ran.randint(0,2)
ccap+=c[xc]
ccap+=' '*ran.randint(0,3)
return ccap
while True:
print("""
┌──────────────────────────────────────────────────────────────────────┐
│ │
│ ROAD SAFETY │
│ │
│ [1]. E-Challan [2]. Safety Rules [3]. Road Signs │
│ │
│ [4]. EXIT │
└──────────────────────────────────────────────────────────────────────┘""")
o=int(input("\nEnter the operation number = "))
if o==4:
break
elif o==1:
while True:
print("""
┌───────────────────────────────────────────┐
│ │
│ E-CHALLAN │
│ │
│ [1]. CIVILIAN LOGIN │
│ [2]. OFFICER LOGIN │
│ [3]. BACK │
│ │
└───────────────────────────────────────────┘""")
op=int(input("Enter the operation number = "))
if op==3:
break
elif op==1:
vfy1=0
vfy2=0
while True:
if vfy1!=1:
vn=input("Enter Vehicle Number = ")
cur.execute("select vehicle_no from vehicleno;")
vhn=cur.fetchall()
for i in vhn:
if i[0].upper()==vn.upper():
vfy1=1
if vfy2!=1:
x=capmaker()
print(x)
xs=''
for i in x:
if i!=' ':
xs+=i
cp=input("Enter the capcha = ")
if cp==xs:
vfy2=1
if vfy1==1 and vfy2==1:
break
elif vfy1!=1 and vfy2!=1:
print("INVALID CAPCHA AND USERNAME")
elif vfy1!=1:
print("INVALID VEHICLE NO")
elif vfy2!=1:
print("INVALID CAPCHA")
cur.execute("select * from challan where vehicle_no=%s;",(vn,))
off=cur.fetchall()
cur.execute("select * from vehicleno where vehicle_no=%s;",(vn,))
det=cur.fetchall()
of=[]
sz=[]
mz=[]
for i in off:
mva=i[2]
cur.execute('select offence_name from roadfine where mva=%s;',(mva,))
ofn=cur.fetchall()
of.append([mva,ofn[0][0]])
sz.append(len(ofn[0][0]))
mz.append(len(mva))
sx=max(sz)
mx=max(mz)
print("""
┌──────────────────────────────────────────────────────────────────────┐
│ │
│ E-CHALLAN │
│ │
│ Owner Name: {name}{sp1}│
│ Vehicle No.: {vhno}{sp2}│
│ Regd. Authority: {regd}{sp3}│
│ │
│ Offence name{sp4}Offence Act{sp5}Amount{sp6}│""".format(name=det[0][1],sp1=' '*(71-16-len(det[0][1])),vhno=det[0][0],sp2=' '*(71-17-len(det[0][0])),regd=det[0][2],sp3=' '*(71-21-len(det[0][2])),sp4=' '*(4+sx-11),sp5=' '*(4+mx-10),sp6=' '*(72-8-sx-3-mx-10)))
for i in range(0,len(off)):
print('│ '+of[i][1]+' '*(1+4+sx-len(of[i][1]))+of[i][0]+' '*(1+4+mx-len(of[i][0]))+str(off[i][4])+' '*(70-3-8-sx-mx-2-len(str(off[i][4])))+'│')
print('└──────────────────────────────────────────────────────────────────────┘')
num=9999
num=int(input("Enter any number to exit = "))
if num!=9999:
break
elif op==2:
while True:
cvfy1=cvfy2=0
emp=int(input("Enter the employee code = "))
pwd=input("Enter the password = ")
cur.execute('select * from ofc_details;')
dt=cur.fetchall()
for i in dt:
if int(i[0])==emp:
cvfy1=1
if i[1]==pwd:
cvfy2=1
if cvfy1!=1:
print("Username not registered")
if cvfy2!=1:
print("Password Invalid")
if cvfy1==cvfy2==1:
break
cur.execute("select * from roadfine")
rdf=cur.fetchall()
print()
for i in rdf:
print(i[0],i[1],i[2],i[3],i[4])
while True:
fn=eval(input("Enter tuple of sno = "))
ch=int(input("Enter 1 to confirm else 0 = "))
if ch==1:
break
elif ch==0:
None
else:
print("Invalid input entered")
while True:
tvfy1=0
vn=input("Enter Vehicle Number = ")
cur.execute("select vehicle_no from vehicleno;")
vhn=cur.fetchall()
for i in vhn:
if i[0].upper()==vn.upper():
tvfy1=1
if tvfy1==1:
break
else:
print("INVALID VEHICLE NO.")
cur.execute("select * from roadfine;")
rdf=cur.fetchall()
rf=[]
for i in rdf:
if i[0] in fn:
mvt=i[2]
cur.execute("select * from challan;")
dt=cur.fetchall()
dt=len(dt)
cur.execute("select * from challan where offence_mva=%s and vehicle_no=%s",(mvt,vn))
rep=cur.fetchall()
rep=len(rep)
if rep==0:
fin=i[4]
else:
fin=i[3]
cur.execute("insert into challan values(%s,%s,%s,%s,%s);",(dt+1,vn,mvt,rep+1,fin))
con.commit()
print("Challan successfully Created")
elif o==2:
traffic_rulesfunc()
elif o==3:
road_signs()
else:
print("INVALID OPERATION ENTERED")
con.close()