From 28344b7c8b1bbd4aea0e1ae5408fc9c82d0cc0eb Mon Sep 17 00:00:00 2001 From: Sahari Date: Fri, 28 May 2021 00:03:32 -0500 Subject: [PATCH 1/5] all options and classes typed out --- .gitignore | 114 ++++++++++++++++++ customer.py | 77 +++++++++++++ main.py | 327 +++++++++++++++++++++++++++++++++++++++++++++++++++- rental.py | 108 +++++++++++++++++ video.py | 77 +++++++++++++ 5 files changed, 702 insertions(+), 1 deletion(-) create mode 100644 customer.py create mode 100644 rental.py create mode 100644 video.py diff --git a/.gitignore b/.gitignore index b4d70396..9e9f4a26 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,117 @@ # Ada Library Information *.ali +.vscode +.DS_Store +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class +# C extensions +*.so +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec +# Installer logs +pip-log.txt +pip-delete-this-directory.txt +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ +# Translations +*.mo +*.pot +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal +# Flask stuff: +instance/ +.webassets-cache +# Scrapy stuff: +.scrapy +# Sphinx documentation +docs/_build/ +# PyBuilder +.pybuilder/ +target/ +# Jupyter Notebook +.ipynb_checkpoints +# IPython +profile_default/ +ipython_config.py +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ +# Celery stuff +celerybeat-schedule +celerybeat.pid +# SageMath parsed files +*.sage.py +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ +# Spyder project settings +.spyderproject +.spyproject +# Rope project settings +.ropeproject +# mkdocs documentation +/site +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json +# Pyre type checker +.pyre/ +# pytype static type analyzer +.pytype/ +# Cython debug symbols +cython_debug/ \ No newline at end of file diff --git a/customer.py b/customer.py new file mode 100644 index 00000000..30975d31 --- /dev/null +++ b/customer.py @@ -0,0 +1,77 @@ +import requests +import datetime + +class Customer: + def __init__(self, url="http://localhost:5000", selected_customer=None): + self.url = url + self.selected_customer = selected_customer + + def create_customer(self,name="Default Name",postal_code="postal code",phone="Default Phone"): + query_params = { + "name": name, + "postal_code": postal_code, + "phone": phone + } + response = requests.post(self.url+"/customers",json=query_params) + return response.json() + + def list_customers(self): + response = requests.get(self.url+"/customers") + return response.json() + + def get_customer(self, name=None, id=None): + + for customer in self.list_customers(): + if customer: + if customer["name"]==name: + id = customer["id"] + self.selected_customer = customer + elif id == customer["id"]: + self.selected_customer = customer + + if self.selected_customer == None: + return "Could not find customer by that name or id" + + response = requests.get(self.url+f"/customers/{id}") + return response.json() + + def update_customer(self,name=None,postal_code=None,phone=None): + if not name: + name = self.selected_customer["name"] + if not postal_code: + postal_code = self.selected_customer["postal_code"] + if not phone: + phone=self.phone["phone"] + + query_params = { + "name": name, + "postal_code": postal_code, + "phone":phone + #"completed_at": self.selected_task["is_complete"] + } + response = requests.put( + self.url+f"/customers/{self.selected_customer['id']}", + json=query_params + ) + print("response:", response) + self.selected_customer = response.json()["customer"] + return response.json() + + def delete_customer(self): + response = requests.delete(self.url+f"/customers/{self.selected_customer['id']}") + self.selected_customer = None + return response.json() + + # def mark_complete(self): + # response = requests.patch(self.url+f"/tasks/{self.selected_task['id']}/mark_complete") + # self.selected_task = response.json()["task"] + # return response.json() + + # def mark_incomplete(self): + # response = requests.patch(self.url+f"/tasks/{self.selected_task['id']}/mark_incomplete") + # self.selected_task = response.json()["task"] + # return response.json() + + def print_selected(self): + if self.selected_video: + print(f"Customer with id {self.selected_customer['id']} is currently selected\n") \ No newline at end of file diff --git a/main.py b/main.py index ed3f1a77..4e816dc1 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,7 @@ import requests +from video import Video +from customer import Customer +from rental import Rental URL = "http://127.0.0.1:5000" BACKUP_URL = "https://retro-video-store-api.herokuapp.com" @@ -9,4 +12,326 @@ def main(): if __name__ == "__main__": - main() \ No newline at end of file + main() + + +def print_stars(): + print("\n**************************\n") + +def list_options(): + + options = { + "1": "add a video", #done + "2": "edit a video", #done + "3": "delete a video", #done + "4": "get information about all videos", #done + "5": "get information about one video", #select a video #done + "6": "add a customer", #done + "7": "edit a customer", #done + "8": "Delete a customer", #done + "9": "get information about one customer", #select a customer # done + "10": "get information about all customers", # done + "11": "check out a video to a customer", + "12": "check in a video from a customer", + "13": "List all options",#done + "14": "Quit" #done + } + + print_stars() + print("Welcome to the Video Store CLI") + 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,customer,rental): + valid_choices = options.keys() + choice = None + + while choice not in valid_choices: + print("What would you like to do? Select 13 to see all options again") + choice = input("Make your selection using the option number 1-14: ") + + if choice in ['2','3'] and video.selected_video == None: + print("You must get information about one video before updating it or deleting it.") + print("Let's get information about one video") + choice = "5" + + if choice in ['7','8'] and customer.selected_customer == None: + print("You must get information about a customer before updating it or deleting it.") + print("Let's get information about one customer") + choice = "9" + + return choice + +def run_cli(play=True): + video=Video(url="https://retro-video-store-api.herokuapp.com/") + customer=Customer(url="https://retro-video-store-api.herokuapp.com/") + rental=Rental(url="https://retro-video-store-api.herokuapp.com/") + # print choices + options = list_options() + + while play==True: + + # get input and validate + choice = make_choice(options, video,customer,rental) + + options.print_selected() + video.print_selected() + customer.print_selected() + rental.print_selected() + + if choice=='4': #get information about all videos + print_stars() + for video in video.list_videos(): + print(video) + elif choice=='1': #add a video + print("Great! Let's add a video.") + title=input("What is the title of your video? ") + release_date=input("Enter release date") + total_inventory=input("Enter total inventory for this video") + response = video.create_video(title=title, release_date=release_date,total_inventory=total_inventory) + + print_stars() + print("New video:", response["video"]) + + elif choice=='5': + select_by = input("Would you like to select by? Enter title or id: ") + if select_by=="title": + title = input("Which video title would you like to select? ") + video.get_video(title=title) + elif select_by=="id": + id = input("Which video id would you like to select? ") + if id.isnumeric(): + id = int(id) + video.get_video(id=id) + else: + print("Could not select. Please enter id or title.") + + if video.selected_video: + print_stars() + print("Selected video: ", video.selected_video) + + elif choice=='2': + print(f"Great! Let's update the video information: {video.selected_video}") + title=input("What is the new title of your video? ") + release_date=input("Enter Release Date: ") + total_inventory=input("Enter total inventory: ") + response = video.update_video(title=title, release_date=release_date, total_inventory=total_inventory) + + print_stars() + print("Updated resonse:", response["video"]) + elif choice=='3': + video.delete_video() + + print_stars() + print("Video has been deleted.") + + print_stars() + print(video.list_videos()) + + elif choice=='10': + print_stars() + for customer in customer.list_customers(): + print(customer) + + elif choice=='6': + print("Great! Let's add a customer.") + name=input("What is the name of your video? ") + postal_code=input("Enter postal_code: ") + phone=input("Enter phone: ") + response = customer.create_customer(name=name, postal_code=postal_code, phone=phone) + + print_stars() + print("New customer:", response["customer"]) + + elif choice=='9': + select_by = input("Would you like to select by? Enter name or id: ") + if select_by=="name": + name = input("Which customer name would you like to select? ") + customer.get_customer(name=name) + elif select_by=="id": + id = input("Which customer id would you like to select? ") + if id.isnumeric(): + id = int(id) + customer.get_customer(id=id) + else: + print("Could not select. Please enter id or name.") + + if customer.selected_customer: + print_stars() + print("Selected customer: ", customer.selected_customer) + + elif choice=='7': + print(f"Great! Let's update the customer information: {customer.selected_customer}") + name=input("What is the new name of your customer? ") + postal_code=input("Enter Postal Code: ") + phone=input("phone: ") + response = customer.update_customer(name=name, postal_code=postal_code, phone=phone) + + print_stars() + print("Updated resonse:", response["customer"]) + + elif choice=='8': + customer.delete_customer() + + print_stars() + print("Customer has been deleted.") + + print_stars() + print(customer.list_customers()) + + elif choice == '11': #check out video to customer + print_stars() + print("Let's checkout a video! ") + + print("Here are all of the available videos: ") + all_videos = video.list_videos() + + for video in all_videos: + print(f"Id: {video['id']},Title: {video['title']}") + + select_by = input("What would you like to select by? Enter either a title or id: ") + + if select_by == "title": + title = input("which video title would you like to select? ") + video.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.selected_video = video.get_video(id=video_id) + + else: + print("please enter a valid video ID: ") + + if video.selected_video: + print_stars() + print("The choosen video information is: ", video.selected_video) + print(video.selected_video) + + print("Here are all of the customers: ") + + all_customers = customer.list_customers() + + for customer in all_customers: + print(f"Id: {customer['id']}, name: {customer['name']}") + + select_by = input("What would you like to select by? Enter either a name or an id: ") + if select_by == "name": + name = input("Which customer name would you like to select? ") + customer.get_customer(name=name) + elif select_by == "id": + customer_id = input("Which customer ID would you like to select? ") + if customer_id.isnumeric(): + customer_id = int(customer_id) + customer.selected_customer = customer.get_customer(id=customer_id) + + else: + print("Please enter valid customer ID: ") + + if customer.selected_customer: + print_stars() + print("Selected customer: ", customer.selected_customer) + response = rental.create_rental(customer_id = customer_id,video_id=video_id) + print("Video successfully checked out! ") + + elif choice == '12': + print_stars() + print("Let's return a video! ") + + print("Here are all of the available videos: ") + all_videos = video.list_videos() + + for video in all_videos: + print(f'Id: {video["id"]}, Title:{video["title"]}') + + select_by = input("What would you like to select by? Enter either a title or id? ") + if select_by == "title": + title = input("which video title would you like to select? ") + video.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.selected_video = video.get_video(id=video_id) + + else: + print("Please enter a valid video ID: ") + + if video.selected_video: + print_stars() + print("Selected Video Information is: ", video.selected_video) + print(video.selected_video) + + print("Here are all of the customers: ") + all_customers = customer.list_customers() + + for customer in all_customers: + print(f'id:{customer["id"]},name: {customer["name"]}') + #print(f'ID: {customer['id']}, name: {customer['name']}') + + select_by = input("What would you like to select by? Enter either a name or an ID: ") + if select_by == "name": + name = input("Which customer name would you like to select? ") + customer.get_customer(name=name) + elif select_by == "id": + customer_id = input("Which customer ID would you like to select? ") + if customer_id.isnumeric(): + customer_id = int(customer_id) + customer.selected_customer = customer.get_customer(id=customer_id) + else: + print("Please enter valid Customer ID: ") + + if customer.selected_customer: + print_stars + print("Selected customer: ", customer.selected_customer) + response = rental.return_rental(customer_id=customer_id, video_id = video_id) + print("Video sucessfully checked in! ") + # all_customers = customer_list.list_customers() + + # for customer in all_customers: + # print(f"Id:{customer['id']},name:{customer['name']}") + + # select_by = input("What would you like to select by? Enter either a name or an id: ") + # if select_by == "id": + # customer_id = input("Which customer ID would you like to select?") + # if customer_id.isnumeric(): + # customer_id = int(customer_id) + # customer_list.selected_customer = customer_list.get_customer(id=customer_id) + + # else: + # print("Please enter valid customer ID: ") + + # if customer_list.selected_customer: + + # print("Selected customer: ", customer_list.selected_customer) + + # response = rental_list.return_rental(customer_id=customer_id,video_id=video_id) + # print("Video successfully checked in! ") + + + # rental.check_out() + # pass + + + + + + elif choice=='13': + list_options() + elif choice=='14': + play=False + print("\nThanks for using the Retro Video CLI!") + + print_stars() + +run_cli() \ No newline at end of file diff --git a/rental.py b/rental.py new file mode 100644 index 00000000..7e89a1e7 --- /dev/null +++ b/rental.py @@ -0,0 +1,108 @@ +import requests +import datetime + +class Rental: + def __init__(self, url="http://localhost:5000", selected_rental=None): + self.url = url + self.selected_rental = selected_rental + #start + def check_out(self,customer_id=None,video_id=None): + query_params = { + "customer_id": customer_id, + "video_id": video_id + } + response = requests.post(self.url+"/rentals/check-out",json=query_params) + return response.json() + + + + def check_in(self,customer_id=None,video_id=None): + query_params = { + "customer_id":customer_id, + "video_id": video_id + } + response = requests.post(self.url+"/rentals/check-in",json=query_params) + return response.json() + # def check_in(self): + # response = requests.get(self.url+"/rentals/check-in") + # return response.json() + + # def check_out(self): + # response = requests.get(self.url+"/rentals/check-out") + # return response.json() + + # def list_rentals(self): + # response=requests.get(self.url+"/rentals") + # return response.json() + + # def get_rental(self,customer_id=None,video_id=None): + # for rental in self.list_rentals(): + # if rental: + # if rental["customer_id"]==customer_id and rental["video_id"]==video_id: + # id=rental["id"] + # self.selected_rental=rental + # elif id==rental["id"]: + # self.selected_rental=rental + + # if self.selected_rental == None: + # return "Could not find rental by that rental id, customer id and video id" + + # response = requests.get(self.url+f"/rentals/check-in") #route ??? + # return response.json() + + # def get_customer(self, name=None, id=None): + + # for customer in self.list_customers(): + # if customer: + # if customer["name"]==name: + # id = customer["id"] + # self.selected_customer = customer + # elif id == customer["id"]: + # self.selected_customer = customer + + # if self.selected_customer == None: + # return "Could not find customer by that name or id" + + # response = requests.get(self.url+f"/customers/{id}") + # return response.json() + + # def update_customer(self,name=None,postal_code=None,phone=None): + # if not name: + # name = self.selected_customer["name"] + # if not postal_code: + # postal_code = self.selected_customer["postal_code"] + # if not phone: + # phone=self.phone["phone"] + + # query_params = { + # "name": name, + # "postal_code": postal_code, + # "phone":phone + # #"completed_at": self.selected_task["is_complete"] + # } + # response = requests.put( + # self.url+f"/customers/{self.selected_customer['id']}", + # json=query_params + # ) + # print("response:", response) + # self.selected_customer = response.json()["customer"] + # return response.json() + + # def delete_customer(self): + # response = requests.delete(self.url+f"/customers/{self.selected_customer['id']}") + # self.selected_customer = None + # return response.json() + + # # def mark_complete(self): + # # response = requests.patch(self.url+f"/tasks/{self.selected_task['id']}/mark_complete") + # # self.selected_task = response.json()["task"] + # # return response.json() + + # # def mark_incomplete(self): + # # response = requests.patch(self.url+f"/tasks/{self.selected_task['id']}/mark_incomplete") + # # self.selected_task = response.json()["task"] + # # return response.json() + + # def print_selected(self): + # if self.selected_video: + # print(f"Customer with id {self.selected_customer['id']} is currently selected\n") \ No newline at end of file diff --git a/video.py b/video.py new file mode 100644 index 00000000..d30496ee --- /dev/null +++ b/video.py @@ -0,0 +1,77 @@ +import requests +import datetime + +class Video: + def __init__(self, url="http://localhost:5000", selected_video=None): + self.url = url + self.selected_video = selected_video + + def create_video(self,title="Default Video",release_date="Default date",total_inventory=None): + 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): + response = requests.get(self.url+"/videos") + return response.json() + + def get_video(self, title=None, id=None): + + for video in self.list_videos(): + if video: + if video["title"]==title: + id = video["id"] + self.selected_video = video + elif id == video["id"]: + self.selected_video = video + + if self.selected_video == None: + return "Could not find video by that name or id" + + response = requests.get(self.url+f"/videos/{id}") + return response.json() + + def update_video(self,title=None,release_date=None,total_inventory=None): + if not title: + title = self.selected_video["title"] + if not release_date: + release_date = self.selected_video["relase_date"] + if not total_inventory: + total_inventory=self.total_inventory["total_inventory"] + + query_params = { + "title": title, + "release_date": release_date, + "total_inventory":total_inventory + #"completed_at": self.selected_task["is_complete"] + } + response = requests.put( + self.url+f"/videos/{self.selected_video['id']}", + json=query_params + ) + print("response:", response) + self.selected_video = response.json()["video"] + return response.json() + + def delete_video(self): + response = requests.delete(self.url+f"/videos/{self.selected_video['id']}") + self.selected_video = None + return response.json() + + # def mark_complete(self): + # response = requests.patch(self.url+f"/tasks/{self.selected_task['id']}/mark_complete") + # self.selected_task = response.json()["task"] + # return response.json() + + # def mark_incomplete(self): + # response = requests.patch(self.url+f"/tasks/{self.selected_task['id']}/mark_incomplete") + # self.selected_task = response.json()["task"] + # return response.json() + + def print_selected(self): + if self.selected_video: + print(f"Video with id {self.selected_video['id']} is currently selected\n") \ No newline at end of file From 4246f16cd893e4ac39aab75a2abbcff18e2f2017 Mon Sep 17 00:00:00 2001 From: Sahari Date: Fri, 28 May 2021 18:53:33 -0500 Subject: [PATCH 2/5] all methods work --- customer.py | 4 +- main.py | 131 +++++++++++++++++++++++----------------------------- video.py | 4 +- 3 files changed, 63 insertions(+), 76 deletions(-) diff --git a/customer.py b/customer.py index 30975d31..24e3b6d0 100644 --- a/customer.py +++ b/customer.py @@ -54,7 +54,7 @@ def update_customer(self,name=None,postal_code=None,phone=None): json=query_params ) print("response:", response) - self.selected_customer = response.json()["customer"] + self.selected_customer = response.json() return response.json() def delete_customer(self): @@ -73,5 +73,5 @@ def delete_customer(self): # return response.json() def print_selected(self): - if self.selected_video: + if self.selected_customer: print(f"Customer with id {self.selected_customer['id']} is currently selected\n") \ No newline at end of file diff --git a/main.py b/main.py index 4e816dc1..80c68ce2 100644 --- a/main.py +++ b/main.py @@ -82,10 +82,10 @@ def run_cli(play=True): # get input and validate choice = make_choice(options, video,customer,rental) - options.print_selected() + #options.print_selected() video.print_selected() customer.print_selected() - rental.print_selected() + #rental.print_selected() if choice=='4': #get information about all videos print_stars() @@ -94,25 +94,25 @@ def run_cli(play=True): elif choice=='1': #add a video print("Great! Let's add a video.") title=input("What is the title of your video? ") - release_date=input("Enter release date") - total_inventory=input("Enter total inventory for this video") + release_date=input("Enter release date ") + total_inventory=input("Enter total inventory for this video ") response = video.create_video(title=title, release_date=release_date,total_inventory=total_inventory) - + video_info = video.get_video(title=title, id = response['id']) print_stars() - print("New video:", response["video"]) - + print("New video:", video_info) + elif choice=='5': - select_by = input("Would you like to select by? Enter title or id: ") - if select_by=="title": + select_by = input("Would you like to select by? Enter 'title' or 'id': ") + if "title" ==select_by: title = input("Which video title would you like to select? ") video.get_video(title=title) - elif select_by=="id": + elif "id" ==select_by: id = input("Which video id would you like to select? ") if id.isnumeric(): id = int(id) video.get_video(id=id) else: - print("Could not select. Please enter id or title.") + print("Could not select. Please enter the words 'id' or 'title'.") if video.selected_video: print_stars() @@ -126,7 +126,8 @@ def run_cli(play=True): response = video.update_video(title=title, release_date=release_date, total_inventory=total_inventory) print_stars() - print("Updated resonse:", response["video"]) + print("Updated response:", response) + elif choice=='3': video.delete_video() @@ -143,13 +144,14 @@ def run_cli(play=True): elif choice=='6': print("Great! Let's add a customer.") - name=input("What is the name of your video? ") + name=input("What is the name of the customer?") postal_code=input("Enter postal_code: ") phone=input("Enter phone: ") response = customer.create_customer(name=name, postal_code=postal_code, phone=phone) + customer_info = customer.get_customer(name = name, id = response['id']) print_stars() - print("New customer:", response["customer"]) + print("New customer:", customer_info) elif choice=='9': select_by = input("Would you like to select by? Enter name or id: ") @@ -176,7 +178,7 @@ def run_cli(play=True): response = customer.update_customer(name=name, postal_code=postal_code, phone=phone) print_stars() - print("Updated resonse:", response["customer"]) + print("Updated resonse:", response) elif choice=='8': customer.delete_customer() @@ -194,10 +196,10 @@ def run_cli(play=True): print("Here are all of the available videos: ") all_videos = video.list_videos() - for video in all_videos: - print(f"Id: {video['id']},Title: {video['title']}") + for choices in all_videos: + print(f"Id: {choices['id']},Title: {choices['title']}") - select_by = input("What would you like to select by? Enter either a title or id: ") + select_by = input("What would you like to select by? Enter either title or id: ") if select_by == "title": title = input("which video title would you like to select? ") @@ -207,53 +209,59 @@ def run_cli(play=True): video_id = input("Which video ID would you like to select? ") if video_id.isnumeric(): video_id = int(video_id) - video.selected_video = video.get_video(id=video_id) + #video.selected_video = video.get_video(id=video_id) + video.get_video(id=video_id) else: print("please enter a valid video ID: ") if video.selected_video: print_stars() - print("The choosen video information is: ", video.selected_video) + print("The chosen video information is: ", video.selected_video) print(video.selected_video) print("Here are all of the customers: ") all_customers = customer.list_customers() - for customer in all_customers: - print(f"Id: {customer['id']}, name: {customer['name']}") + for person in all_customers: + print(f"Id: {person['id']}, name: {person['name']}") select_by = input("What would you like to select by? Enter either a name or an id: ") if select_by == "name": - name = input("Which customer name would you like to select? ") - customer.get_customer(name=name) + customer_name = input("Which customer name would you like to select? ") + selected_customer=customer.get_customer(name=customer_name) + print(selected_customer) + customer_id=selected_customer["id"] + video_id=video.selected_video["id"] + # video_id = selected_customer["video_id"] elif select_by == "id": customer_id = input("Which customer ID would you like to select? ") if customer_id.isnumeric(): customer_id = int(customer_id) - customer.selected_customer = customer.get_customer(id=customer_id) + #customer.selected_customer = customer.get_customer(id=customer_id) + customer.get_customer(id=customer_id) else: print("Please enter valid customer ID: ") - if customer.selected_customer: + if customer.get_customer(id=customer_id): print_stars() - print("Selected customer: ", customer.selected_customer) - response = rental.create_rental(customer_id = customer_id,video_id=video_id) - print("Video successfully checked out! ") + #print("Selected customer: ", customer.get_customer(id=customer_id)) + response = rental.check_out(customer_id,video_id) + print("Video successfully checked out! ", response) - elif choice == '12': + elif choice == '12': #check in a video from customer print_stars() print("Let's return a video! ") print("Here are all of the available videos: ") all_videos = video.list_videos() - for video in all_videos: - print(f'Id: {video["id"]}, Title:{video["title"]}') + for choices in all_videos: + print(f'Id: {choices["id"]}, Title:{choices["title"]}') - select_by = input("What would you like to select by? Enter either a title or id? ") + select_by = input("What would you like to select by? Enter either 'title' or 'id'. ") if select_by == "title": title = input("which video title would you like to select? ") video.get_video(title=title) @@ -262,70 +270,47 @@ def run_cli(play=True): video_id = input("Which video ID would you like to select? ") if video_id.isnumeric(): video_id = int(video_id) - video.selected_video = video.get_video(id=video_id) - + #video.selected_video = video.get_video(id=video_id) + video.get_video(id=video_id) else: print("Please enter a valid video ID: ") if video.selected_video: print_stars() print("Selected Video Information is: ", video.selected_video) - print(video.selected_video) + #print(video.selected_video) print("Here are all of the customers: ") all_customers = customer.list_customers() - for customer in all_customers: - print(f'id:{customer["id"]},name: {customer["name"]}') + for person in all_customers: + print(f'id:{person["id"]},name: {person["name"]}') #print(f'ID: {customer['id']}, name: {customer['name']}') select_by = input("What would you like to select by? Enter either a name or an ID: ") if select_by == "name": - name = input("Which customer name would you like to select? ") - customer.get_customer(name=name) + customer_name = input("Which customer name would you like to select? ") + selected_customer = customer.get_customer(name=customer_name) + #print(selected_customer) + customer_id=selected_customer['id'] + video_id=video.selected_video['id'] elif select_by == "id": customer_id = input("Which customer ID would you like to select? ") if customer_id.isnumeric(): customer_id = int(customer_id) - customer.selected_customer = customer.get_customer(id=customer_id) + #customer.selected_customer = customer.get_customer(id=customer_id) + customer.get_customer(id=customer_id) else: print("Please enter valid Customer ID: ") - if customer.selected_customer: - print_stars - print("Selected customer: ", customer.selected_customer) - response = rental.return_rental(customer_id=customer_id, video_id = video_id) - print("Video sucessfully checked in! ") - # all_customers = customer_list.list_customers() - - # for customer in all_customers: - # print(f"Id:{customer['id']},name:{customer['name']}") - - # select_by = input("What would you like to select by? Enter either a name or an id: ") - # if select_by == "id": - # customer_id = input("Which customer ID would you like to select?") - # if customer_id.isnumeric(): - # customer_id = int(customer_id) - # customer_list.selected_customer = customer_list.get_customer(id=customer_id) - - # else: - # print("Please enter valid customer ID: ") - - # if customer_list.selected_customer: - - # print("Selected customer: ", customer_list.selected_customer) - - # response = rental_list.return_rental(customer_id=customer_id,video_id=video_id) - # print("Video successfully checked in! ") - - - # rental.check_out() - # pass - + if customer.get_customer(id=customer_id): + print_stars() + #print("Selected customer: ", customer.selected_customer) + response = rental.check_in(customer_id, video_id) + print("Video sucessfully checked in! ", response) - elif choice=='13': list_options() elif choice=='14': diff --git a/video.py b/video.py index d30496ee..b620f3f3 100644 --- a/video.py +++ b/video.py @@ -54,7 +54,9 @@ def update_video(self,title=None,release_date=None,total_inventory=None): json=query_params ) print("response:", response) - self.selected_video = response.json()["video"] + # self.selected_video = response.json()["video"] + self.selected_video = response.json() + return response.json() def delete_video(self): From 99c22ccaaedaa1b0f96a76943628365fa95b0f62 Mon Sep 17 00:00:00 2001 From: Sahari Date: Fri, 28 May 2021 19:41:16 -0500 Subject: [PATCH 3/5] formatting done --- main.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index 80c68ce2..d7cca554 100644 --- a/main.py +++ b/main.py @@ -143,8 +143,8 @@ def run_cli(play=True): print(customer) elif choice=='6': - print("Great! Let's add a customer.") - name=input("What is the name of the customer?") + print("Great! Let's add a customer. ") + name=input("What is the name of the customer? ") postal_code=input("Enter postal_code: ") phone=input("Enter phone: ") response = customer.create_customer(name=name, postal_code=postal_code, phone=phone) @@ -199,7 +199,7 @@ def run_cli(play=True): for choices in all_videos: print(f"Id: {choices['id']},Title: {choices['title']}") - select_by = input("What would you like to select by? Enter either title or id: ") + select_by = input("What would you like to select by? Enter either 'title' or 'id': ") if select_by == "title": title = input("which video title would you like to select? ") @@ -227,11 +227,11 @@ def run_cli(play=True): for person in all_customers: print(f"Id: {person['id']}, name: {person['name']}") - select_by = input("What would you like to select by? Enter either a name or an id: ") + select_by = input("What would you like to select by? Enter either 'name' or 'id': ") if select_by == "name": customer_name = input("Which customer name would you like to select? ") selected_customer=customer.get_customer(name=customer_name) - print(selected_customer) + print(video.selected_video) customer_id=selected_customer["id"] video_id=video.selected_video["id"] # video_id = selected_customer["video_id"] @@ -249,7 +249,7 @@ def run_cli(play=True): print_stars() #print("Selected customer: ", customer.get_customer(id=customer_id)) response = rental.check_out(customer_id,video_id) - print("Video successfully checked out! ", response) + print("Video successfully checked out! Rental info: ", response) elif choice == '12': #check in a video from customer print_stars() @@ -287,7 +287,7 @@ def run_cli(play=True): print(f'id:{person["id"]},name: {person["name"]}') #print(f'ID: {customer['id']}, name: {customer['name']}') - select_by = input("What would you like to select by? Enter either a name or an ID: ") + select_by = input("What would you like to select by? Enter either 'name' or 'id': ") if select_by == "name": customer_name = input("Which customer name would you like to select? ") selected_customer = customer.get_customer(name=customer_name) @@ -307,7 +307,7 @@ def run_cli(play=True): print_stars() #print("Selected customer: ", customer.selected_customer) response = rental.check_in(customer_id, video_id) - print("Video sucessfully checked in! ", response) + print("Video sucessfully checked in! Rental Info: ", response) From 7e080bc364ccbca92ae2ca0c1c2971702b7c3cd8 Mon Sep 17 00:00:00 2001 From: Sahari Date: Fri, 28 May 2021 20:36:13 -0500 Subject: [PATCH 4/5] edits --- main.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/main.py b/main.py index d7cca554..345b5e69 100644 --- a/main.py +++ b/main.py @@ -90,7 +90,8 @@ def run_cli(play=True): if choice=='4': #get information about all videos print_stars() for video in video.list_videos(): - print(video) + print(f"Id: {video['id']},Title: {video['title']}") + #print(video) elif choice=='1': #add a video print("Great! Let's add a video.") title=input("What is the title of your video? ") @@ -101,24 +102,27 @@ def run_cli(play=True): print_stars() print("New video:", video_info) - elif choice=='5': - select_by = input("Would you like to select by? Enter 'title' or 'id': ") - if "title" ==select_by: + elif choice=='5': #select a video + select_by = input("What would you like to select by? Enter 'title' or 'id': ") + if select_by=="title": + title = input("Which video title would you like to select? ") + video.get_video(title=title) - elif "id" ==select_by: + + elif select_by=="id": id = input("Which video id would you like to select? ") if id.isnumeric(): id = int(id) video.get_video(id=id) else: print("Could not select. Please enter the words 'id' or 'title'.") - + # if selected_video: if video.selected_video: print_stars() print("Selected video: ", video.selected_video) - elif choice=='2': + elif choice=='2': #update a video print(f"Great! Let's update the video information: {video.selected_video}") title=input("What is the new title of your video? ") release_date=input("Enter Release Date: ") @@ -128,7 +132,7 @@ def run_cli(play=True): print_stars() print("Updated response:", response) - elif choice=='3': + elif choice=='3':#delete a video video.delete_video() print_stars() @@ -140,7 +144,8 @@ def run_cli(play=True): elif choice=='10': print_stars() for customer in customer.list_customers(): - print(customer) + print(f"Id: {customer['id']}, Name: {customer['name']}") + #print(customer) elif choice=='6': print("Great! Let's add a customer. ") From a4ffc1ee02acdf503969c75ecec684138123bdff Mon Sep 17 00:00:00 2001 From: Sahari Date: Fri, 28 May 2021 21:49:31 -0500 Subject: [PATCH 5/5] final --- main.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 345b5e69..8e0efadc 100644 --- a/main.py +++ b/main.py @@ -110,7 +110,7 @@ def run_cli(play=True): video.get_video(title=title) - elif select_by=="id": + elif select_by=="id" or select_by == "ID" or select_by == "Id": id = input("Which video id would you like to select? ") if id.isnumeric(): id = int(id) @@ -121,7 +121,10 @@ def run_cli(play=True): if video.selected_video: print_stars() print("Selected video: ", video.selected_video) - + else: + print("\nInvalid id or title entry,\nplease check video list to make sure video is in inventory.\nSelect option 4 for inventory info\nOr select option 1 to add this video to inventory") + + elif choice=='2': #update a video print(f"Great! Let's update the video information: {video.selected_video}") title=input("What is the new title of your video? ") @@ -159,11 +162,11 @@ def run_cli(play=True): print("New customer:", customer_info) elif choice=='9': - select_by = input("Would you like to select by? Enter name or id: ") + select_by = input("Would you like to select by? Enter 'name' or 'id': ") if select_by=="name": name = input("Which customer name would you like to select? ") customer.get_customer(name=name) - elif select_by=="id": + elif select_by=="id" or select_by == "ID" or select_by == "Id": id = input("Which customer id would you like to select? ") if id.isnumeric(): id = int(id) @@ -175,6 +178,9 @@ def run_cli(play=True): print_stars() print("Selected customer: ", customer.selected_customer) + else: + print("\nInvalid id or name entry,\nplease check customer list to make sure customer exists.\nSelect option 10 for customer list info\nOr select option 6 to add this customer") + elif choice=='7': print(f"Great! Let's update the customer information: {customer.selected_customer}") name=input("What is the new name of your customer? ")