Advertisement
Blessing988

Untitled

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