Advertisement
Blessing988

Untitled

Apr 26th, 2020
576
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 10.00 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.         if re.search(r"^[A-Za-z]+[A-Za-z]{4}[0-9]", username):
  39.             break
  40.         else:
  41.             print("Invalid Username")
  42.  
  43.     while True:
  44.         print("Enter Password")
  45.         password = input(" ").strip()
  46.         if  8<=len(password)<=16:
  47.             if re.search(r"[A-Za-z]", password):
  48.                 if re.search(r"[0-9]", password):
  49.                     if re.search(r"[*#@!^#$%]", password):
  50.                         break
  51.                     else:
  52.                         print("Password must contain special characters or symbols")
  53.                         continue
  54.                 else:
  55.                     print("Password must contain numbers")
  56.                     continue
  57.             else:
  58.                 print("Password must contain letters")
  59.                 continue
  60.         else:
  61.             print("Password must be between 8 - 16 characters")
  62.             continue
  63.     while True:
  64.         print("Enter a valid email address: ")
  65.         email_address = input().strip()
  66.  
  67.         if re.search("^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$", email_address):
  68.             break
  69.         else:
  70.             print("Invalid email address")
  71.  
  72.         if email_address in StudentDetails[username]:
  73.             print("Account already exist")
  74.             continue
  75.  
  76.     AcountId = random.randint(10000, 99999)
  77.     StudentDetails[username] = [email_address, str(AcountId), password]
  78.     print("Account Created Succesfully")
  79.     print(f"Your Account Id is {AcountId}")
  80. def login():
  81.     global StudentDetails
  82.     while True:
  83.         print("Enter your name: ")
  84.         username = input().strip()
  85.         print()
  86.  
  87.         if re.search(r"^[A-Za-z]+[A-Za-z]{4}[0-9]", username) and username:
  88.             if username in StudentDetails:
  89.                 break
  90.             else:
  91.                 print("Invalid Username")
  92.                 continue
  93.         else:
  94.             print("Invalid Usename")
  95.             continue
  96.  
  97.     while True:
  98.         print("Enter your email address: ")
  99.         email_address = input().strip()
  100.         if email_address in StudentDetails[username]:
  101.             break
  102.         else:
  103.             print("Invalid email address")
  104.             continue
  105.  
  106.     while True:
  107.  
  108.         print("Enter your password: ")
  109.         password = input().strip()
  110.         if re.search(r"[A-Z0-9a-z*#@!^#$%]", password):
  111.             if password in StudentDetails[username]:
  112.                 break
  113.             else:
  114.                 print("Invalid password")
  115.                 continue
  116.         else:
  117.             print("Invalid password")
  118.             continue
  119.     print("Access Granted")
  120. # What the library does
  121. def display_books( ):
  122.     global AvailableBooks
  123.     print()
  124.     for book in AvailableBooks:
  125.         print("\t\t\t", book)
  126. def request_a_book():
  127.     global deadline
  128.     my_deadline = deadline.strftime("%A, %B %d, %Y")
  129.     global StudentDetails
  130.     global AvailableBooks
  131.     while True:
  132.         print("Enter the book you are requesting: ")
  133.         book = input( ).strip().title()
  134.         if re.search(r"^[A-Za-z]+[A-Za-z]",book ) and isinstance(book, str):
  135.             if book in AvailableBooks:
  136.                 break
  137.             else:
  138.                 print("Book not available")
  139.                 continue
  140.         else:
  141.             print("Invalid input")
  142.             continue
  143.     print("You are supposed to enter your login credentials to secure your identity")
  144.     while True:
  145.         print("What is your name: ")
  146.         name = input( )
  147.         print()
  148.  
  149.         if re.search(r"[A-Za-z][A-Za-z][^0-9]",name) and isinstance(name, str):
  150.             if name in StudentDetails:
  151.                 break
  152.             else:
  153.                 print("Invalid name")
  154.                 continue
  155.         else:
  156.             print("Invalid Input")
  157.     while True:
  158.         print("What is your accountId: ")
  159.         accountid = input()
  160.         print()
  161.  
  162.         if re.search(r"^[0-9]", accountid) and len(accountid)==5 :
  163.             if accountid in StudentDetails[name]:
  164.                 break
  165.             else:
  166.                 print("Invalid accountid")
  167.                 continue
  168.         else:
  169.             print("Invalid input")
  170.             continue
  171.     if book not in StudentDetails[name]:
  172.         StudentDetails[name].append(book)
  173.         AvailableBooks[book]-=1
  174.         print(f"You have borrowed {book} successfully")
  175.         print(f"The deadline for submission is on {my_deadline}")
  176.         print()
  177.     elif book in StudentDetails[name]:
  178.         print(f"You have borrowed {book} already")
  179.     elif book not in AvailableBooks:
  180.         print(f"We dont have {book} in our Library. Management services will make Modifications")
  181.     elif book in AvailableBooks and AvailableBooks[book]==0:
  182.         print("{Book} out of stock. Check up later")
  183.  
  184.  
  185. def return_a_book():
  186.     global StudentDetails
  187.     global AvailableBooks
  188.     while True:
  189.         print("Which book are you returning: ")
  190.         book = input().strip().title()
  191.         if re.search(r"[A-za-z][^0-9]", book) and isinstance(book, str):
  192.             if book in AvailableBooks:
  193.                 break
  194.             else:
  195.                 continue
  196.         else:
  197.             continue
  198.     print("You are supposed to enter your login credentials to secure your identity")
  199.     while True:
  200.         print("What is your name: ")
  201.         name = input()
  202.         print()
  203.  
  204.         if re.search(r"[A-Za-z][A-Za-z][^0-9]", name) and isinstance(name, str):
  205.             if name in StudentDetails:
  206.                 break
  207.             else:
  208.                 print("Invalid name")
  209.                 continue
  210.         else:
  211.             print("Invalid Input")
  212.     while True:
  213.         print("What is your accountId: ")
  214.         accountid = input()
  215.         print()
  216.  
  217.         if re.search(r"^[0-9]", accountid) and len(accountid) == 5:
  218.             if accountid in StudentDetails[name]:
  219.                 break
  220.             else:
  221.                 print("Invalid accountid")
  222.                 continue
  223.         else:
  224.             print("Invalid input")
  225.             print()
  226.             continue
  227.     if book in StudentDetails[name]:
  228.         StudentDetails[name].remove(book)
  229.         AvailableBooks[book]+=1
  230.         print(f"You have successfully returned {book}")
  231.         print()
  232.     else:
  233.         print(f"{Book} isn't inside your Archives!")
  234.  
  235.  
  236. while True:
  237.     try:
  238.         print("Press 1 to Login or access an existing account")
  239.         print("Press 2 to Create Account")
  240.         print("Press 3 to quit")
  241.         print()
  242.         useroption = int(input())
  243.  
  244.         if isinstance(useroption, int):
  245.             if useroption ==1:
  246.                 login()
  247.                 status = False
  248.         else:
  249.             print("Invalid input")
  250.             contnue
  251.         if isinstance(useroption, int):
  252.             if useroption == 2:
  253.                 CreateAccount()
  254.                 status = False
  255.                 while True:
  256.                     print("Press 1 to display available books")
  257.                     print("Press 2 to request a book")
  258.                     print("Press 3 to return a book")
  259.                     print("Press 4 to return to previous menu ")
  260.                     useroption = int(input())
  261.                     if isinstance(useroption, int):
  262.                         if useroption == 1:
  263.                             display_books()
  264.                     else:
  265.                         print("Invalid input")
  266.                         continue
  267.                     if isinstance(useroption, int):
  268.                         if useroption ==2:
  269.                             request_a_book()
  270.                     else:
  271.                         print("Invalid input")
  272.                         continue
  273.                     if isinstance(useroption, int):
  274.                         if useroption == 3:
  275.                             return_a_book()
  276.                     else:
  277.                         print("Invalid input")
  278.                         continue
  279.                     if isinstance(useroption, int):
  280.                         if useroption == 4:
  281.                             break
  282.                     else:
  283.                         print("Invalid input")
  284.                         continue
  285.  
  286.         if isinstance(useroption, int):
  287.             if useroption == 3:
  288.                 print()
  289.                 quit()
  290.     except ValueError:
  291.         print("Invalid input")
  292.         print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement