Advertisement
Blessing988

Untitled

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