Tanish69420

Movie ticket booking

Aug 11th, 2022 (edited)
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 10.63 KB | Source Code | 0 0
  1. import math
  2. import random
  3. import mysql.connector as my
  4. mydb=my.connect(host='localhost',user='root',database='movie')
  5. cur=mydb.cursor()
  6. cur.execute("create database if not exists movie")
  7. cur.execute("use movie")
  8. choice=None
  9.  
  10.  
  11. while choice!=0:
  12.     print(" If EMPLOYEE press 1.")
  13.     print("If CUSTOMER press 2.")
  14.     print("To exit press 0")
  15.     choice=int(input("Enter choice: "))
  16.     if choice==0:
  17.         print("Thank you for visting our site. Have a nice day")
  18.         break
  19.     if choice==1:
  20.         password=int(input("Enter passcode: "))
  21.         if password!=12345:
  22.             print("!!!INCORRECT PASSWORD!!!")
  23.             print(" # SYSTEM SHUTTING DOWN # ")
  24.             choice=0
  25.  
  26.         while password==12345:
  27.             print("\n\n\n")
  28.             print("0. EXIT")
  29.             print("1. VIEW ALL SHOWS RUNNING AND SEATS BOOKED")
  30.             print("2. ADD NEW MOVIE")
  31.             print("3. ADD NEW SHOW")
  32.             print("4. DELETE SHOWS RUNNING")
  33.             print("5. VIEW BOOKINGS")
  34.             c=int(input("Enter choice: "))
  35.  
  36.             if c==5:
  37.                 query="SELECT*FROM customer"
  38.                 cur.execute(query)
  39.                 for j in cur.description:
  40.                     print(j[0].upper(),end="::")
  41.                 print()
  42.                 for i in cur:
  43.                     print(i)
  44.            
  45.  
  46.             if c==1:
  47.                 query="SELECT*FROM booking"
  48.                 cur.execute(query)
  49.                 for j in cur.description:
  50.                     print(j[0].upper(),end="::")
  51.                 print()
  52.                 for i in cur:
  53.                     print(i)
  54.            
  55.  
  56.             if c==2:
  57.                 print("\n")
  58.                 a=input(" Enter movie code ")
  59.                 b=input(" Enter movie name ")
  60.                 b=b.capitalize()
  61.                 c=input(" Enter hall no. ")
  62.                 c=c.capitalize()
  63.                 d=input(" Enter duration ")
  64.                
  65.                 f=input(" Enter language ")
  66.                 f=f.capitalize()
  67.                 query=("INSERT INTO schedule VALUES('{}','{}','{}','{}','{}')").format(a,c,b,d,f)
  68.                
  69.                 cur.execute(query)
  70.                 mydb.commit()
  71.                 print("Movie has been added")
  72.            
  73.             if c==3:
  74.                 a=input(" Enter movie code ")
  75.                 e=input("Enter start time in HH:MM format including ':' ")
  76.                 g=input("Enter date in DD/MM/YYYY format including '/' ")
  77.                 query1=("INSERT INTO booking VALUES('{}','{}','{}','10','1,2,3,4,5,6,7,8,9,10',NULL)").format(a,e,g)
  78.                 cur.execute(query1)
  79.                 mydb.commit()
  80.                 print("Show has been added")
  81.  
  82.  
  83.             if c==4:
  84.                 print("\n")
  85.                 a=input("Enter movie code ")
  86.                 e=input("Enter start time in HH:MM format including ':' ")
  87.                 g=input("Enter date in DD/MM/YYYY format including '/' ")
  88.                 query=("DELETE*from booking where movie_code='{}' and timing='{}' and show_date='{}'").format(a,e,g)
  89.                 cur.execute(query)
  90.                 query=("DELETE*from customer where movie_code='{}' and timing='{}' and show_date='{}'").format(a,e,g)
  91.                 cur.execute(query)
  92.                 mydb.commit()
  93.                 print("The show has been deleted")
  94.  
  95.  
  96.  
  97.  
  98.             if c==0:
  99.                 password=1
  100.                 print("\n\n")
  101.  
  102.  
  103.  
  104.     if choice==2:
  105.         while choice==2:
  106.             print("\n\n")
  107.             print("0. EXIT")
  108.             print("1. VIEW ALL MOVIES RUNNING")
  109.             print("2. BOOK SEATS")
  110.             print("3. SEARCH FOR YOUR BOOKING")
  111.             ch=int(input("Enter your choice "))
  112.  
  113.             if ch==2:
  114.                 query="SELECT*FROM schedule"
  115.                 cur.execute(query)
  116.                 for j in cur.description:
  117.                     print(j[0].upper(),end="::")
  118.                 print()
  119.                 for i in cur:
  120.                     print(i)
  121.                 print("\n\n")
  122.                 a=input("Enter the movie code from the above running shows ")
  123.                 query=("SELECT*FROM booking where movie_code='{}'").format(a)
  124.                 cur.execute(query)
  125.                 for j in cur.description:
  126.                     print(j[0].upper(),end="::")
  127.                 print()
  128.                 for i in cur:
  129.                     print(i)
  130.                 print("\n\n")
  131.                 x=input("Enter preffered show date in DD/MM/YYYY format including '/' ")
  132.                 y=input("Enter your preffered timing in 24 hours format(HH:MM) including ':' ")
  133.                 print("\n\n")
  134.                 print("1. To book a single seat")
  135.                 print("2. To book a multiple seats")
  136.                 b=int(input("Enter your choice "))
  137.                 l=[]
  138.                 query=("Select*from booking where movie_code='{}' and timing='{}' and show_date='{}'").format(a,y,x)
  139.                 cur.execute(query)
  140.                 for j in cur.description:
  141.                     print(j[0].upper(),end=" ")
  142.                 print()
  143.                 for i in cur:
  144.                     print(i,end=",")
  145.                 print()
  146.  
  147.                 if b==1:
  148.                     z=input("Enter your preferred seat no. ")
  149.                     query=("Select total_available,seat_no_available,seat_booked from booking where movie_code='{}' and timing='{}' and show_date='{}'").format(a,y,x)
  150.                     cur.execute(query)
  151.                     l1=[]
  152.                     l2=[]
  153.                     l3=[]
  154.                     for i in cur:
  155.                         l1=i[0]
  156.                         l2=i[1]
  157.                         l3=i[2]
  158.                     if l3==None:
  159.                         l3=z
  160.                         l3=l3.split(',')
  161.                     else:
  162.                         l3=l3.split(',')
  163.                         l3.append(z)
  164.                    
  165.                     l2=l2.split(",")
  166.                     l2.remove(z)
  167.                     l1=int(l1)-1
  168.                     l2=",".join(l2)
  169.                     l3=",".join(l3)
  170.                    
  171.                     query=("delete from booking where movie_code='{}' and timing='{}' and show_date='{}' ").format(a,y,x)
  172.                     query1=("insert into booking values('{}','{}','{}','{}','{}','{}')").format(a,y,x,l1,l2,l3)
  173.                     cur.execute(query)
  174.                     cur.execute(query1)
  175.  
  176.                     na=input("Enter your name ")
  177.                     em=input("Enter your email address ")
  178.                     mo=input("Enter your mobile number ")
  179.                     bo=random.randint(10000,99999)
  180.                     co='Rs.500'
  181.                     query=("insert into customer values('{}','{}','{}','{}','{}','{}','{}','{}','{}')").format(bo,na,em,mo,z,a,co,y,x)
  182.                     cur.execute(query)
  183.                     print("Your booking has been confirmed")
  184.                     print()
  185.                     print("Your booking id is",bo,"Please remember it for future purposes")
  186.                     print()
  187.                     print("The total cost is Rs.",co,"Pay it at the counter in the hall")
  188.                     print('\n')
  189.                     print("#General guidelines#\n* Theatre operators to promote advance booking and keep counters open the whole day.")
  190.                     print("\n* Frequent visits outside the hall during intermission/break should be avoided by customers.")
  191.                     print("\n* Use of the Aarogya Setu app advised in the guidelines.")
  192.                     print( "\n* Government has also advised in favour of cashless transactions")
  193.                     print( "\n* No spitting will be allowed outside or inside the premises of the cinema halls.")
  194.                     print("\n* The cinema halls are to function on only half of their seating capacity.")
  195.                     print("\n* One seat will be kept vacant between two persons in the cinema hall")
  196.                     print( "\n* Cinema halls will keep the temperature of the hall fixed at 23 degree celsius.")
  197.                     print("\n* Proper ventilation in the hall is mandated to avoid the spread of the infection.")
  198.                     print( "\n* In order to avoid crowding at the end of the show, shows will be timed in a staggered manner.")
  199.                     print( "\n* Adequate number of ticket counters to avoid crowding at the counters.")
  200.                     print("\n\n#Guidelines for Theatre Entry#")
  201.                     print("\n* Mandatory thermal screening at the entry gates.")
  202.                     print("\n* Only asymptomatic individuals will be let inside the theatre.")
  203.                     print("\n* All the people will have to keep their face mask on throughout the entire duration of the film.")
  204.                     print("THANK YOU FOR YOUR COOPERATION.")
  205.                     mydb.commit()
  206.  
  207.                
  208.  
  209.                 if b==2:
  210.                     z=input("Enter your preferred seat no. seperated by comma ")
  211.                     z=z.split(',')
  212.                     query=("Select total_available,seat_no_available,seat_booked from booking where movie_code='{}' and timing='{}' and show_date='{}'").format(a,y,x)
  213.                     cur.execute(query)
  214.                     t=[]
  215.                     for i in cur:
  216.                         l1=i[0]
  217.                         l2=i[1]
  218.                         l3=i[2]
  219.                     l2=l2.split(',')
  220.                     for i in z:
  221.                         if i in l2:
  222.                             t.append(i)
  223.                         else:
  224.                             print(i," seat not available")
  225.                     z=t
  226.                     t=[]       
  227.                     for i in l2:
  228.                         if i not in z:
  229.                             t.append(i)
  230.                     l2=t
  231.                    
  232.                     if l3==None:
  233.                         l3=z
  234.                     else:
  235.                         l3=l3.split(',')
  236.                         for i in z:
  237.                             l3.append(i)
  238.  
  239.                     l1=int(l1)-len(z)
  240.                     l2=",".join(l2)
  241.                     l3=",".join(l3)
  242.                     z=",".join(z)
  243.                     query=("delete from booking where movie_code='{}' and timing='{}' and show_date='{}' ").format(a,y,x)
  244.                     query1=("insert into booking values('{}','{}','{}','{}','{}','{}')").format(a,y,x,l1,l2,l3)
  245.                     cur.execute(query)
  246.                     cur.execute(query1)
  247.  
  248.                     na=input("Enter your name ")
  249.                     em=input("Enter your email address ")
  250.                     mo=input("Enter your mobile number ")
  251.                     bo=random.randint(10000,99999)
  252.                     co1=500*len(z)
  253.                     co='Rs.'+str(co1)
  254.                     query=("insert into customer values('{}','{}','{}','{}','{}','{}','{}','{}','{}')").format(bo,na,em,mo,z,a,co,y,x)
  255.                     cur.execute(query)
  256.                     print("Your booking has been confirmed")
  257.                     print()
  258.                     print("Your booking id is",bo,"Please remember it for future purposes")
  259.                     print()
  260.                     print("The total cost is Rs.",co,"Pay it at the counter in the hall")
  261.                     mydb.commit()
  262.                     print('\n')
  263.                     print("#General guidelines#\n* Theatre operators to promote advance booking and keep counters open the whole day.")
  264.                     print("\n* Frequent visits outside the hall during intermission/break should be avoided by customers.")
  265.                     print("\n* Use of the Aarogya Setu app advised in the guidelines.")
  266.                     print( "\n* Government has also advised in favour of cashless transactions")
  267.                     print( "\n* No spitting will be allowed outside or inside the premises of the cinema halls.")
  268.                     print("\n* The cinema halls are to function on only half of their seating capacity.")
  269.                     print("\n* One seat will be kept vacant between two persons in the cinema hall")
  270.                     print( "\n* Cinema halls will keep the temperature of the hall fixed at 23 degree celsius.")
  271.                     print("\n* Proper ventilation in the hall is mandated to avoid the spread of the infection.")
  272.                     print( "\n* In order to avoid crowding at the end of the show, shows will be timed in a staggered manner.")
  273.                     print( "\n* Adequate number of ticket counters to avoid crowding at the counters.")
  274.                     print("\n\n#Guidelines for Theatre Entry#")
  275.                     print("\n* Mandatory thermal screening at the entry gates.")
  276.                     print("\n* Only asymptomatic individuals will be let inside the theatre.")
  277.                     print("\n* All the people will have to keep their face mask on throughout the entire duration of the film.")
  278.                     print("THANK YOU FOR YOUR COOPERATION.")
  279.                    
  280.             if ch==0:
  281.                 print("\n\n")
  282.                 break
  283.            
  284.  
  285.             if ch==3:
  286.                 print("1. To search by booking id")
  287.                 print("2. To search by phone number")
  288.                 tr=int(input("Enter your choice "))
  289.                 if tr==1:
  290.                     a=int(input("Enter your booking id "))
  291.                     query=("select*from customer where booking_id='{}'").format(a)
  292.                     cur.execute(query)
  293.                     for j in cur.description:
  294.                         print(j[0].upper(),end="::")
  295.                     print()
  296.                     for i in cur:
  297.                         print(i)
  298.                    
  299.                 if tr==2:
  300.                     a=input("Enter your phone number ")
  301.                     query=("select*from customer where mob_no='{}'").format(a)
  302.                     cur.execute(query)
  303.                     for j in cur.description:
  304.                         print(j[0].upper(),end="::")
  305.                     print()
  306.                     for i in cur:
  307.                         print(i)
  308.  
  309.  
  310.  
  311.             if ch==1:
  312.                 query="SELECT*FROM schedule"
  313.                 cur.execute(query)
  314.                 for j in cur.description:
  315.                     print(j[0].upper(),end="::")
  316.                 print()
  317.                 for i in cur:
  318.                     print(i)
  319.  
  320.  
  321.            
Advertisement
Add Comment
Please, Sign In to add comment