Pymysql q-3 Dhwanil Pits

import pymysql
import warnings
import time

print ("Establishing Connection...")
conn = pymysql.connect(host = 'localhost', user = 'root', passwd = 'root', db = 'Hollywood')
cursor = conn.cursor()
print ("Connection Established..!")
print ("")
print ("")

def menu():
    global a
    print ("*"*40)
    print ("Welcome To Movies Database..!")
    time.sleep(2)
    a = int(input('''Is Table Already Created..??
1. Yes
2. No:  '''))
    print ("")
    print ("")

   
def menu2():
    global b
    time.sleep(2)
    b = int(input('''Select Operation From The Following...
1. Display And Save Everything
2. Add A Record
3. Update A Record
4. Delete A Record
5. Select A Specific Query and Save It
6. Quit:  '''))
    print ("")
    print ("")

   
def DeleteTable():
    print ("Deleting the table...")
    time.sleep(2)
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        cursor.execute("drop table if exists Movies")
    print ("Table Deleted")
    print ("")
    print ("")

def CreateTable():
    print ("Creating Table...")
    time.sleep(2)
    Comm = "create table Movies(srno int(2) primary key, Title varchar(50), Writer varchar(40), Year int(4), Actors varchar(200))"
    cursor.execute(Comm)
    print ("Table Created : Movies")
    print ("Entering Values...")
    time.sleep(3)
    Comm = "insert into Movies(srno, Title, Writer, Year, Actors) values(1, 'Fight Club', 'Chuck Palahniuk', 1999, '[Brad Pitt, Edward Norton]')"
    cursor.execute(Comm)
    Comm = "insert into Movies(srno, Title, Writer, Year, Actors) values(2, 'Pulp Fiction', 'Quentin Tarantino', 1999, '[John Travolta, Uma Thurman]')"
    cursor.execute(Comm)
    Comm = "insert into Movies(srno, Title, Writer, Year, Actors) values(3, 'Inglorious Basterds', 'Quentin Tarantino', 2009, '[Brad Pitt, Diane Kruger, Eli Roth]')"
    cursor.execute(Comm)
    conn.commit()
    print ("Values Inserted..!!")
    print ("")
    print ("")

def ShowSave():
    ofile = open("Movies.txt", "a")
    print ("Retrieving Records...")
    time.sleep(2)
    Comm = "select * from Movies"
    cursor.execute(Comm)
    row = cursor.fetchone()
    print ("Records Retrieved! They are as follows...")
    ofile.write("--------------------\n")
    ofile.write("New Run\n")
    while row is not None:
        ofile.write(str(row)+"\n")
        print (row)
        row = cursor.fetchone()
    ofile.write("\n\n")
    print ("")
    print ("")

def Update():
    print ("Loading...")
    time.sleep(1)
    x = input('''Input The Field You Want To Change
[Srno / Title / Writer / Year / Actors]:  ''')
    y = input("Enter The Record Srno You Want To Change: ")
    z = input("Enter Your Data: ")
    print ("Updating...")
    time.sleep(1)
    str1 = "update movies set "+str(x)+" = '"+str(z)+"' where srno = "+str(y)
    Comm = str1
    cursor.execute(Comm)
    conn.commit()
    print ("Record Updated..!")
    print ("")
    print ("")

def DelRec():
    print ("Loading...")
    time.sleep(1)
    x = input("Enter The Record Srno You Want To Delete: ")
    print ("Deleting...")
    time.sleep(1)
    str1 = "delete from movies where srno = "+str(x)
    Comm = str1
    cursor.execute(Comm)
    conn.commit()
    print ("Record Deleted..!")
    print ("")
    print ("")

def Select():
    ofile = open("Search.txt", "a")
    print ("Loading...")
    time.sleep(1)
    w = input('''Enter Fields You Want To See
[Srno / Title / Writer / Year / Actors] (Seperate Fields By Comma (,)):  ''')
    x = input('''Enter Which Field You Want To Search From
[Srno / Title / Writer / Year / Actors]:  ''')
    y = input("Enter Data You Want To Search: ")
    print ("Searching...")
    time.sleep(1)
    str1 = "select "+str(w)+" from movies where "+str(x)+" = '"+str(y)+"'"
    Comm = str1
    cursor.execute(Comm)
    print ("Search Done, Now Displaying Records...")
    time.sleep(2)
    row = cursor.fetchone()
    ofile.write("---------------------\n")
    ofile.write("New Search\n")
    while row is not None:
        ofile.write(str(row)+"\n")
        print (row)
        row = cursor.fetchone()
    ofile.write("\n\n")
    print ("")
    print ("")

def Add():
    v = input("Enter Srno: ")
    x = input("Enter Title: ")
    y = input("Enter Writer: ")
    z = input("Enter Year: ")
    w = input("Enter Actors (Seperate By Comma(,)): ")
    print ("Entering Data...")
    time.sleep(2)
    str1 = "insert into Movies(srno, Title, Writer, Year, Actors) values("+str(v)+", '"+str(x)+"', '"+str(y)+"', "+str(z)+", '["+str(w)+"]')"
    Comm = str1
    cursor.execute(Comm)
    conn.commit()
    print ("Data Successfully Entered..!")
    print ("")
    print ("")
   
n=1
menu()
if a == 1:
    pass
elif a == 2:
    DeleteTable()
    CreateTable()
while n>0:
    menu2()
    if b == 1:
        ShowSave()
    elif b == 2:
        Add()
    elif b == 3:
        Update()
    elif b == 4:
        DelRec()
    elif b == 5:
        Select()
    elif b == 6:
        n=0
        print ("Thank You So Much For Using Our Program..!")
    else:
        print ("Please Enter A Valid Option")
        print ("")
        print ("")

Comments