Advertisement
Blessing988

Untitled

Apr 27th, 2020
747
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 12.94 KB | None | 0 0
  1. print()
  2. print()
  3. print("_________________________________________________________________________________________________")
  4. print("\t\t\t\tWELCOME TO BLESSING'S LIBRARY",end="")
  5. print("\U0001f600","\U0001f600","\U0001f600")
  6. print("__________________________________________________________________________________________________")
  7. print()
  8. import re
  9. import random
  10. import datetime
  11.  
  12. today = datetime.datetime.now()
  13. year = today.year
  14. month = today.month + 2
  15. day = today.day
  16. deadline = datetime.datetime(year, month, day)
  17.  
  18.                       #key    #value
  19. StudentDetails = { } #name : [email address, AccountId, password ,books borrowed]
  20. AvailableBooks = {"Lord Of The Rings": 5,"The Colour Of Magic":12,"A Game Of Thrones":25, "The Fellowship Of The Ring":16,"Pride And Prejudice":10,
  21.                    "Fifty Shades Of Grey":4,"The Hating Game":6,"Vision White":14,"Gone With The Wind":2,"The Thorn Birds":7,
  22.                     "The Calculating Stars":3,"Semiosis":13,"Space Opera":7,"The Book Of M":11,"The Gone World":13,"Blackfish City":15,
  23.                     "Into Thin Air":8,"Into The World":12,"Treasure Island":5,"Journey To The Centre Of The Earth":6, "Heart of Darkness":4,
  24.                      "The Power Of Positive Thinking":3,"Think And Grow Rich":0, "You Are A Badass":17, "You Can Heal Your Life":16}
  25.  
  26.  
  27.  
  28. def CreateAccount():
  29.     global StudentDetails
  30.     while True:
  31.         print()
  32.         print("Enter your name: ")
  33.         print("Name should be valid and must contain numbers. eg: Blesing123 ")
  34.         username= input().strip()
  35.         print()
  36.         if username in StudentDetails:
  37.             print("Username already exists")
  38.             print()
  39.             continue
  40.         if re.search(r"^[A-Za-z]+[A-Za-z]{4}[0-9]", username):
  41.             break
  42.         else:
  43.             print("Invalid Username")
  44.             print()
  45.  
  46.     while True:
  47.         print("Enter Password")
  48.         password = input(" ").strip()
  49.         print()
  50.         if  8<=len(password)<=16:
  51.             if re.search(r"[A-Za-z]", password):
  52.                 if re.search(r"[0-9]", password):
  53.                     if re.search(r"[*#@!^#$%]", password):
  54.                         break
  55.                     else:
  56.                         print("Password must contain special characters or symbols")
  57.                         continue
  58.                 else:
  59.                     print("Password must contain numbers")
  60.                     continue
  61.             else:
  62.                 print("Password must contain letters")
  63.                 continue
  64.         else:
  65.             print("Password must be between 8 - 16 characters")
  66.             continue
  67.     while True:
  68.         print("Enter a valid email address: ")
  69.         email_address = input().strip()
  70.         print()
  71.  
  72.         if re.search("^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$", email_address):
  73.             break
  74.         else:
  75.             print("Invalid email address")
  76.             print()
  77.             continue
  78.  
  79.         if email_address in StudentDetails[username]:
  80.             print("Account already exist")
  81.             print()
  82.             continue
  83.  
  84.     AcountId = random.randint(10000, 99999)
  85.     StudentDetails[username] = [email_address, str(AcountId), password]
  86.     print("Account Created Succesfully")
  87.     print("____________________________________________")
  88.     print(f"Your Account Id is {AcountId}")
  89.     print("_____________________________________________")
  90.     print()
  91. def login():
  92.     global StudentDetails
  93.     while True:
  94.         print("Enter your name: ")
  95.         username = input().strip()
  96.         print()
  97.  
  98.         if re.search(r"^[A-Za-z]+[A-Za-z]{4}[0-9]", username) and username:
  99.             if username in StudentDetails:
  100.                 break
  101.             else:
  102.                 print("Invalid Username")
  103.                 continue
  104.         else:
  105.             print("Invalid Username")
  106.             continue
  107.  
  108.     while True:
  109.         print("Enter your email address: ")
  110.         email_address = input().strip()
  111.         print()
  112.         if email_address in StudentDetails[username]:
  113.             break
  114.         else:
  115.             print("Invalid email address")
  116.             continue
  117.  
  118.     while True:
  119.  
  120.         print("Enter your password: ")
  121.         password = input().strip()
  122.         if re.search(r"[A-Z0-9a-z*#@!^#$%]", password):
  123.             if password in StudentDetails[username]:
  124.                 break
  125.             else:
  126.                 print("Invalid password")
  127.                 continue
  128.         else:
  129.             print("Invalid password")
  130.             continue
  131.     print("Access Granted")
  132.     print()
  133. # What the library does
  134. def display_books( ):
  135.     global AvailableBooks
  136.     print()
  137.     print("\t\t\tAvailable Books: ")
  138.     for book in AvailableBooks:
  139.         print("___________________________________________________________")
  140.         print("\t\t\t", book)
  141.         print("____________________________________________________________")
  142. #What the user does
  143. def request_a_book():
  144.     global deadline
  145.     my_deadline = deadline.strftime("%A, %B %d, %Y")
  146.     global StudentDetails
  147.     global AvailableBooks
  148.     while True:
  149.         print("Enter the book you are requesting: ")
  150.         book = input( ).strip().title()
  151.         if re.search(r"^[A-Za-z]+[A-Za-z]",book ) and isinstance(book, str):
  152.             if book in AvailableBooks:
  153.                 break
  154.             else:
  155.                 print("Book not available")
  156.                 continue
  157.         else:
  158.             print("Invalid input")
  159.             continue
  160.     print("You are supposed to enter your login credentials to secure your identity")
  161.     while True:
  162.         print("What is your name: ")
  163.         name = input( )
  164.         print()
  165.  
  166.         if re.search(r"[A-Za-z][A-Za-z][^0-9]",name) and isinstance(name, str):
  167.             if name in StudentDetails:
  168.                 break
  169.             else:
  170.                 print("Invalid name")
  171.                 continue
  172.         else:
  173.             print("Invalid Input")
  174.     while True:
  175.         print("What is your accountId: ")
  176.         accountid = input()
  177.         print()
  178.  
  179.         if re.search(r"^[0-9]", accountid) and len(accountid)==5 :
  180.             if accountid in StudentDetails[name]:
  181.                 break
  182.             else:
  183.                 print("Invalid accountid")
  184.                 continue
  185.         else:
  186.             print("Invalid input")
  187.             continue
  188.     if book not in StudentDetails[name]:
  189.         StudentDetails[name].append(book)
  190.         AvailableBooks[book]-=1
  191.         print(f"You have borrowed {book} successfully")
  192.         print("____________________________________________________________")
  193.         print(f"The deadline for submission is on {my_deadline}")
  194.         print("_____________________________________________________________")
  195.         print()
  196.     elif book in StudentDetails[name]:
  197.         print(f"You have borrowed {book} already")
  198.     elif book not in AvailableBooks:
  199.         print(f"We dont have {book} in our Library. Management services will make Modifications")
  200.     elif book in AvailableBooks and AvailableBooks[book]==0:
  201.         print("{Book} out of stock. Check up later")
  202.  
  203.  
  204. def return_a_book():
  205.     global StudentDetails
  206.     global AvailableBooks
  207.     while True:
  208.         print("Which book are you returning: ")
  209.         book = input().strip().title()
  210.         if re.search(r"[A-za-z][^0-9]", book) and isinstance(book, str):
  211.             if book in AvailableBooks:
  212.                 break
  213.             else:
  214.                 continue
  215.         else:
  216.             continue
  217.     print("You are supposed to enter your login credentials to secure your identity")
  218.     while True:
  219.         print("What is your name: ")
  220.         name = input()
  221.         print()
  222.  
  223.         if re.search(r"[A-Za-z][A-Za-z][^0-9]", name) and isinstance(name, str):
  224.             if name in StudentDetails:
  225.                 break
  226.             else:
  227.                 print("Invalid name")
  228.                 continue
  229.         else:
  230.             print("Invalid Input")
  231.     while True:
  232.         print("What is your accountId: ")
  233.         accountid = input()
  234.         print()
  235.  
  236.         if re.search(r"^[0-9]", accountid) and len(accountid) == 5:
  237.             if accountid in StudentDetails[name]:
  238.                 break
  239.             else:
  240.                 print("Invalid accountid")
  241.                 continue
  242.         else:
  243.             print("Invalid input")
  244.             print()
  245.             continue
  246.     if book in StudentDetails[name]:
  247.         StudentDetails[name].remove(book)
  248.         AvailableBooks[book]+=1
  249.         print(f"You have successfully returned {book}")
  250.         print()
  251.     else:
  252.         print(f"{book} isn't inside your Archives!")
  253.  
  254.  
  255. while True:
  256.     try:
  257.         print("________________________________________________________________")
  258.         print("Press 1 to Login or access an existing account")
  259.         print("Press 2 to Create Account")
  260.         print("Press 3 to quit")
  261.         print("_________________________________________________________________")
  262.         print()
  263.         useroption = int(input())
  264.  
  265.         if isinstance(useroption, int):
  266.             if useroption ==1:
  267.                 login()
  268.  
  269.                 while True:
  270.                     print("__________________________________________________________________________________________")
  271.                     print("Press 1 to display available books")
  272.                     print("Press 2 to request a book")
  273.                     print("Press 3 to return a book")
  274.                     print("Press 4 to return to previous menu ")
  275.                     print("___________________________________________________________________________________________")
  276.                     print()
  277.                     useroption = int(input())
  278.                     if isinstance(useroption, int):
  279.                         if useroption == 1:
  280.                             display_books()
  281.                     else:
  282.                         print("Invalid input")
  283.                         continue
  284.                     if isinstance(useroption, int):
  285.                         if useroption == 2:
  286.                             request_a_book()
  287.                     else:
  288.                         print("Invalid input")
  289.                         continue
  290.                     if isinstance(useroption, int):
  291.                         if useroption == 3:
  292.                             return_a_book()
  293.                     else:
  294.                         print("Invalid input")
  295.                         continue
  296.                     if isinstance(useroption, int):
  297.                         if useroption == 4:
  298.                             break
  299.                     else:
  300.                         print("Invalid input")
  301.                         continue
  302.  
  303.  
  304.         else:
  305.             print("Invalid input")
  306.             contnue
  307.         if isinstance(useroption, int):
  308.             if useroption == 2:
  309.                 CreateAccount()
  310.  
  311.                 while True:
  312.                     print("_____________________________________________________________________")
  313.                     print("Press 1 to display available books")
  314.                     print("Press 2 to request a book")
  315.                     print("Press 3 to return a book")
  316.                     print("Press 4 to return to previous menu ")
  317.                     print("______________________________________________________________________")
  318.                     print()
  319.                     useroption = int(input())
  320.                     if isinstance(useroption, int):
  321.                         if useroption == 1:
  322.                             display_books()
  323.                     else:
  324.                         print("Invalid input")
  325.                         continue
  326.                     if isinstance(useroption, int):
  327.                         if useroption ==2:
  328.                             request_a_book()
  329.                     else:
  330.                         print("Invalid input")
  331.                         continue
  332.                     if isinstance(useroption, int):
  333.                         if useroption == 3:
  334.                             return_a_book()
  335.                     else:
  336.                         print("Invalid input")
  337.                         print()
  338.                         continue
  339.                     if isinstance(useroption, int):
  340.                         if useroption == 4:
  341.                             break
  342.                     else:
  343.                         print("Invalid input")
  344.                         print()
  345.                         continue
  346.             else:
  347.                 print("Invalid input")
  348.                 continue
  349.         else:
  350.             print("Invalid input")
  351.             continue
  352.  
  353.         if isinstance(useroption, int):
  354.             if useroption == 3:
  355.                 print()
  356.                 quit()
  357.             else:
  358.                 print("Invalid input")
  359.                 continue
  360.         else:
  361.             print("Invalid input")
  362.             continue
  363.     except ValueError:
  364.         print("Invalid input")
  365.         print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement