Advertisement
Blessing988

Untitled

Apr 27th, 2020
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 11.71 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 Usename")
  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.     for book in AvailableBooks:
  137.         print("\t\t\t", book)
  138. def request_a_book():
  139.     global deadline
  140.     my_deadline = deadline.strftime("%A, %B %d, %Y")
  141.     global StudentDetails
  142.     global AvailableBooks
  143.     while True:
  144.         print("Enter the book you are requesting: ")
  145.         book = input( ).strip().title()
  146.         if re.search(r"^[A-Za-z]+[A-Za-z]",book ) and isinstance(book, str):
  147.             if book in AvailableBooks:
  148.                 break
  149.             else:
  150.                 print("Book not available")
  151.                 continue
  152.         else:
  153.             print("Invalid input")
  154.             continue
  155.     print("You are supposed to enter your login credentials to secure your identity")
  156.     while True:
  157.         print("What is your name: ")
  158.         name = input( )
  159.         print()
  160.  
  161.         if re.search(r"[A-Za-z][A-Za-z][^0-9]",name) and isinstance(name, str):
  162.             if name in StudentDetails:
  163.                 break
  164.             else:
  165.                 print("Invalid name")
  166.                 continue
  167.         else:
  168.             print("Invalid Input")
  169.     while True:
  170.         print("What is your accountId: ")
  171.         accountid = input()
  172.         print()
  173.  
  174.         if re.search(r"^[0-9]", accountid) and len(accountid)==5 :
  175.             if accountid in StudentDetails[name]:
  176.                 break
  177.             else:
  178.                 print("Invalid accountid")
  179.                 continue
  180.         else:
  181.             print("Invalid input")
  182.             continue
  183.     if book not in StudentDetails[name]:
  184.         StudentDetails[name].append(book)
  185.         AvailableBooks[book]-=1
  186.         print(f"You have borrowed {book} successfully")
  187.         print(f"The deadline for submission is on {my_deadline}")
  188.         print()
  189.     elif book in StudentDetails[name]:
  190.         print(f"You have borrowed {book} already")
  191.     elif book not in AvailableBooks:
  192.         print(f"We dont have {book} in our Library. Management services will make Modifications")
  193.     elif book in AvailableBooks and AvailableBooks[book]==0:
  194.         print("{Book} out of stock. Check up later")
  195.  
  196.  
  197. def return_a_book():
  198.     global StudentDetails
  199.     global AvailableBooks
  200.     while True:
  201.         print("Which book are you returning: ")
  202.         book = input().strip().title()
  203.         if re.search(r"[A-za-z][^0-9]", book) and isinstance(book, str):
  204.             if book in AvailableBooks:
  205.                 break
  206.             else:
  207.                 continue
  208.         else:
  209.             continue
  210.     print("You are supposed to enter your login credentials to secure your identity")
  211.     while True:
  212.         print("What is your name: ")
  213.         name = input()
  214.         print()
  215.  
  216.         if re.search(r"[A-Za-z][A-Za-z][^0-9]", name) and isinstance(name, str):
  217.             if name in StudentDetails:
  218.                 break
  219.             else:
  220.                 print("Invalid name")
  221.                 continue
  222.         else:
  223.             print("Invalid Input")
  224.     while True:
  225.         print("What is your accountId: ")
  226.         accountid = input()
  227.         print()
  228.  
  229.         if re.search(r"^[0-9]", accountid) and len(accountid) == 5:
  230.             if accountid in StudentDetails[name]:
  231.                 break
  232.             else:
  233.                 print("Invalid accountid")
  234.                 continue
  235.         else:
  236.             print("Invalid input")
  237.             print()
  238.             continue
  239.     if book in StudentDetails[name]:
  240.         StudentDetails[name].remove(book)
  241.         AvailableBooks[book]+=1
  242.         print(f"You have successfully returned {book}")
  243.         print()
  244.     else:
  245.         print(f"{Book} isn't inside your Archives!")
  246.  
  247.  
  248. while True:
  249.     try:
  250.         print("Press 1 to Login or access an existing account")
  251.         print("Press 2 to Create Account")
  252.         print("Press 3 to quit")
  253.         print()
  254.         useroption = int(input())
  255.  
  256.         if isinstance(useroption, int):
  257.             if useroption ==1:
  258.                 login()
  259.                 status = False
  260.                 while True:
  261.                     print("Press 1 to display available books")
  262.                     print("Press 2 to request a book")
  263.                     print("Press 3 to return a book")
  264.                     print("Press 4 to return to previous menu ")
  265.                     print()
  266.                     useroption = int(input())
  267.                     if isinstance(useroption, int):
  268.                         if useroption == 1:
  269.                             display_books()
  270.                     else:
  271.                         print("Invalid input")
  272.                         continue
  273.                     if isinstance(useroption, int):
  274.                         if useroption == 2:
  275.                             request_a_book()
  276.                     else:
  277.                         print("Invalid input")
  278.                         continue
  279.                     if isinstance(useroption, int):
  280.                         if useroption == 3:
  281.                             return_a_book()
  282.                     else:
  283.                         print("Invalid input")
  284.                         continue
  285.                     if isinstance(useroption, int):
  286.                         if useroption == 4:
  287.                             break
  288.                     else:
  289.                         print("Invalid input")
  290.                         continue
  291.  
  292.  
  293.         else:
  294.             print("Invalid input")
  295.             contnue
  296.         if isinstance(useroption, int):
  297.             if useroption == 2:
  298.                 CreateAccount()
  299.                 status = False
  300.                 while True:
  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.                     useroption = int(input())
  307.                     if isinstance(useroption, int):
  308.                         if useroption == 1:
  309.                             display_books()
  310.                     else:
  311.                         print("Invalid input")
  312.                         continue
  313.                     if isinstance(useroption, int):
  314.                         if useroption ==2:
  315.                             request_a_book()
  316.                     else:
  317.                         print("Invalid input")
  318.                         continue
  319.                     if isinstance(useroption, int):
  320.                         if useroption == 3:
  321.                             return_a_book()
  322.                     else:
  323.                         print("Invalid input")
  324.                         print()
  325.                         continue
  326.                     if isinstance(useroption, int):
  327.                         if useroption == 4:
  328.                             break
  329.                     else:
  330.                         print("Invalid input")
  331.                         print()
  332.                         continue
  333.  
  334.         if isinstance(useroption, int):
  335.             if useroption == 3:
  336.                 print()
  337.                 quit()
  338.     except ValueError:
  339.         print("Invalid input")
  340.         print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement