fork download
  1. #LOGIN MODULE
  2. import mysql.connector as ms
  3. db=ms.connect(host="localhost",user="root",password="suni13",database="library")
  4. cn=db.cursor()
  5. cn.execute("select * from login;")
  6. #variable rec is list having all rows and column of list
  7. t=0
  8. un=True
  9. up=False
  10. tuname= " "
  11. pword = " "
  12.  
  13. def login(uname):
  14. global un
  15. global up
  16. tuname=uname
  17. cn.execute("select * from login")
  18. rec=cn.fetchall()
  19. for i in range (0,len(rec)):
  20. while un == True:
  21. if tuname in rec[i][0]:
  22. print("Username found, enter correct password")
  23. up=True
  24. un = False
  25. break
  26. else:
  27. print("Username not found")
  28. print("Please try Again")
  29. tuname = input("Enter username")
  30. if up== True:
  31. break
  32. if up==True and un == False:
  33. pword = input("Enter password")
  34. for i in range (0,len(rec)):
  35. while up== True:
  36. if pword in rec[i][1]:
  37. print("User Found")
  38.  
  39.  
  40. #CHOICE MODULE
  41. def choice(uname):
  42. ch="" #making variable public for whole function
  43. if uname=='Admin':
  44. print("1 for Adding extra user")
  45. print("2 for removing user")
  46. print("3 for checking all book") #print all the books in main list
  47. print("4 for checking books borrowed")#print all the books in borrowed list along with name
  48. print("5 for list of users")
  49. print("6 for printing all available books")
  50. print("7 for adding extra book")
  51. print("8 for removing extra book")
  52. print("9 for updating passowrd for this current user")
  53. print("M for returning to main menu")
  54. print("O for logging out but not exiting the program")
  55. print("X for closing the program")
  56. ch=input("Please enter choice: ")
  57. else:
  58. print("A for borrowing book")
  59. print("B for returing back book")
  60. print("9 for updating passowrd for this current user")
  61. print("M for returning to main menu")
  62. print("O for logging out and exit")
  63. ch=input("Please enter choice: ")
  64. ch.upper()
  65. return ch
  66.  
  67.  
  68. #MANAGER MODULE
  69. import mysql.connector as ms
  70. from datetime import date
  71. db=ms.connect(host="localhost",user="root",password="suni13", database="library")
  72. cn=db.cursor() #login table
  73. mn=db.cursor() #library table
  74. def manager(ch,uname):
  75. tuname = uname
  76. if uname=="Admin" and ch=='1': #proper
  77. newname=input("Enter new user name to add")
  78. newpassword=input("Enter password for new username")
  79. cn.execute("insert into login values('0','0')".format(newname,newpassword))
  80. db.commit()
  81. print("Task completed")
  82. print()
  83. elif uname=="Admin" and ch=='2': #proper
  84. a = "Admin"
  85. cn.execute("select * from login where username!='0' ".format(a))
  86. rec=cn.fetchall()
  87. print("Username Passwords")
  88. for i in rec:
  89. print(i)
  90. deluser=input("Enter username to remove")
  91. cn.execute("delete from login where username='(".format(deluser))
  92. db.commit()
  93. print("Task completed")
  94. print()
  95. elif uname=="Admin" and ch=="3": #done
  96. header=["ID"," Borrowed"]
  97. print(Book_Name,",", Book_Type ,",", Borrower ,",",Date_Borrowed)
  98. mn.execute("select * from library;")
  99. rec=mn.fetchall()
  100. try:
  101. tt.print(list(rec),header,style=tt.styles.rounded,padding=(0,1),)
  102. except Exception as e:
  103. print("No Book Available")
  104.  
  105.  
  106. #MAINFRAME MODULE
  107. login(tuname)
  108. choice()
  109. manager()
  110. print("********** *LIBRARY MANAGEMENT PROGRAM****************")
  111. uname=input("Enter username")
  112. uname-uname.login(uname)
  113. ch-choice.choice(uname)
  114. print("Entered choice is",ch)
  115. while True:
  116. if ch== 'M' or ch== 'm':
  117. ch-choice.choice(uname)
  118. print("Entered choice is",ch)
  119. manager.manager(ch,uname)
  120. continue
  121. elif ch== '0':
  122. print("Logging out")
  123. print("Successfully logged out")
  124. print("Please login again to continue")
  125. uname = input("Enter username")
  126. uname=login.login(uname)
  127. print("Logged in as",uname)
  128. ch-choice.choice(uname)
  129. print("Entered choice is",ch)
  130. continue
  131. else:
  132. manager.manager(ch,uname)
  133. ch-choice.choice(uname)
  134. print("Entered choice is",ch)
  135. continue
  136.  
  137.  
  138.  
  139.  
  140.  
Success #stdin #stdout 0.02s 26076KB
stdin
Standard input is empty
stdout
#LOGIN MODULE
import mysql.connector as ms
db=ms.connect(host="localhost",user="root",password="suni13",database="library")
cn=db.cursor()
cn.execute("select * from login;")  
#variable rec is list having all rows and column of list
t=0
un=True 
up=False
tuname= " "
pword = " "

def login(uname):
    global un
    global up
    tuname=uname
    cn.execute("select * from login")
    rec=cn.fetchall()
    for i in range (0,len(rec)): 
        while un == True: 
            if tuname in rec[i][0]: 
                print("Username found, enter correct password")
                up=True 
                un = False 
                break 
            else: 
                print("Username not found") 
                print("Please try Again") 
                tuname = input("Enter username")
        if up== True:
            break
    if up==True and un == False:
        pword = input("Enter password") 
        for i in range (0,len(rec)): 
            while up== True: 
                if pword in rec[i][1]:
                    print("User Found")


#CHOICE MODULE
def choice(uname): 
    ch="" #making variable public for whole function 
    if uname=='Admin': 
        print("1 for Adding extra user") 
        print("2 for removing user") 
        print("3 for checking all book") #print all the books in main list 
        print("4 for checking books borrowed")#print all the books in borrowed list along with name 
        print("5 for list of users") 
        print("6 for printing all available books") 
        print("7 for adding extra book") 
        print("8 for removing extra book") 
        print("9 for updating passowrd for this current user") 
        print("M for returning to main menu") 
        print("O for logging out but not exiting the program") 
        print("X for closing the program") 
        ch=input("Please enter choice: ") 
    else: 
        print("A for borrowing book") 
        print("B for returing back book") 
        print("9 for updating passowrd for this current user") 
        print("M for returning to main menu") 
        print("O for logging out and exit") 
        ch=input("Please enter choice: ") 
    ch.upper()
    return ch


#MANAGER MODULE
import mysql.connector as ms 
from datetime import date 
db=ms.connect(host="localhost",user="root",password="suni13", database="library") 
cn=db.cursor() #login table 
mn=db.cursor() #library table 
def manager(ch,uname): 
    tuname = uname 
    if uname=="Admin" and ch=='1': #proper 
        newname=input("Enter new user name to add")
        newpassword=input("Enter password for new username")
        cn.execute("insert into login values('0','0')".format(newname,newpassword))
        db.commit() 
        print("Task completed") 
        print() 
    elif uname=="Admin" and ch=='2': #proper 
        a = "Admin" 
        cn.execute("select * from login where username!='0' ".format(a))
        rec=cn.fetchall() 
        print("Username        Passwords")
        for i in rec: 
            print(i) 
            deluser=input("Enter username to remove") 
            cn.execute("delete from login where username='(".format(deluser))
            db.commit() 
            print("Task completed") 
            print() 
    elif uname=="Admin" and ch=="3": #done 
        header=["ID"," Borrowed"]
        print(Book_Name,",", Book_Type ,",", Borrower ,",",Date_Borrowed)
        mn.execute("select * from library;") 
        rec=mn.fetchall() 
        try:
            tt.print(list(rec),header,style=tt.styles.rounded,padding=(0,1),) 
        except Exception as e: 
            print("No Book Available")


#MAINFRAME MODULE
login(tuname)
choice()
manager()
print("********** *LIBRARY MANAGEMENT PROGRAM****************")
uname=input("Enter username") 
uname-uname.login(uname) 
ch-choice.choice(uname) 
print("Entered choice is",ch) 
while True: 
    if ch== 'M' or ch== 'm': 
        ch-choice.choice(uname) 
        print("Entered choice is",ch) 
        manager.manager(ch,uname) 
        continue 
    elif ch== '0': 
        print("Logging out") 
        print("Successfully logged out") 
        print("Please login again to continue") 
        uname = input("Enter username") 
        uname=login.login(uname) 
        print("Logged in as",uname) 
        ch-choice.choice(uname) 
        print("Entered choice is",ch) 
        continue 
    else: 
        manager.manager(ch,uname) 
        ch-choice.choice(uname) 
        print("Entered choice is",ch) 
        continue