Advertisement
Blessing988

Untitled

Apr 27th, 2020
452
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 12.67 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.  
  78.         if email_address in StudentDetails[username]:
  79.             print("Account already exist")
  80.             print()
  81.             continue
  82.  
  83.     AcountId = random.randint(10000, 99999)
  84.     StudentDetails[username] = [email_address, str(AcountId), password]
  85.     print("Account Created Succesfully")
  86.     print("____________________________________________")
  87.     print(f"Your Account Id is {AcountId}")
  88.     print("_____________________________________________")
  89.     print()
  90. def login():
  91.     global StudentDetails
  92.     while True:
  93.         print("Enter your name: ")
  94.         username = input().strip()
  95.         print()
  96.  
  97.         if re.search(r"^[A-Za-z]+[A-Za-z]{4}[0-9]", username) and username:
  98.             if username in StudentDetails:
  99.                 break
  100.             else:
  101.                 print("Invalid Username")
  102.                 continue
  103.         else:
  104.             print("Invalid Username")
  105.             continue
  106.  
  107.     while True:
  108.         print("Enter your email address: ")
  109.         email_address = input().strip()
  110.         print()
  111.         if email_address in StudentDetails[username]:
  112.             break
  113.         else:
  114.             print("Invalid email address")
  115.             continue
  116.  
  117.     while True:
  118.  
  119.         print("Enter your password: ")
  120.         password = input().strip()
  121.         if re.search(r"[A-Z0-9a-z*#@!^#$%]", password):
  122.             if password in StudentDetails[username]:
  123.                 break
  124.             else:
  125.                 print("Invalid password")
  126.                 continue
  127.         else:
  128.             print("Invalid password")
  129.             continue
  130.     print("Access Granted")
  131.     print()
  132. # What the library does
  133. def display_books( ):
  134.     global AvailableBooks
  135.     print()
  136.     print("\t\t\tAvailable Books: ")
  137.     for book in AvailableBooks:
  138.         print("___________________________________________________________")
  139.         print("\t\t\t", book)
  140.         print("____________________________________________________________")
  141. #What the user does
  142. def request_a_book():
  143.     global deadline
  144.     my_deadline = deadline.strftime("%A, %B %d, %Y")
  145.     global StudentDetails
  146.     global AvailableBooks
  147.     while True:
  148.         print("Enter the book you are requesting: ")
  149.         book = input( ).strip().title()
  150.         if re.search(r"^[A-Za-z]+[A-Za-z]",book ) and isinstance(book, str):
  151.             if book in AvailableBooks:
  152.                 break
  153.             else:
  154.                 print("Book not available")
  155.                 continue
  156.         else:
  157.             print("Invalid input")
  158.             continue
  159.     print("You are supposed to enter your login credentials to secure your identity")
  160.     while True:
  161.         print("What is your name: ")
  162.         name = input( )
  163.         print()
  164.  
  165.         if re.search(r"[A-Za-z][A-Za-z][^0-9]",name) and isinstance(name, str):
  166.             if name in StudentDetails:
  167.                 break
  168.             else:
  169.                 print("Invalid name")
  170.                 continue
  171.         else:
  172.             print("Invalid Input")
  173.     while True:
  174.         print("What is your accountId: ")
  175.         accountid = input()
  176.         print()
  177.  
  178.         if re.search(r"^[0-9]", accountid) and len(accountid)==5 :
  179.             if accountid in StudentDetails[name]:
  180.                 break
  181.             else:
  182.                 print("Invalid accountid")
  183.                 continue
  184.         else:
  185.             print("Invalid input")
  186.             continue
  187.     if book not in StudentDetails[name]:
  188.         StudentDetails[name].append(book)
  189.         AvailableBooks[book]-=1
  190.         print(f"You have borrowed {book} successfully")
  191.         print("____________________________________________________________")
  192.         print(f"The deadline for submission is on {my_deadline}")
  193.         print("_____________________________________________________________")
  194.         print()
  195.     elif book in StudentDetails[name]:
  196.         print(f"You have borrowed {book} already")
  197.     elif book not in AvailableBooks:
  198.         print(f"We dont have {book} in our Library. Management services will make Modifications")
  199.     elif book in AvailableBooks and AvailableBooks[book]==0:
  200.         print("{Book} out of stock. Check up later")
  201.  
  202.  
  203. def return_a_book():
  204.     global StudentDetails
  205.     global AvailableBooks
  206.     while True:
  207.         print("Which book are you returning: ")
  208.         book = input().strip().title()
  209.         if re.search(r"[A-za-z][^0-9]", book) and isinstance(book, str):
  210.             if book in AvailableBooks:
  211.                 break
  212.             else:
  213.                 continue
  214.         else:
  215.             continue
  216.     print("You are supposed to enter your login credentials to secure your identity")
  217.     while True:
  218.         print("What is your name: ")
  219.         name = input()
  220.         print()
  221.  
  222.         if re.search(r"[A-Za-z][A-Za-z][^0-9]", name) and isinstance(name, str):
  223.             if name in StudentDetails:
  224.                 break
  225.             else:
  226.                 print("Invalid name")
  227.                 continue
  228.         else:
  229.             print("Invalid Input")
  230.     while True:
  231.         print("What is your accountId: ")
  232.         accountid = input()
  233.         print()
  234.  
  235.         if re.search(r"^[0-9]", accountid) and len(accountid) == 5:
  236.             if accountid in StudentDetails[name]:
  237.                 break
  238.             else:
  239.                 print("Invalid accountid")
  240.                 continue
  241.         else:
  242.             print("Invalid input")
  243.             print()
  244.             continue
  245.     if book in StudentDetails[name]:
  246.         StudentDetails[name].remove(book)
  247.         AvailableBooks[book]+=1
  248.         print(f"You have successfully returned {book}")
  249.         print()
  250.     else:
  251.         print(f"{book} isn't inside your Archives!")
  252.  
  253.  
  254. while True:
  255.     try:
  256.         print("________________________________________________________________")
  257.         print("Press 1 to Login or access an existing account")
  258.         print("Press 2 to Create Account")
  259.         print("Press 3 to quit")
  260.         print("_________________________________________________________________")
  261.         print()
  262.         useroption = int(input())
  263.  
  264.         if isinstance(useroption, int):
  265.             if useroption ==1:
  266.                 login()
  267.                 status = False
  268.                 while True:
  269.                     print("__________________________________________________________________________________________")
  270.                     print("Press 1 to display available books")
  271.                     print("Press 2 to request a book")
  272.                     print("Press 3 to return a book")
  273.                     print("Press 4 to return to previous menu ")
  274.                     print("___________________________________________________________________________________________")
  275.                     print()
  276.                     useroption = int(input())
  277.                     if isinstance(useroption, int):
  278.                         if useroption == 1:
  279.                             display_books()
  280.                     else:
  281.                         print("Invalid input")
  282.                         continue
  283.                     if isinstance(useroption, int):
  284.                         if useroption == 2:
  285.                             request_a_book()
  286.                     else:
  287.                         print("Invalid input")
  288.                         continue
  289.                     if isinstance(useroption, int):
  290.                         if useroption == 3:
  291.                             return_a_book()
  292.                     else:
  293.                         print("Invalid input")
  294.                         continue
  295.                     if isinstance(useroption, int):
  296.                         if useroption == 4:
  297.                             break
  298.                     else:
  299.                         print("Invalid input")
  300.                         continue
  301.  
  302.  
  303.         else:
  304.             print("Invalid input")
  305.             contnue
  306.         if isinstance(useroption, int):
  307.             if useroption == 2:
  308.                 CreateAccount()
  309.                 status = False
  310.                 while True:
  311.                     print("_____________________________________________________________________")
  312.                     print("Press 1 to display available books")
  313.                     print("Press 2 to request a book")
  314.                     print("Press 3 to return a book")
  315.                     print("Press 4 to return to previous menu ")
  316.                     print("______________________________________________________________________")
  317.                     print()
  318.                     useroption = int(input())
  319.                     if isinstance(useroption, int):
  320.                         if useroption == 1:
  321.                             display_books()
  322.                     else:
  323.                         print("Invalid input")
  324.                         continue
  325.                     if isinstance(useroption, int):
  326.                         if useroption ==2:
  327.                             request_a_book()
  328.                     else:
  329.                         print("Invalid input")
  330.                         continue
  331.                     if isinstance(useroption, int):
  332.                         if useroption == 3:
  333.                             return_a_book()
  334.                     else:
  335.                         print("Invalid input")
  336.                         print()
  337.                         continue
  338.                     if isinstance(useroption, int):
  339.                         if useroption == 4:
  340.                             break
  341.                     else:
  342.                         print("Invalid input")
  343.                         print()
  344.                         continue
  345.  
  346.         if isinstance(useroption, int):
  347.             if useroption == 3:
  348.                 print()
  349.                 quit()
  350.     except ValueError:
  351.         print("Invalid input")
  352.         print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement