From 6fa2e7677078370818c984ca673da83ff1809d95 Mon Sep 17 00:00:00 2001 From: Daniela Sanchez Date: Thu, 27 May 2021 16:45:38 -0700 Subject: [PATCH 1/3] cli project started- main menu created --- main.py | 83 +++++++++++++++++++++++++++++++++++++++++++++++--- video_store.py | 41 +++++++++++++++++++++++++ 2 files changed, 119 insertions(+), 5 deletions(-) create mode 100644 video_store.py diff --git a/main.py b/main.py index ed3f1a77..eb4f8cc6 100644 --- a/main.py +++ b/main.py @@ -1,12 +1,85 @@ -import requests +import video_store -URL = "http://127.0.0.1:5000" -BACKUP_URL = "https://retro-video-store-api.herokuapp.com" -def main(): +# def main(): +# print("WELCOME TO RETRO VIDEO STORE") + +def print_stars(): + print("*********************") + +def make_choice(options): + valid_choices = options.keys() + choice = None + while choice not in valid_choices: + print("What would you like to do? Select 12 to see all options again") + choice = input("Make your selection using the option number: ") + return choice + + +def print_main_menu(): + options = { + "1": "Add a video to inventory", + "2": "Edit a video", + "3": "Delete a video from inventory", + "4": "List all videos in the catelog", + "5": "Get information on one video", + "6": "Add a new customer", + "7": "Edit a customer", + "8": "Delete a customer", + "9": "Find a customers information", + "10": "List all customers", + "11": "Check-out a video", + "12": "Check-in a video", + "13": "Quit" + } + + print_stars() print("WELCOME TO RETRO VIDEO STORE") - pass + print("These are the options you can choose from") + print_stars() + + for choice_num in options: + print(f"Option {choice_num}. {options[choice_num]}") + print_stars() + + return options + +def main(play=True): + options = print_main_menu() + while play == True: + choice = make_choice(options) + + if choice=='1': + print_stars() + response = creating_video() + print(f"New Video created! {response}") + elif choice=='2': + print_stars() + response = updating_video() + print(f"Video updated! {response}") + + + + return "the end!!" + + + +def creating_video(): + print("Awesome Sauce!! Lets add a new video to our inventory") + title = input("What is the name of the video? ") + release_date = input("What is the release_date of the video? ") + total_inventory = input("What is the starting inventory of the video? ") + response = video_store.create_video(title=title, release_date=release_date, total_inventory=total_inventory) + return response +def updating_video(): + print("Okay!! Lets update a video in our inventory") + video_id = input("What is the video id? ") + title = input("What is the name of the video? ") + release_date = input("What is the release_date of the video in datetime format? ") + total_inventory = input("What is the starting inventory of the video? ") + response = video_store.edit_video(title=title, release_date=release_date, total_inventory=total_inventory, video_id=video_id) + return response if __name__ == "__main__": main() \ No newline at end of file diff --git a/video_store.py b/video_store.py new file mode 100644 index 00000000..dff2214b --- /dev/null +++ b/video_store.py @@ -0,0 +1,41 @@ +import requests + +#URL = "http://127.0.0.1:5000" +URL = "http://localhost:5000" +BACKUP_URL = "https://retro-video-store-api.herokuapp.com" + +# class VideoStore: +# def __init__(self, url="http://localhost:5000"): +# self.url = url + +def create_video( title, release_date, total_inventory): + query_params = { + "title": title, + "release_date": release_date, + "total_inventory": total_inventory + } + response = requests.post(URL+ "/videos", json=query_params) + return response.json() + +# "2": "Edit a video" +def edit_video(title, release_date, total_inventory, video_id): + query_params = { + "title": title, + "release_date": release_date, + "total_inventory": total_inventory + } + response = requests.put(URL+ "/videos/" + video_id, json=query_params) + return response.json() + +# "3": "Delete a video from inventory", + +# "4": "List all videos in the catelog", +# "5": "Get information on one video", +# "6": "Add a new customer", +# "7": "Edit a customer", +# "8": "Delete a customer", +# "9": "Find a customers information", +# "10": "List all customers", +# "11": "Check-out a video", +# "12": "Check-in a video", +# "13": "Quit" \ No newline at end of file From 669e9a64393d05e840d66b07f72a3f60b7332f83 Mon Sep 17 00:00:00 2001 From: Daniela Sanchez Date: Fri, 28 May 2021 20:40:21 -0700 Subject: [PATCH 2/3] full cli functional --- main.py | 133 +++++++++++++++++++++++++++++++++++++++++++++---- video_store.py | 66 +++++++++++++++++++++--- 2 files changed, 184 insertions(+), 15 deletions(-) diff --git a/main.py b/main.py index eb4f8cc6..2e33126c 100644 --- a/main.py +++ b/main.py @@ -1,8 +1,4 @@ import video_store - - -# def main(): -# print("WELCOME TO RETRO VIDEO STORE") def print_stars(): print("*********************") @@ -11,7 +7,7 @@ def make_choice(options): valid_choices = options.keys() choice = None while choice not in valid_choices: - print("What would you like to do? Select 12 to see all options again") + print("What would you like to do? Select 14 to see all options again") choice = input("Make your selection using the option number: ") return choice @@ -30,7 +26,8 @@ def print_main_menu(): "10": "List all customers", "11": "Check-out a video", "12": "Check-in a video", - "13": "Quit" + "13": "Quit", + "14": "View options again!" } print_stars() @@ -41,6 +38,8 @@ def print_main_menu(): for choice_num in options: print(f"Option {choice_num}. {options[choice_num]}") print_stars() + print_stars() + print_stars() return options @@ -57,10 +56,59 @@ def main(play=True): print_stars() response = updating_video() print(f"Video updated! {response}") - - + elif choice == '3': + print_stars() + response = delete_video() + print(f"Video delete! {response}") + elif choice == '4': + print_stars() + response = list_videos() + print(f"All the videos: ") + for video in response: + print(video) + elif choice == '5': + print_stars() + response = get_one_video() + print(f"Video requested!: {response}") + elif choice == '6': + print_stars() + response = add_new_customer() + print(f"New Customer Added!: {response}") + elif choice == '7': + print_stars() + response = update_a_customer() + print(f"Customer updated! {response}") + elif choice == '8': + print_stars() + response = delete_a_customer() + print(f"Customer deleted!! {response}") + elif choice == '9': + print_stars() + response = get_one_customer() + print(f"Customer!: {response}") + elif choice == '10': + print_stars() + response = list_all_customer() + print(f"All the customers!") + for custoner in response: + print(video) + elif choice == '11': + print_stars() + response = checkout_video() + print(f"Checked out!: {response}") + elif choice == '12': + print_stars() + response = checkin_video() + print(f"Checked back in!: {response}") + elif choice == '13': + print_stars() + print_stars() + play=False + print("\nThanks for coming to the Retro Video Store!") + elif choice == '14': + options = print_main_menu() + print_stars() - return "the end!!" @@ -81,5 +129,72 @@ def updating_video(): response = video_store.edit_video(title=title, release_date=release_date, total_inventory=total_inventory, video_id=video_id) return response +def delete_video(): + print("Sure thing! Let get rid of this rejected video!") + video_id = input("What is the video id? ") + response = video_store.delete_video(video_id=video_id) + return response + +def list_videos(): + print("Alrighty!! Lets see our inventory!!") + response = video_store.list_all_videos() + return response + +def get_one_video(): + print("Interested in just video? OK!!") + video_id = input("What is the video id? ") + response = video_store.get_video(video_id=video_id) + return response + +def add_new_customer(): + print("Cool!! Lets add a new customer") + name = input("What is the name of this new customer? ") + postal_code = input("What is the postal code of this new customer? ") + phone = input("What is this customers' phone number? ") + response = video_store.add_customer(name=name, postal_code=postal_code, phone=phone) + return response + +def update_a_customer(): + print("Lets update this puppy!!") + customer_id = input("What is the customers' id? ") + name = input("What is the updated name of this customer? ") + postal_code = input("What is the updated postal code of this customer? ") + phone = input("What is this customers' updated phone number? ") + response = video_store.edit_customer(customer_id=customer_id, name=name, postal_code=postal_code, phone=phone) + return response + +def delete_a_customer(): + print("Let remove this customer!!") + customer_id = input("What is the customers' id? ") + response = video_store.delete_customer(customer_id=customer_id) + return response + +def get_one_customer(): + print("Let's get just one customer? OK!!") + customer_id = input("What is the customer id? ") + response = video_store.get_customer(customer_id=customer_id) + return response + +def list_all_customer(): + print("Lets see all the customers!") + response = video_store.list_customers() + return response + +def checkout_video(): + print("Whooyee! You're checking a video out!") + customer_id = input("What is the customers' id that is checking out the video? ") + video_id = input("What is the video id of the video being checked out? ") + response = video_store.checkout(customer_id=customer_id, video_id=video_id) + return response + +def checkin_video(): + print("Alrightyyy! I hope you liked the video! Let's check it back in!") + customer_id = input("What is the customers' id? ") + video_id = input("What is the video id of the video being checked back in? ") + response = video_store.checkin(customer_id=customer_id, video_id=video_id) + return response + + + if __name__ == "__main__": main() \ No newline at end of file diff --git a/video_store.py b/video_store.py index dff2214b..481cd855 100644 --- a/video_store.py +++ b/video_store.py @@ -18,6 +18,8 @@ def create_video( title, release_date, total_inventory): return response.json() # "2": "Edit a video" + + def edit_video(title, release_date, total_inventory, video_id): query_params = { "title": title, @@ -27,15 +29,67 @@ def edit_video(title, release_date, total_inventory, video_id): response = requests.put(URL+ "/videos/" + video_id, json=query_params) return response.json() -# "3": "Delete a video from inventory", +# "3": "Delete a video from inventory", +def delete_video(video_id): + response = requests.delete(URL+ "/videos/" + video_id) + return response.json() # "4": "List all videos in the catelog", +def list_all_videos(): + response = requests.get(URL+ "/videos/") + return response.json() + # "5": "Get information on one video", -# "6": "Add a new customer", -# "7": "Edit a customer", -# "8": "Delete a customer", -# "9": "Find a customers information", -# "10": "List all customers", +def get_video(video_id): + response = requests.get(URL+ "/videos/" + video_id) + return response.json() + +def add_customer(name, postal_code, phone): + query_params = { + "name": name, + "postal_code": postal_code, + "phone": phone + } + response = requests.post(URL+ "/customers", json=query_params) + return response.json() + +def edit_customer(customer_id, name, postal_code, phone): + query_params = { + "name": name, + "postal_code": postal_code, + "phone": phone + } + response = requests.put(URL+ "/customers/"+ customer_id, json=query_params) + return response.json() + +def delete_customer(customer_id): + response = requests.delete(URL+ "/customers/" + customer_id) + return response.json() + +def get_customer(customer_id): + response = requests.get(URL+ "/customers/" + customer_id) + return response.json() +# +def list_customers(): + response = requests.get(URL+ "/customers/") + return response.json() + +def checkout(customer_id, video_id): + query_params = { + "customer_id": customer_id, + "video_id": video_id + } + response = requests.post(URL+ "/rentals/check-out", json=query_params) + return response.json() + +def checkin(customer_id, video_id): + query_params = { + "customer_id": customer_id, + "video_id": video_id + } + response = requests.post(URL+ "/rentals/check-in", json=query_params) + return response.json() + # "11": "Check-out a video", # "12": "Check-in a video", # "13": "Quit" \ No newline at end of file From 039fd4b2404496d55e1e4b5fc7e90608af251374 Mon Sep 17 00:00:00 2001 From: Daniela Sanchez Date: Fri, 28 May 2021 21:26:35 -0700 Subject: [PATCH 3/3] Added pyfiglet lettering --- main.py | 59 ++++++++++++++++++++++++++++++++++---------------- video_store.py | 4 ---- 2 files changed, 40 insertions(+), 23 deletions(-) diff --git a/main.py b/main.py index 2e33126c..25554652 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,6 @@ import video_store +import pyfiglet + def print_stars(): print("*********************") @@ -17,7 +19,7 @@ def print_main_menu(): "1": "Add a video to inventory", "2": "Edit a video", "3": "Delete a video from inventory", - "4": "List all videos in the catelog", + "4": "List all videos in the catalog", "5": "Get information on one video", "6": "Add a new customer", "7": "Edit a customer", @@ -31,80 +33,99 @@ def print_main_menu(): } print_stars() - print("WELCOME TO RETRO VIDEO STORE") - print("These are the options you can choose from") + print("These are the options you can choose from:") + print_stars() print_stars() + for choice_num in options: print(f"Option {choice_num}. {options[choice_num]}") print_stars() print_stars() - print_stars() return options def main(play=True): + welcome_sign = pyfiglet.figlet_format(" WELCOME TO:", font = "bubble" ) + print(welcome_sign) + store_name = pyfiglet.figlet_format("RETRO VIDEO STORE", font = "5lineoblique" ) + print(store_name) options = print_main_menu() + while play == True: choice = make_choice(options) - if choice=='1': print_stars() response = creating_video() print(f"New Video created! {response}") + print("\n") elif choice=='2': print_stars() response = updating_video() print(f"Video updated! {response}") + print("\n") elif choice == '3': print_stars() response = delete_video() print(f"Video delete! {response}") + print("\n") elif choice == '4': print_stars() response = list_videos() print(f"All the videos: ") for video in response: print(video) + print("\n") elif choice == '5': print_stars() response = get_one_video() print(f"Video requested!: {response}") + print("\n") elif choice == '6': print_stars() response = add_new_customer() print(f"New Customer Added!: {response}") + print("\n") elif choice == '7': print_stars() response = update_a_customer() print(f"Customer updated! {response}") + print("\n") elif choice == '8': print_stars() response = delete_a_customer() print(f"Customer deleted!! {response}") + print("\n") elif choice == '9': print_stars() response = get_one_customer() print(f"Customer!: {response}") + print("\n") elif choice == '10': print_stars() response = list_all_customer() print(f"All the customers!") for custoner in response: - print(video) + print(custoner) + print("\n") elif choice == '11': print_stars() response = checkout_video() print(f"Checked out!: {response}") + print("\n") elif choice == '12': print_stars() response = checkin_video() print(f"Checked back in!: {response}") + print("\n") elif choice == '13': print_stars() print_stars() play=False - print("\nThanks for coming to the Retro Video Store!") + # print("\nThanks for coming to the Retro Video Store!") + Goodbye = pyfiglet.figlet_format("Goodbye!!", font = "slant" ) + print(Goodbye) + elif choice == '14': options = print_main_menu() print_stars() @@ -113,7 +134,7 @@ def main(play=True): def creating_video(): - print("Awesome Sauce!! Lets add a new video to our inventory") + print("\nAwesome Sauce!! Lets add a new video to our inventory") title = input("What is the name of the video? ") release_date = input("What is the release_date of the video? ") total_inventory = input("What is the starting inventory of the video? ") @@ -121,7 +142,7 @@ def creating_video(): return response def updating_video(): - print("Okay!! Lets update a video in our inventory") + print("\nOkay!! Lets update a video in our inventory") video_id = input("What is the video id? ") title = input("What is the name of the video? ") release_date = input("What is the release_date of the video in datetime format? ") @@ -130,24 +151,24 @@ def updating_video(): return response def delete_video(): - print("Sure thing! Let get rid of this rejected video!") + print("\nSure thing! Let get rid of this rejected video!") video_id = input("What is the video id? ") response = video_store.delete_video(video_id=video_id) return response def list_videos(): - print("Alrighty!! Lets see our inventory!!") + print("\nAlrighty!! Lets see our inventory!!") response = video_store.list_all_videos() return response def get_one_video(): - print("Interested in just video? OK!!") + print("\nInterested in just video? OK!!") video_id = input("What is the video id? ") response = video_store.get_video(video_id=video_id) return response def add_new_customer(): - print("Cool!! Lets add a new customer") + print("\nCool!! Lets add a new customer") name = input("What is the name of this new customer? ") postal_code = input("What is the postal code of this new customer? ") phone = input("What is this customers' phone number? ") @@ -155,7 +176,7 @@ def add_new_customer(): return response def update_a_customer(): - print("Lets update this puppy!!") + print("\nLet's update this puppy!!") customer_id = input("What is the customers' id? ") name = input("What is the updated name of this customer? ") postal_code = input("What is the updated postal code of this customer? ") @@ -164,31 +185,31 @@ def update_a_customer(): return response def delete_a_customer(): - print("Let remove this customer!!") + print("\nLet's remove this customer!!") customer_id = input("What is the customers' id? ") response = video_store.delete_customer(customer_id=customer_id) return response def get_one_customer(): - print("Let's get just one customer? OK!!") + print("\nLet's get just one customer? OK!!") customer_id = input("What is the customer id? ") response = video_store.get_customer(customer_id=customer_id) return response def list_all_customer(): - print("Lets see all the customers!") + print("\nLet's see all the customers!") response = video_store.list_customers() return response def checkout_video(): - print("Whooyee! You're checking a video out!") + print("\nWhooyee! You're checking a video out!") customer_id = input("What is the customers' id that is checking out the video? ") video_id = input("What is the video id of the video being checked out? ") response = video_store.checkout(customer_id=customer_id, video_id=video_id) return response def checkin_video(): - print("Alrightyyy! I hope you liked the video! Let's check it back in!") + print("\nAlrightyyy! I hope you liked the video! Let's check it back in!") customer_id = input("What is the customers' id? ") video_id = input("What is the video id of the video being checked back in? ") response = video_store.checkin(customer_id=customer_id, video_id=video_id) diff --git a/video_store.py b/video_store.py index 481cd855..e978abaa 100644 --- a/video_store.py +++ b/video_store.py @@ -89,7 +89,3 @@ def checkin(customer_id, video_id): } response = requests.post(URL+ "/rentals/check-in", json=query_params) return response.json() - -# "11": "Check-out a video", -# "12": "Check-in a video", -# "13": "Quit" \ No newline at end of file