From 0ec3cd663166e08bb7bdface7824718567c9f2fa Mon Sep 17 00:00:00 2001 From: Laurel Date: Fri, 28 May 2021 20:26:51 -0700 Subject: [PATCH 1/7] completed requirements 1-5 chck/in/out in works --- main.py | 153 ++++++++++++++++++++++++++++++++++++++++++++++++- video_store.py | 107 ++++++++++++++++++++++++++++++++++ 2 files changed, 257 insertions(+), 3 deletions(-) create mode 100644 video_store.py diff --git a/main.py b/main.py index ed3f1a77..4af70539 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,8 @@ import requests +from video_store import Video_store -URL = "http://127.0.0.1:5000" -BACKUP_URL = "https://retro-video-store-api.herokuapp.com" +#URL = "http://localhost:5000" +URL = "https://retro-video-store-api.herokuapp.com" def main(): print("WELCOME TO RETRO VIDEO STORE") @@ -9,4 +10,150 @@ def main(): if __name__ == "__main__": - main() \ No newline at end of file + main() + +def print_stars(): + print("\n**************************\n") + +def list_options(): + + options = { + "1": "List all videos in stock", + "2": "Create a new video record", + "3": "Select a video", + "4": "Update selected video", + "5": "Delete selected video", + "6": "Delete all videos in stock", + "7": "List all options", + "8": "Quit", + "9": "Rent out a video", + "10": "Return a video" + } + + print_stars() + print("Welcome") + print("These are the actions you can perform") + print_stars() + + for choice_num in options: + print(f"Option {choice_num}. {options[choice_num]}") + + print_stars() + + return options + + +def make_choice(options, video_store): + valid_choices = options.keys() + choice = None + + while choice not in valid_choices: + print("What would you like to do? Select 7 to see all options again") + choice = input("Make your selection using the option number: ") + + if choice in ['4','5'] and video_store.selected_video == None: + print("You must select a video before updating it, deleting it, checking it out, or checking back in.") + print("Let's select a video!") + choice = "3" + + return choice + +def run_cli(play=True): + + #initialize video + video_store = Video_store(URL) ##put url here if you can't find it ya silly + + # print choices + options = list_options() + + while play==True: + + # get input and validate + choice = make_choice(options, video_store) + + #video_store.print_selected() + + if choice=='1': + print_stars() + for video in video_store.list_videos(): + print(video) + + elif choice=='2': + print("Great! Let's create a new video.") + title=input("What is the name of the video? ") + release_date=input("When was this movie released?") + total_inventory=input("How many copies of this video are we adding?") + response = video_store.create_video(title=title, release_date=release_date, total_inventory= total_inventory) + + print_stars() + print("New video:", response) + + elif choice=='3': + select_by = input("Would you like to select by? Enter title or id: ") + if select_by=="title": + title = input("Which title would you like to select? ") + video_store.get_video(title=title) + elif select_by=="id": + video_id = input("Which video id would you like to select? ") + if video_id.isnumeric(): + video_id = int(video_id) + video_store.get_video(video_id=video_id) + else: + print("Could not select. Please enter id or title.") + + if video_store.selected_video: + print_stars() + print("Selected video: ", video_store.selected_video) + + elif choice=='4': + print(f"Great! Let's update the movie: {video_store.selected_video}") + title=input("What is the title of your new video? ") + release_date=input("When was it released?") + total_inventory=input("How many copies do you have available to add to stock?") + response = video_store.update_video(title=title, release_date=release_date, total_inventory=total_inventory) + + print_stars() + print("video:", response) + elif choice=='5': + video_store.delete_video() + + print_stars() + print("Movie has been deleted.") + + print_stars() + + elif choice=='6': + for video in video_store.list_videos(): + video_store.get_video(video_id=video['id']) + video_store.delete_video() + + print_stars() + print("Deleted all videos in stock. Out with the old.") + + elif choice=='7': + list_options() + + elif choice=='8': + play=False + print("\nThanks!") + + elif choice =='9': + customer_id = input("Which customer is renting today? (please provide customer id)") + video_id = input("Which video would they like to rent? (please provide video id)" ) + response = video_store.check_out_video(int(customer_id), int(video_id)) + print(response) + print_stars() + + elif choice =='10': + customer_id = input("Which customer is returning today? (please provide customer id)") + video_id = input("Which video are they returning? (please provide video id)") + response = video_store.check_in_video(int(customer_id), int(video_id)) + print(response) + print_stars() + + + print_stars() + + +run_cli() + diff --git a/video_store.py b/video_store.py new file mode 100644 index 00000000..fc9964c4 --- /dev/null +++ b/video_store.py @@ -0,0 +1,107 @@ +import requests +import datetime +from flask import json + + +##could also put a helper function for select video in main.py +# +# +###below is becc'as code +class Video_store: + def __init__(self, URL = "https://retro-video-store-api.herokuapp.com", selected_video=None, selected_customer=None): #selected_customer=None, selected_rental=None ): + self.url = URL + self.selected_video = selected_video + self.selected_customer = selected_customer + + + ########## video actions to do: edit, still need to decide which query params needed and how to edit (look at routes?) + ##Check out video to customer: part of video requirements is to be able to check it out to customers, which is through rental routes + def check_out_video(self, video_id, customer_id): + query_params={ + "customer_id": customer_id, + "video_id": video_id + } + response = requests.post(self.url+"/rentals/check-out", json = query_params) + return response + + def check_in_video(self, video_id, customer_id): + query_params={ + "customer_id": customer_id, + "video_id": video_id + } + response = requests.post(self.url+"/rentals/check-in", json= query_params) + return response + + def print_selected(self): + pass + if self.selected_video: + print(f"Video with id {self.selected_video} is selected.") + else: + print("Video not found") + + def create_video(self, title= "Default title", release_date= "Default release date", total_inventory= "default stock"): + + query_params = { + "title": title, + "release_date": release_date, + "total_inventory": total_inventory, + } + response = requests.post(self.url+"/videos",json=query_params) + return response.json() + + def list_videos(self): #List videos, get information about all videos | I can see the store stock | + response = requests.get(self.url+"/videos") + return response.json() + + #| List videos #2 get information about one video | I can see how many copies + def get_video(self, title=None, video_id=None, release_date= None): + + for video in self.list_videos(): + if title: + if video["title"]==title: + video_id = video["id"] + self.selected_video = video + elif int(video_id) == video["id"]: + self.selected_video = video + # elif release_date: + # if video["release_date"]==release_date: + # self.selected_video = video + + if self.selected_video == None: + return "Could not find video in stock" + + response = requests.get(self.url+f"/videos/{video_id}") #self. instead of requests? + return response.json() + + #edit a video | the information about the video is accurate + def update_video(self,title=None, video_id=None, release_date=None, total_inventory=None): + if not title: + title = self.selected_video["title"] + if not video_id: + video_id = self.selected_video["id"] + if not release_date: + release_date = self.selected_video["release_date"] + if not total_inventory: + total_inventory = self.selected_video["total_inventory"] + + query_params = { + "id": video_id, + "title": title, + "release_date": release_date, + "total_inventory": total_inventory} + + response = requests.put( + self.url+f"/videos/{self.selected_video['id']}", + json=query_params + ) + print("response:", response) #add ansi color codes here? + self.selected_video = response.json() + return response.json() + + # delete a video | the store records stay up to date | + def delete_video(self): #delete a video + response = requests.delete(self.url+f"/videos/{self.selected_video['id']}") + self.selected_video = None + return response.json() + #################################################### end video actions + From 325940b53aa4a2219415113d00e810c5d267f88f Mon Sep 17 00:00:00 2001 From: Laurel Date: Sat, 29 May 2021 14:51:18 -0700 Subject: [PATCH 2/7] ah, check in/out works now --- video_store.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/video_store.py b/video_store.py index fc9964c4..ea017959 100644 --- a/video_store.py +++ b/video_store.py @@ -6,7 +6,7 @@ ##could also put a helper function for select video in main.py # # -###below is becc'as code + class Video_store: def __init__(self, URL = "https://retro-video-store-api.herokuapp.com", selected_video=None, selected_customer=None): #selected_customer=None, selected_rental=None ): self.url = URL @@ -16,15 +16,18 @@ def __init__(self, URL = "https://retro-video-store-api.herokuapp.com", selected ########## video actions to do: edit, still need to decide which query params needed and how to edit (look at routes?) ##Check out video to customer: part of video requirements is to be able to check it out to customers, which is through rental routes - def check_out_video(self, video_id, customer_id): + def check_out_video(self, customer_id, video_id): query_params={ "customer_id": customer_id, "video_id": video_id } + print(query_params) + print(self.url+"/rentals/check-out") response = requests.post(self.url+"/rentals/check-out", json = query_params) + return response - def check_in_video(self, video_id, customer_id): + def check_in_video(self, customer_id, video_id): query_params={ "customer_id": customer_id, "video_id": video_id From 10cbce8d9c00161a32aa4ac3efd32e11570006f1 Mon Sep 17 00:00:00 2001 From: Laurel Date: Sat, 29 May 2021 16:19:32 -0700 Subject: [PATCH 3/7] added customer functions --- video_store.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/video_store.py b/video_store.py index ea017959..7b0ce89a 100644 --- a/video_store.py +++ b/video_store.py @@ -107,4 +107,48 @@ def delete_video(self): #delete a video self.selected_video = None return response.json() #################################################### end video actions + + #List customers + def list_customers(self): + response = requests.get(self.url+"/customers") + return response.json() + + #Customer create, edit, delete + def create_customer(self, name= "Default name", phone= "000-000-0000", postal_code= "00000"): + + query_params = { + "name": name, + "phone": phone, + "postal_code": postal_code, + } + response = requests.post(self.url+"/customers",json=query_params) + return response.json() + + def update_customer(self,customer_id=None,name=None, phone=None, postal_code=None): + if not customer_id: + customer_id = self.selected_customer["id"] + if not name: + name = self.selected_customer["name"] + if not phone: + phone = self.selected_customer["phone"] + if not postal_code: + postal_code = self.selected_customer["postal_code"] + + query_params = { + "name": name, + "phone": phone, + "postal_code": postal_code, + } + + response = requests.put( + self.url+f"/customers/{self.selected_customer['id']}", + json=query_params + ) + print("response:", response) #add ansi color codes here? + self.selected_video = response.json() + return response.json() + def delete_customer(self): #delete a customer + response = requests.delete(self.url+f"/customers/{self.selected_customer['id']}") + self.selected_video = None + return response.json() From 96465c797b1eb4003101004a34eef9b47905d234 Mon Sep 17 00:00:00 2001 From: Laurel Date: Sat, 29 May 2021 16:26:36 -0700 Subject: [PATCH 4/7] smol steps --- main.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 4af70539..801e3df2 100644 --- a/main.py +++ b/main.py @@ -16,7 +16,7 @@ def print_stars(): print("\n**************************\n") def list_options(): - + #add option where every customer action requires you to select a customer within that action. options = { "1": "List all videos in stock", "2": "Create a new video record", @@ -27,7 +27,11 @@ def list_options(): "7": "List all options", "8": "Quit", "9": "Rent out a video", - "10": "Return a video" + "10": "Return a video", + "1": "List all customers", + "2": "Add a new video customer", + "4": "Update a customer", + "5": "Delete a customer", } print_stars() From d4a4870d02ed381ff02c86c53a1a864da0dfba29 Mon Sep 17 00:00:00 2001 From: Laurel Date: Sat, 29 May 2021 19:38:23 -0700 Subject: [PATCH 5/7] added customers not cleaned or tested --- main.py | 68 ++++++++++++++++++++++++++++++++++++++++++++++---- video_store.py | 17 +++++++++++++ 2 files changed, 80 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 801e3df2..e4e40f17 100644 --- a/main.py +++ b/main.py @@ -28,10 +28,11 @@ def list_options(): "8": "Quit", "9": "Rent out a video", "10": "Return a video", - "1": "List all customers", - "2": "Add a new video customer", - "4": "Update a customer", - "5": "Delete a customer", + "11": "List all customers", + "12": "Add a new video customer", + "13": "Update selected customer", + "14": "Delete selected customer", + "15": "Select a customer" } print_stars() @@ -56,9 +57,15 @@ def make_choice(options, video_store): choice = input("Make your selection using the option number: ") if choice in ['4','5'] and video_store.selected_video == None: - print("You must select a video before updating it, deleting it, checking it out, or checking back in.") + print("You must select a video before updating or deleting it") print("Let's select a video!") choice = "3" + + elif choice in ['13', '14'] and video_store.selected_customer == None: + print("You must select a customer before updating or deleting it") + print("Let's select a customer!") + choice = "15" + return choice @@ -118,6 +125,7 @@ def run_cli(play=True): print_stars() print("video:", response) + elif choice=='5': video_store.delete_video() @@ -155,6 +163,56 @@ def run_cli(play=True): print(response) print_stars() + # "11": "List all customers", + elif choice =='11': + print_stars() + for customer in video_store.list_customers(): + print(customer) + # "12": "Add a new customer", + elif choice =='12': + print("Great! Let's add a new customer.") + name=input("What is the name of customer?") + phone=input("Please add customer's phone number ->") + postal_code=input("Please add customer's postal code ->") + response = video_store.create_customer(name=name, phone=phone, postal_code= postal_code) + + print_stars() + print("New customer:", response) + # "13": "Update a customer", + elif choice =='13': + print(f"Great! Let's update the customer {video_store.selected_customer}'s record") + name=input("What is the new name of customer?") + phone=input("Please add customer's new phone number ->") + postal_code=input("Please add customer's new postal code ->") + response = video_store.update_customer(name=name, phone=phone, postal_code= postal_code) + + print_stars() + print("Customer:", response) + # "14": "Delete a customer", + elif choice == '14': + video_store.delete_customer() + + print_stars() + print("Customer has been deleted.") + + print_stars() + + elif choice == '15': + select_by = input("Would you like to select your cutomer by? Enter name or id: ") + if select_by=="name": + title = input("Which customer would you like to select by name? ") + video_store.get_customer(customer=customer) + elif select_by=="id": + customer_id = input("Which customer id would you like to select? ") + if customer_id.isnumeric(): + customer_id = int(customer_id) + video_store.get_video(customer_id=customer_id) + else: + print("Could not select. Please enter id or name.") + + if video_store.selected_customer: + print_stars() + print("Selected customer: ", video_store.selected_customer) print_stars() diff --git a/video_store.py b/video_store.py index 7b0ce89a..c40d3770 100644 --- a/video_store.py +++ b/video_store.py @@ -113,6 +113,23 @@ def list_customers(self): response = requests.get(self.url+"/customers") return response.json() + #get one customer's information + def get_customer(self, name=None, customer_id=None): + + for customer in self.list_customers(): + if name: + if customer["name"]==name: + customer_id = customer["id"] + self.selected_customer = customer + elif int(customer_id) == customer["id"]: + self.selected_customer = customer + + if self.selected_customer == None: + return "Could not find that customer in our records" + + response = requests.get(self.url+f"/customers/{customer_id}") + return response.json() + #Customer create, edit, delete def create_customer(self, name= "Default name", phone= "000-000-0000", postal_code= "00000"): From cd5bd9d122cd23f84badd7f39daf47e234598726 Mon Sep 17 00:00:00 2001 From: Laurel Date: Sat, 29 May 2021 20:13:49 -0700 Subject: [PATCH 6/7] all the required actions, not pretty yet --- main.py | 23 ++++++++--------------- video_store.py | 34 ++++++++-------------------------- 2 files changed, 16 insertions(+), 41 deletions(-) diff --git a/main.py b/main.py index e4e40f17..efaeaacf 100644 --- a/main.py +++ b/main.py @@ -16,7 +16,6 @@ def print_stars(): print("\n**************************\n") def list_options(): - #add option where every customer action requires you to select a customer within that action. options = { "1": "List all videos in stock", "2": "Create a new video record", @@ -29,7 +28,7 @@ def list_options(): "9": "Rent out a video", "10": "Return a video", "11": "List all customers", - "12": "Add a new video customer", + "12": "Add a new customer", "13": "Update selected customer", "14": "Delete selected customer", "15": "Select a customer" @@ -47,7 +46,6 @@ def list_options(): return options - def make_choice(options, video_store): valid_choices = options.keys() choice = None @@ -66,24 +64,19 @@ def make_choice(options, video_store): print("Let's select a customer!") choice = "15" - return choice def run_cli(play=True): - #initialize video - video_store = Video_store(URL) ##put url here if you can't find it ya silly + video_store = Video_store(URL) - # print choices options = list_options() while play==True: - # get input and validate + choice = make_choice(options, video_store) - #video_store.print_selected() - if choice=='1': print_stars() for video in video_store.list_videos(): @@ -163,12 +156,12 @@ def run_cli(play=True): print(response) print_stars() - # "11": "List all customers", + elif choice =='11': print_stars() for customer in video_store.list_customers(): print(customer) - # "12": "Add a new customer", + elif choice =='12': print("Great! Let's add a new customer.") name=input("What is the name of customer?") @@ -178,7 +171,7 @@ def run_cli(play=True): print_stars() print("New customer:", response) - # "13": "Update a customer", + elif choice =='13': print(f"Great! Let's update the customer {video_store.selected_customer}'s record") name=input("What is the new name of customer?") @@ -188,7 +181,7 @@ def run_cli(play=True): print_stars() print("Customer:", response) - # "14": "Delete a customer", + elif choice == '14': video_store.delete_customer() @@ -206,7 +199,7 @@ def run_cli(play=True): customer_id = input("Which customer id would you like to select? ") if customer_id.isnumeric(): customer_id = int(customer_id) - video_store.get_video(customer_id=customer_id) + video_store.get_customer(customer_id=customer_id) else: print("Could not select. Please enter id or name.") diff --git a/video_store.py b/video_store.py index c40d3770..b7457e24 100644 --- a/video_store.py +++ b/video_store.py @@ -2,20 +2,12 @@ import datetime from flask import json - -##could also put a helper function for select video in main.py -# -# - class Video_store: - def __init__(self, URL = "https://retro-video-store-api.herokuapp.com", selected_video=None, selected_customer=None): #selected_customer=None, selected_rental=None ): + def __init__(self, URL = "https://retro-video-store-api.herokuapp.com", selected_video=None, selected_customer=None): self.url = URL self.selected_video = selected_video self.selected_customer = selected_customer - - ########## video actions to do: edit, still need to decide which query params needed and how to edit (look at routes?) - ##Check out video to customer: part of video requirements is to be able to check it out to customers, which is through rental routes def check_out_video(self, customer_id, video_id): query_params={ "customer_id": customer_id, @@ -52,11 +44,10 @@ def create_video(self, title= "Default title", release_date= "Default release da response = requests.post(self.url+"/videos",json=query_params) return response.json() - def list_videos(self): #List videos, get information about all videos | I can see the store stock | + def list_videos(self): response = requests.get(self.url+"/videos") return response.json() - #| List videos #2 get information about one video | I can see how many copies def get_video(self, title=None, video_id=None, release_date= None): for video in self.list_videos(): @@ -66,17 +57,13 @@ def get_video(self, title=None, video_id=None, release_date= None): self.selected_video = video elif int(video_id) == video["id"]: self.selected_video = video - # elif release_date: - # if video["release_date"]==release_date: - # self.selected_video = video if self.selected_video == None: return "Could not find video in stock" - response = requests.get(self.url+f"/videos/{video_id}") #self. instead of requests? + response = requests.get(self.url+f"/videos/{video_id}") return response.json() - #edit a video | the information about the video is accurate def update_video(self,title=None, video_id=None, release_date=None, total_inventory=None): if not title: title = self.selected_video["title"] @@ -97,23 +84,19 @@ def update_video(self,title=None, video_id=None, release_date=None, total_invent self.url+f"/videos/{self.selected_video['id']}", json=query_params ) - print("response:", response) #add ansi color codes here? + print("response:", response) self.selected_video = response.json() return response.json() - # delete a video | the store records stay up to date | - def delete_video(self): #delete a video + def delete_video(self): response = requests.delete(self.url+f"/videos/{self.selected_video['id']}") self.selected_video = None return response.json() - #################################################### end video actions - - #List customers + def list_customers(self): response = requests.get(self.url+"/customers") return response.json() - #get one customer's information def get_customer(self, name=None, customer_id=None): for customer in self.list_customers(): @@ -130,7 +113,6 @@ def get_customer(self, name=None, customer_id=None): response = requests.get(self.url+f"/customers/{customer_id}") return response.json() - #Customer create, edit, delete def create_customer(self, name= "Default name", phone= "000-000-0000", postal_code= "00000"): query_params = { @@ -161,11 +143,11 @@ def update_customer(self,customer_id=None,name=None, phone=None, postal_code=Non self.url+f"/customers/{self.selected_customer['id']}", json=query_params ) - print("response:", response) #add ansi color codes here? + print("response:", response) self.selected_video = response.json() return response.json() - def delete_customer(self): #delete a customer + def delete_customer(self): response = requests.delete(self.url+f"/customers/{self.selected_customer['id']}") self.selected_video = None return response.json() From 93ce69e6a46a0d867778e864e63fdece7b523bd7 Mon Sep 17 00:00:00 2001 From: Laurel Date: Sun, 30 May 2021 00:17:16 -0700 Subject: [PATCH 7/7] purdy colors --- main.py | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index efaeaacf..b613eb6b 100644 --- a/main.py +++ b/main.py @@ -5,15 +5,42 @@ URL = "https://retro-video-store-api.herokuapp.com" def main(): - print("WELCOME TO RETRO VIDEO STORE") - pass + print(u"\u001b[34;1mWELCOME TO BRICKBUSTER\u001b[0m") + #pass if __name__ == "__main__": main() def print_stars(): - print("\n**************************\n") + + print("______________________________________________________________________") + print(u"\u001b[41m___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__") + print("_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|") + print("___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__") + print("_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|\u001b[0m") + + +def houston_we(): + print(" _______ ") + print(" _________ .----'''' ''''----. ") + print(" :______.-': : .-----------------. : ") + print(" | ______ | | : : | ") + print(" |:______B:| | | Little Error: | | ") + print(" |:______B:| | | | | ") + print(" |:______B:| | | Item not | | ") + print(" | | | | found. | | ") + print(" |:_____: | | | | | ") + print(" | == | | : : | ") + print(" | O | : '-----------------' : ") + print(" | o | :'-----...______...-----' ") + print(" | o |-._.-i_____/' \._ ") + print(" |'-.____o_| '-. '-...______...-' `-._ ") + print(" :_________: `.____________________ `-.___.-. ") + print(" .'.eeeeeeeeeeeeeeeeee.'. :___: ") + print(" fsc .'.eeeeeeeeeeeeeeeeeeeeee.'. ") + print(" :____________________________: ") + def list_options(): options = { @@ -35,12 +62,13 @@ def list_options(): } print_stars() - print("Welcome") - print("These are the actions you can perform") + print(u"\u001b[34m Good to see You") + print(" These are the actions you can perform\u001b[0m") print_stars() + #houston_we() for choice_num in options: - print(f"Option {choice_num}. {options[choice_num]}") + print(f"\u001b[34mOption {choice_num}. {options[choice_num]}\u001b[0m") print_stars() @@ -146,6 +174,8 @@ def run_cli(play=True): customer_id = input("Which customer is renting today? (please provide customer id)") video_id = input("Which video would they like to rent? (please provide video id)" ) response = video_store.check_out_video(int(customer_id), int(video_id)) + if response != 200: + houston_we() print(response) print_stars()