From be1263971995817f7715f0489babc30d22cf4c1f Mon Sep 17 00:00:00 2001 From: Hannah Lumapas Date: Tue, 25 May 2021 21:38:43 -0400 Subject: [PATCH 1/8] sets up main.py --- main.py | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index ed3f1a77..54abe483 100644 --- a/main.py +++ b/main.py @@ -3,9 +3,75 @@ URL = "http://127.0.0.1:5000" BACKUP_URL = "https://retro-video-store-api.herokuapp.com" +def welcome_message(): + return("WELCOME TO RETRO VIDEO STORE") + +def list_options(): + options = { + "1": "Add a video", + "2": "Edit a video", + "3": "Delete a video", + "4": "Get information on all videos", + "5": "Get information about one video", + "6": "Add a customer", + "7": "Edit a customer", + "8": "Delete a customer", + "9": "Get information about one customer", + "10": "Get information about all customers", + "11": "Check out a video to a customer", + "12": "Check in a video from a customer", + "13": "List all options", + "14": "Quit" + } + + print("What would you like to do?") + print("**************************") + for choice_num in options: + print(f"Option {choice_num}. {options[choice_num]}") + + # do i need another prompt here like: + # print("You must select a task before updating it, deleting it, marking it complete, or marking it incomplete.") + return options + +def make_choice(options, ?): + 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: ") + + # if the choices need a video id, prompt user to select video with id + if choice in ["2", "3", "11", "12"] and video_list.selected_video == None: + print("You must select a video before updating it or deleting it.") + print("Let's select a video!") + choice = "5" + + # if the choices need a customer id, prompt user to select customer with id + if choice in ["7", "8"] and customer_list.selected_customer == None: + print("You must select a customer before updating them or deleting them.") + print("Let's select a customer!") + choice = "9" + + # if the choices need a customer id, prompt user to select customer with id + # dont know if i need this whole thing + # if choice in ["11", "12"] and video_list.selected_video == None and customer_list.selected_customer == None: + # print("Let's select a customer!") + # choice = "9" + # print("Let's select a video") + + return choice + +def print_stars(): + print("**************************") + + def main(): - print("WELCOME TO RETRO VIDEO STORE") - pass + # print("WELCOME TO RETRO VIDEO STORE") + print(welcome_message()) + response = requests.get(BACKUP_URL + "/videos") + print(response.json()) + # pass if __name__ == "__main__": From 00898b9a776c7c9dfa1f4aad93149834471482cf Mon Sep 17 00:00:00 2001 From: Hannah Lumapas Date: Wed, 26 May 2021 00:44:19 -0400 Subject: [PATCH 2/8] creates Video class & successfully requests/responds to add, edit, delete, list, get --- __pycache__/video.cpython-39.pyc | Bin 0 -> 2260 bytes main.py | 78 +++++++++++++++++++++++++++---- video.py | 78 +++++++++++++++++++++++++++++++ 3 files changed, 147 insertions(+), 9 deletions(-) create mode 100644 __pycache__/video.cpython-39.pyc create mode 100644 video.py diff --git a/__pycache__/video.cpython-39.pyc b/__pycache__/video.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8d8dd0bf97685fc125a60a83ac60325371110609 GIT binary patch literal 2260 zcmZuzOK;pZ5GJX|YBy^;P8>UK(ne?xh0@x4%ONO&00~f_D0E5MgMmU-mU69)yizEx z3oqnTa_ui@0yxJU`d@n1wWs_Aqb>Rkxv#k4LZcyPNX>ln;HGP9J%;iA&p&>?5AH9T ztPTg0hj{AGK_rvBU8s1$g@Wq|h z`!SbUdGXbe)>VCfFi@FR<=zP`?$x?f*t3@sJ#w58?%$M|kS1 zAPsL=!WsbzL-7$FN1}Bms%Y2itjLBslZp92R6R&# zI*{2(R+Lqy29+vD*j^7-%^McEo$pttZIC4SIM+$yrmzTzIkeI6F)y zg$|$Qy2uoV+K@g!A7lf~jZb&Mz$ei-jVt+U_sr951RqC2iXGN?()mrC`Hg?>yd`hl zIC5K0)4^?D!QZsb5}E3(-O!~@3mABkje+cGdp$i#^CEp#WXr{ij`gN~$6I$)mt&k3 zsO-fgt99MFRat8b*Cx!0I*J@sSBUh9tPxoUY5UlsPLnEC>2Xa*)KxhKsN|a^0jYIU zIg17zQqxu@1UJ9G{mvGjZdmXZdP9P1J}B}8vq9=67|qTtHhhP@6mMFAELf}|?vhqw={#XtoI`iyO1BZe zvp2{E`0F{6IyIyJCA0 z>xKT%lo07-P^vBPRG2ipUIzkbY(NebQr|YS8IJW`GjkvV+6GVewR7fbK0|?<8Clyt;#dZ%`rqeSZ3q0-Pm`eJ`_guck#lODW z1J=`PHgi|E|F5hF?nMJymX(1H5HC^=DG7)G@wsaf&xzFn0;GwlHeaF<>1^3(jk}5p z_Hw!Pt*Z6uG5JJ>Fn*gF>CEm`l@IKu*05*?rg0)Y)MuJYY6`gV$ZqMpab9xH#sSt{ z;>N~I} z;x?$48sEAJdon-nJ7~^4_4!RP-Let-PzlF6&_jn;xbInPZVp2t5yz1egY@VUqLNOM zwwENwrJSI@Cv87TUQE)$N>mry6&0c_^G}HjiO^pK^#zfoy@sQ1t*G5n4x2t5@SfM} o2VQTpw-fkAhH5bJ4k#^kew>-rj~&$p-&oTgP|QqEMK5sv14OvrA^-pY literal 0 HcmV?d00001 diff --git a/main.py b/main.py index 54abe483..0452512c 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,5 @@ import requests +from video import Video URL = "http://127.0.0.1:5000" BACKUP_URL = "https://retro-video-store-api.herokuapp.com" @@ -33,7 +34,7 @@ def list_options(): # print("You must select a task before updating it, deleting it, marking it complete, or marking it incomplete.") return options -def make_choice(options, ?): +def make_choice(options, video): valid_choices = options.keys() choice = None @@ -42,16 +43,16 @@ def make_choice(options, ?): choice = input("Make your selection using the option number: ") # if the choices need a video id, prompt user to select video with id - if choice in ["2", "3", "11", "12"] and video_list.selected_video == None: + if choice in ["2", "3", "11", "12"] and video.selected_video == None: print("You must select a video before updating it or deleting it.") print("Let's select a video!") choice = "5" # if the choices need a customer id, prompt user to select customer with id - if choice in ["7", "8"] and customer_list.selected_customer == None: - print("You must select a customer before updating them or deleting them.") - print("Let's select a customer!") - choice = "9" + # if choice in ["7", "8"] and customer.selected_customer == None: + # print("You must select a customer before updating them or deleting them.") + # print("Let's select a customer!") + # choice = "9" # if the choices need a customer id, prompt user to select customer with id # dont know if i need this whole thing @@ -69,9 +70,68 @@ def print_stars(): def main(): # print("WELCOME TO RETRO VIDEO STORE") print(welcome_message()) - response = requests.get(BACKUP_URL + "/videos") - print(response.json()) - # pass + # response = requests.get(BACKUP_URL + "/videos") + # print(response.json()) + + # initialize video.py + video = Video(url="https://retro-video-store-api.herokuapp.com") + + #print choices + options = list_options() + + play = True + while play == True: + + # get input and validate + choice = make_choice(options, video) + + video.print_selected() + + if choice =='1': + print("Great! Let's add a new video.") + title=input("What is the title of the video? ") + release_date=input("When was the release_date of the video? ") + total_inventory=input("What is the total inventory of the video? ") + available_inventory=input("What is the available inventory of the video? ") + response = video.add_video(title=title, release_date=release_date, total_inventory=total_inventory, available_inventory=available_inventory) + video_info = video.get_video(title=title, id=response["id"]) + print("Video added:", video_info) + + elif choice =='2': + print(f"Great! Let's update the video: {video.selected_video}") + title=input("What is the new title of the video? ") + release_date=input("What is the new release date of the video? ") + total_inventory=input("What is the new total_inventory of the video? ") + response = video.update_video(title=title, release_date=release_date, total_inventory=total_inventory) + video_info = video.get_video(title=title, id=response["id"]) + print("Updated video:", video_info) + + elif choice == '3': + video.delete_video() + print("Video has been deleted") + print(video.list_videos()) + + elif choice =='4': + print("Videos:") + print_stars() + for video in video.list_videos(): + print(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("Selected video: ", video.selected_video) if __name__ == "__main__": diff --git a/video.py b/video.py new file mode 100644 index 00000000..23ecd68e --- /dev/null +++ b/video.py @@ -0,0 +1,78 @@ +import requests +import datetime + + +class Video: + def __init__(self, url="https://retro-video-store-api.herokuapp.com",selected_video=None): + self.url = url + self.selected_video = selected_video + + # add a video + def add_video(self, title="Default Title", release_date=None, total_inventory=0, available_inventory=0): + query_params = { + "title": title, + "release_date": release_date, + "total_inventory": total_inventory, + "available_inventory": available_inventory + } + + response = requests.post(self.url+"/videos", json=query_params) + return response.json() + + # get info on all videos + def list_videos(self): + response = requests.get(self.url+"/videos") + return response.json() + + #get a video + def get_video(self, title=None, id=None): + + for video in self.list_videos(): + if title: + 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() + + # update a video + 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["release_date"] + if not total_inventory: + total_inventory = self.selected_video["total_inventory"] + + query_params = { + "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) + # not sure what next line is doing + self.selected_video = response.json() # prints + return response.json() + + # 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() + + # print selected video + def print_selected(self): + if self.selected_video: + print(f"Video with id {self.selected_video['id']} is currently selected") + else: + print("There is no selected video.") From bec4203706f3e0d39e3ddfd717e03f5d8ec89fd4 Mon Sep 17 00:00:00 2001 From: Hannah Lumapas Date: Wed, 26 May 2021 23:45:32 -0400 Subject: [PATCH 3/8] Creates Customer clas & successfully requests/responds to add, edit, delete, list, get --- __pycache__/customer.cpython-39.pyc | Bin 0 -> 2236 bytes __pycache__/video.cpython-39.pyc | Bin 2260 -> 2260 bytes customer.py | 79 ++++++++++++++++++++++++++++ main.py | 68 ++++++++++++++++++++---- 4 files changed, 138 insertions(+), 9 deletions(-) create mode 100644 __pycache__/customer.cpython-39.pyc create mode 100644 customer.py diff --git a/__pycache__/customer.cpython-39.pyc b/__pycache__/customer.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8cb01d24759aec4816f271206c7f35720f6c6356 GIT binary patch literal 2236 zcmZuzOK;>v5bl>9$C*4gPj*=>kPs6{=7z)yt&jrZ0Gi9fWh7+0Q(od(XY6!)7G>m! zLvrO8z)Hz6C;pGGocIfoKvcD7JdUMQkbxqY*k506_>@ys{E&uiN$4iX;O`G{4 zaq|^U^C2$4fTyfie|e98%RqpO zI`Rn;=!hsK@IU3bD%b$s8VC?OtW+R>7w1mtT*+&4P<3z6jbU^WS4(+jiYN{H8N`*7 zA7{h()^Ch6H@s2-^9++(unS^SMk9Qgq?@Hat zJjxcDHee|dCA(tR>}&SZ=jXEI`ZEgN9)|I?(9e+;d+ZzoN_lze+0fz%^1S8@gA8=i z1^I#%;tFL43REfnU~e(-=(sA?m1BeMbZvwxk-&KWC>x~^46`D5l?)-6CS&mOEGUkn zBB0y|G94svyEMy&PTSRcXt&LKi=W=1ZG&IinM;NDkX3n8)%snSZXo&%q~Xi6FoDN- z%Yw^9i!0vZp78AIb0xO<_;G{u!@Cd4qd{Av){>hQ#0NVY;)6R z6_@eiv^Jh0zGU(wHS0$4p9*|NFJb!ZR1QRj=0rRPD;vA ze3Og+T;&U&k9Qk9?aIdD(#jsw&zng&4*P&D<^f&;Y)eBHpnH_0MS{;a-FTO(%KNf5?K#EEwpWjP@_&2y?EnA( literal 0 HcmV?d00001 diff --git a/__pycache__/video.cpython-39.pyc b/__pycache__/video.cpython-39.pyc index 8d8dd0bf97685fc125a60a83ac60325371110609..dbafe1f814e569d034146cf4d1595edd20e8e886 100644 GIT binary patch delta 20 acmca2ctwyqk(ZZ?0SNfm*Kg!L$pHW|oCK@@ delta 20 acmca2ctwyqk(ZZ?0SI1RSi6z?BnJRJMFvg) diff --git a/customer.py b/customer.py new file mode 100644 index 00000000..09dafbf1 --- /dev/null +++ b/customer.py @@ -0,0 +1,79 @@ +import requests +import datetime + + +class Customer: + def __init__(self, url="https://retro-video-store-api.herokuapp.com",selected_customer=None): + self.url = url + self.selected_customer = selected_customer + + # add a customer + def add_customer(self, name=None, postal_code=None, phone=None): + query_params = { + "name": name, + "postal_code": postal_code, + "phone": phone + } + + response = requests.post(self.url+"/customers", json=query_params) + return response.json() + + # get info on all customers + def list_customers(self): + response = requests.get(self.url+"/customers") + return response.json() + + # get a customer by id + def get_customer_by_id(self, name=None, id=None): + + for customer in self.list_customers(): + if name: + if customer["name"]==name: + id = customer["id"] + # assigning attribute to the data customer (an iteration in the list of customers) + self.selected_customer = customer + elif id == customer["id"]: + self.selected_customer = customer + # ^ if there was no customer found by id or title -> self.selected_customer = None + 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() + + # update a customer + def update_customer(self, name=None, postal_code=None, phone=None): + # if these attributes aren't given, will assign them the same value as before(keep it the same) + if not name: + name = self.selected_customer["name"] + if not postal_code: + postal_code = self.selected_customer["postal_code"] + if not phone: + phone = self.selected_customer["phone"] + + query_params = { + "name": name, + "postal_code": postal_code, + "phone": phone + } + response = requests.put( + self.url+f"/customers/{self.selected_customer['id']}", + json=query_params + ) + print("response:", response) + # not sure what next line is doing + self.selected_customer = response.json() # prints + return response.json() + + # delete a customer + def delete_customer(self): + response = requests.delete(self.url+f"/customers/{self.selected_customer['id']}") + self.selected_customer = None + return response.json() + + # print selected customer + def print_selected(self): + if self.selected_customer: + print(f"Customer with id {self.selected_customer['id']} is currently selected") + else: + print("There is no selected customer.") diff --git a/main.py b/main.py index 0452512c..982e6602 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,6 @@ import requests from video import Video +from customer import Customer URL = "http://127.0.0.1:5000" BACKUP_URL = "https://retro-video-store-api.herokuapp.com" @@ -34,7 +35,7 @@ def list_options(): # print("You must select a task before updating it, deleting it, marking it complete, or marking it incomplete.") return options -def make_choice(options, video): +def make_choice(options, video, customer): valid_choices = options.keys() choice = None @@ -43,16 +44,16 @@ def make_choice(options, video): choice = input("Make your selection using the option number: ") # if the choices need a video id, prompt user to select video with id - if choice in ["2", "3", "11", "12"] and video.selected_video == None: + if choice in ["2", "3"] and video.selected_video == None: print("You must select a video before updating it or deleting it.") print("Let's select a video!") choice = "5" # if the choices need a customer id, prompt user to select customer with id - # if choice in ["7", "8"] and customer.selected_customer == None: - # print("You must select a customer before updating them or deleting them.") - # print("Let's select a customer!") - # choice = "9" + if choice in ["7", "8"] and customer.selected_customer == None: + print("You must select a customer before updating them or deleting them.") + print("Let's select a customer!") + choice = "9" # if the choices need a customer id, prompt user to select customer with id # dont know if i need this whole thing @@ -66,15 +67,15 @@ def make_choice(options, video): def print_stars(): print("**************************") - def main(): # print("WELCOME TO RETRO VIDEO STORE") print(welcome_message()) # response = requests.get(BACKUP_URL + "/videos") # print(response.json()) - # initialize video.py + # initialize video.py & customer.py video = Video(url="https://retro-video-store-api.herokuapp.com") + customer = Customer(url="https://retro-video-store-api.herokuapp.com") #print choices options = list_options() @@ -83,9 +84,10 @@ def main(): while play == True: # get input and validate - choice = make_choice(options, video) + choice = make_choice(options, video, customer) video.print_selected() + customer.print_selected() if choice =='1': print("Great! Let's add a new video.") @@ -105,6 +107,7 @@ def main(): response = video.update_video(title=title, release_date=release_date, total_inventory=total_inventory) video_info = video.get_video(title=title, id=response["id"]) print("Updated video:", video_info) + print(video.selected_video) elif choice == '3': video.delete_video() @@ -133,6 +136,53 @@ def main(): if video.selected_video: print("Selected video: ", video.selected_video) + elif choice == '6': + print("Great! Let's add a new customer.") + name=input("What is the name of the customer? ") + postal_code=input(f"What is {name}'s postal code? ") + phone=input(f"What {name}'s phone number? ") + response = customer.add_customer(name=name, postal_code=postal_code, phone=phone) + customer_info = customer.get_customer_by_id(name=name, id=response["id"]) + print("Customer added:", customer_info) + + elif choice == '7': + print(f"Great! Let's update the customer: {customer.selected_customer}") + name=input("What is the new name of the customer? ") + postal_code=input("What is the new postal code of the customer? ") + phone=input("What is the new phone number of the customer? ") + response = customer.update_customer(name=name, postal_code=postal_code, phone=phone) + customer_info = customer.get_customer_by_id(name=name, id=response["id"]) + print("Updated customer:", customer_info) + print(customer.selected_customer) + + elif choice == '8': + customer.delete_customer() + print("Customer has been deleted") + print(customer.list_customers()) + + elif choice == '9': + select_by = input("Would you like to select by? Enter name or id: ") + if select_by == "name": + name = input("Which video name would you like to select? ") + customer.get_customer_by_id(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_by_id(id=id) + else: + print("Could not select. Please enter name or id.") + + if customer.selected_customer: + print("Selected customer: ", customer.selected_customer) + + elif choice == '10': + print("Customers:") + print_stars() + for customer in customer.list_customers(): + print(customer) + + if __name__ == "__main__": main() \ No newline at end of file From 6ff92700639855f4119812cf02a030ae74116496 Mon Sep 17 00:00:00 2001 From: Hannah Lumapas Date: Thu, 27 May 2021 15:11:09 -0400 Subject: [PATCH 4/8] Creates Rental class & completes option 11 and 12 --- __pycache__/rental.cpython-39.pyc | Bin 0 -> 1073 bytes main.py | 70 ++++++++++++++++++++++++++++-- rental.py | 28 ++++++++++++ 3 files changed, 94 insertions(+), 4 deletions(-) create mode 100644 __pycache__/rental.cpython-39.pyc create mode 100644 rental.py diff --git a/__pycache__/rental.cpython-39.pyc b/__pycache__/rental.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9302eca5aad93d3b72848da2c7cae88657db78c0 GIT binary patch literal 1073 zcmb_aF>ljA6uvtXE!B8jGT4fJwHFc?|biFvcDfOT(5q7d-us>>^r?|F7&bIxXl9u zV8C-WX-_`kFBu5%t{8Y9#6$pp!v_9OjAP@JaC6<}d4yiYCL9?4u?rsfSA60@1RV&_ z@?j5lAVjMJ0`qlU@LCl%$*&(zt*y+HIM&MQa(JGBDu>3FS`Cvb8%>oiPwS+rMrk=8 zr~U>x*#h?q+~x>j$(KyBr9k8j3Sh{^#{y!AcQQE`_Br&LSm6w&$aiz-{rZw@V_%zS3Br0)KUAR!ntjMgC zl+sX2#shp7y|xXb_4kxIx?U7aLYfL6qJb6SeS8*|o@Fzvb|yd^v!w^#M{(&d{V(2E zs@NZ|gxg!!C^K+jBMq&^-5XUVPNyn89hS9Sap%uWS*&~)YIRmCV~z8x(%7~QJ!D>W z^bQ`nOR$gNx)`W0WR>V-ZsG!qo^D2SrQhm?JEyATqq YY=(nPk^f5J!ly0$GfsIZS;#~28 Date: Fri, 28 May 2021 20:52:09 -0400 Subject: [PATCH 5/8] Refactored slightly, everything works again --- __pycache__/customer.cpython-39.pyc | Bin 2236 -> 2236 bytes __pycache__/rental.cpython-39.pyc | Bin 1073 -> 1073 bytes __pycache__/video.cpython-39.pyc | Bin 2260 -> 2256 bytes main.py | 223 ++++++++++++++++++++++------ rental.py | 4 +- video.py | 3 +- 6 files changed, 182 insertions(+), 48 deletions(-) diff --git a/__pycache__/customer.cpython-39.pyc b/__pycache__/customer.cpython-39.pyc index 8cb01d24759aec4816f271206c7f35720f6c6356..6206c56a7312b272ba596d9bd76c440b6cbcc9ce 100644 GIT binary patch delta 20 acmdlZxJQsXk(ZZ?0SI0vY}m-XkploX0tK4@ delta 20 acmdlZxJQsXk(ZZ?0SM}O*Kg$B$N>N{7X;e? diff --git a/__pycache__/rental.cpython-39.pyc b/__pycache__/rental.cpython-39.pyc index 9302eca5aad93d3b72848da2c7cae88657db78c0..212e6d221c49bfe2bd029143855001de40a1a6d0 100644 GIT binary patch delta 22 ccmdnUv5|u}k(ZZ?0SMmNY)n|WkynKU06((@&j0`b delta 22 ccmdnUv5|u}k(ZZ?0SG*vtxuS=kynKU06we*x&QzG diff --git a/__pycache__/video.cpython-39.pyc b/__pycache__/video.cpython-39.pyc index dbafe1f814e569d034146cf4d1595edd20e8e886..2d5b636f48988b2bbc0b614859362c5ed8289605 100644 GIT binary patch delta 59 zcmca2ctMaik(ZZ?0SK&=HYB8P>jKt=lap94F>x_YHe*}K=rZ{M T+e=2T$*0)&GKx>`;P3zdLERIF diff --git a/main.py b/main.py index c5bcc01e..42f0080a 100644 --- a/main.py +++ b/main.py @@ -45,16 +45,36 @@ def make_choice(options, video, customer): choice = input("Make your selection using the option numbers 1-14: ") # if the choices need a video id, prompt user to select video with id - if choice in ["2", "3"] and video.selected_video == None: - print("You must select a video before updating it or deleting it.") - print("Let's select a video!") - choice = "5" + # if choice in ["2", "3"] and video.selected_video == None: + # print("You must select a video before updating it or deleting it.") + # print("Let's select a video!") + # -------- shubha's suggestions, delete if breaks things -------- # + # 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("Selected video: ", video.selected_video) + # make this into a helper function + # should this be a helper function in the class or in the main? + # prob main if it prints stuff out and takes input??? idk + # -------- shubha's suggestions, delete if breaks things -------- # + # uncomment choice = 5 if it breaks + # choice = "5" # if the choices need a customer id, prompt user to select customer with id - if choice in ["7", "8"] and customer.selected_customer == None: - print("You must select a customer before updating them or deleting them.") - print("Let's select a customer!") - choice = "9" + # if choice in ["7", "8"] and customer.selected_customer == None: + # print("You must select a customer before updating them or deleting them.") + # print("Let's select a customer!") + # choice = "9" # might not need a elif for 11 or 12 # if the choices need a customer id, prompt user to select customer with id @@ -66,12 +86,55 @@ def make_choice(options, video, customer): return choice +def select_video(video): + 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("Selected video: ", video.selected_video) + else: + print("ID not found") + return None + + return video.selected_video + +def select_customer(customer): + 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_by_id(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_by_id(id=id) + else: + print("Could not select. Please enter id or title.") + + if customer.selected_customer: + print("Selected customer: ", customer.selected_customer) + else: + print("ID not found") + return None + + return customer.selected_customer + def print_stars(): print("**************************") def main(play=True): # print("WELCOME TO RETRO VIDEO STORE") print(welcome_message()) + # print(blockbuster_header()) # response = requests.get(BACKUP_URL + "/videos") # print(response.json()) @@ -89,8 +152,8 @@ def main(play=True): # get input and validate choice = make_choice(options, video, customer) - video.print_selected() - customer.print_selected() + # video.print_selected() # do i need this still ?? + # customer.print_selected() if choice =='1': print("Great! Let's add a new video.") @@ -103,6 +166,28 @@ def main(play=True): print("Video added:", video_info) elif choice =='2': + # ----- made this into helper function --------# + # 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("Selected video: ", video.selected_video) + # else: + # print("ID not found") + # break + # ----- made this into helper function --------# + if select_video(video) is None: + break + print("------------------------------------") print(f"Great! Let's update the video: {video.selected_video}") title=input("What is the new title of the video? ") release_date=input("What is the new release date of the video? ") @@ -110,9 +195,32 @@ def main(play=True): response = video.update_video(title=title, release_date=release_date, total_inventory=total_inventory) video_info = video.get_video(title=title, id=response["id"]) print("Updated video:", video_info) - print(video.selected_video) + # this lines clears out the selected video after being done with the put request + video.selected_video = None + # print(video.selected_video) elif choice == '3': + # 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("Selected video: ", video.selected_video) + # else: + # print("ID not found") + # break + # ----- made this into helper function --------# + if select_video(video) is None: + break + print("------------------------------------") video.delete_video() print("Video has been deleted") print(video.list_videos()) @@ -120,24 +228,34 @@ def main(play=True): elif choice =='4': print("Videos:") print_stars() - for video in video.list_videos(): - print(video) + for each_video in video.list_videos(): + print(each_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.") + # 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("Selected video: ", video.selected_video) + # if video.selected_video: + # print("Selected video: ", video.selected_video) + # try to do this to clear video after selected ... delete if it breaks + # yeah cant do this bc the others rely on it... for now. + # try to get the other options not to rely on it by doing the logic in make choice + # video.selected_video = None + + # video.print_selected() + + select_video(video) + +# ---------------------customers---------------------- # elif choice == '6': print("Great! Let's add a new customer.") @@ -149,6 +267,9 @@ def main(play=True): print("Customer added:", customer_info) elif choice == '7': + if select_customer(customer) is None: + break + print("------------------------------------") print(f"Great! Let's update the customer: {customer.selected_customer}") name=input("What is the new name of the customer? ") postal_code=input("What is the new postal code of the customer? ") @@ -156,36 +277,44 @@ def main(play=True): response = customer.update_customer(name=name, postal_code=postal_code, phone=phone) customer_info = customer.get_customer_by_id(name=name, id=response["id"]) print("Updated customer:", customer_info) - print(customer.selected_customer) + customer.selected_customer = None + # print(customer.selected_customer) elif choice == '8': + if select_customer(customer) is None: + break + print("------------------------------------") customer.delete_customer() print("Customer has been deleted") # print(customer.list_customers()) 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_by_id(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_by_id(id=id) - else: - print("Could not select. Please 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_by_id(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_by_id(id=id) + # else: + # print("Could not select. Please enter name or id.") - if customer.selected_customer: - print("Selected customer: ", customer.selected_customer) + # if customer.selected_customer: + # print("Selected customer: ", customer.selected_customer) + # customer.selected_customer = None + select_customer(customer) elif choice == '10': print("Customers:") print_stars() - for customer in customer.list_customers(): - print(customer) + for each_customer in customer.list_customers(): + print(each_customer) + elif choice == '11': + print(rental) print("You are checking out a video to a customer: ") video_id = input("Enter the video id: ") # check if it is a valid id @@ -200,15 +329,17 @@ def main(play=True): if customer_id.isnumeric(): customer_id = int(customer_id) # assign to selected_customer + print(f"test:{customer}") customer.selected_customer = customer.get_customer_by_id(id=customer_id) print(customer.selected_customer) # make a post request for checking out the id and plugging the instance of video and customer on there - rental = rental.check_out_video(customer_id=customer_id, video_id=video_id) - print(f"Rental info: {rental}") + checked_out = rental.check_out_video(customer_id=customer_id, video_id=video_id) + print(f"Rental info: {checked_out}") print(f"{video.selected_video['title']} successfully checked out to {customer.selected_customer['name']}") elif choice == '12': + print(rental) print("You are checking in a video from a customer: ") video_id = input("Enter the video id: ") # check if it is a valid id @@ -226,8 +357,8 @@ def main(play=True): customer.selected_customer = customer.get_customer_by_id(id=customer_id) print(customer.selected_customer) - rental = rental.check_in_video(customer_id=customer_id, video_id=video_id) - print(f"Rental info: {rental}") + checked_in = rental.check_in_video(customer_id=customer_id, video_id=video_id) + print(f"Rental info: {checked_in}") print(f"{customer.selected_customer['name']} successfully checked in {video.selected_video['title']}") elif choice == '13': diff --git a/rental.py b/rental.py index 799c46b6..a77fbe9a 100644 --- a/rental.py +++ b/rental.py @@ -25,4 +25,6 @@ def check_in_video(self, customer_id=None, video_id=None): } response = requests.post(self.url+"/rentals/check-in", json=query_params) - return response.json() \ No newline at end of file + return response.json() + + # get rental \ No newline at end of file diff --git a/video.py b/video.py index 23ecd68e..22bfd742 100644 --- a/video.py +++ b/video.py @@ -61,7 +61,8 @@ def update_video(self, title=None, release_date=None, total_inventory=None): ) print("response:", response) # not sure what next line is doing - self.selected_video = response.json() # prints + self.selected_video = None #response.json() # prints + # clear selected video = None return response.json() # delete a video From aa8a079aeb13db54ea2793b606bba5daf9353eae Mon Sep 17 00:00:00 2001 From: Hannah Lumapas Date: Sat, 29 May 2021 00:55:06 -0400 Subject: [PATCH 6/8] Cleans up experience & deletes extra comments --- __pycache__/rental.cpython-39.pyc | Bin 1073 -> 1073 bytes __pycache__/video.cpython-39.pyc | Bin 2256 -> 2002 bytes main.py | 369 ++++++++++++------------------ rental.py | 2 - video.py | 16 +- 5 files changed, 158 insertions(+), 229 deletions(-) diff --git a/__pycache__/rental.cpython-39.pyc b/__pycache__/rental.cpython-39.pyc index 212e6d221c49bfe2bd029143855001de40a1a6d0..5e43ce3b606b03cfa690056beb3eb786d29bae29 100644 GIT binary patch delta 22 ccmdnUv5|u}k(ZZ?0SLUeZA_TFkynKU06kg-kN^Mx delta 22 ccmdnUv5|u}k(ZZ?0SMmNY)n|WkynKU06((@&j0`b diff --git a/__pycache__/video.cpython-39.pyc b/__pycache__/video.cpython-39.pyc index 2d5b636f48988b2bbc0b614859362c5ed8289605..151c049661f2007779e51895f83e887d801ab330 100644 GIT binary patch delta 181 zcmca0c!{4kk(ZZ?0SFimZcNCV$eZfr0_3DJL@}l?L@}iZrZA_lv@k|7rwFC6r*HsS zEGe8RTrCVytSQ1N+$lUj5w;YO6y6j*Ad5YPKScm2$C1Jm%%CZ{@kkmoqsC-y7Fm{( z%#xhV-YlCLS-DbEGD{}2vKes;gk`3r=Iep^ADP4_N3$)T{El6Pk#n*zhx6oU4p{*n Xpi?*)xmdY)I9Ry^xg;icakv2hNdqdh delta 472 zcmY*WJx>Bb5Z%3RP7dTm#En6J}uwlE_$)0}oP&Y)Hd2_8iE7k7ok3LsFc3eY?;L>*ZFb2`p?$ zb`gZYZUW#fcHU*OQIjmJT@QDRA+?j8Hq<1Kzs*h0KUSL3nAx)4`*o^D9f!gOW*IZu zz;Z{fh**{ss6wF4lP3cDvwlx02_57Og@E8pW~G<^v`b(xk%{< zwP;@JWk;L-7on|=ib~NC>W36mWD%{x~7VDJ6_ DE!S_o diff --git a/main.py b/main.py index 42f0080a..9ef968bf 100644 --- a/main.py +++ b/main.py @@ -3,13 +3,16 @@ from customer import Customer from rental import Rental -URL = "http://127.0.0.1:5000" -BACKUP_URL = "https://retro-video-store-api.herokuapp.com" def welcome_message(): return("WELCOME TO RETRO VIDEO STORE") +def print_line(): + print("--------------------------------------------------") + def list_options(): + print("\n---------------------- MENU ---------------------- ") + options = { "1": "Add a video", "2": "Edit a video", @@ -26,14 +29,10 @@ def list_options(): "13": "List all options", "14": "Quit" } - - print("What would you like to do?") - print("**************************") + for choice_num in options: print(f"Option {choice_num}. {options[choice_num]}") - - # do i need another prompt here like: - # print("You must select a task before updating it, deleting it, marking it complete, or marking it incomplete.") + return options def make_choice(options, video, customer): @@ -41,53 +40,15 @@ def make_choice(options, video, customer): choice = None while choice not in valid_choices: + print_line() print("What would you like to do? Select 13 to see all options again") choice = input("Make your selection using the option numbers 1-14: ") - - # if the choices need a video id, prompt user to select video with id - # if choice in ["2", "3"] and video.selected_video == None: - # print("You must select a video before updating it or deleting it.") - # print("Let's select a video!") - # -------- shubha's suggestions, delete if breaks things -------- # - # 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("Selected video: ", video.selected_video) - # make this into a helper function - # should this be a helper function in the class or in the main? - # prob main if it prints stuff out and takes input??? idk - # -------- shubha's suggestions, delete if breaks things -------- # - # uncomment choice = 5 if it breaks - # choice = "5" - - # if the choices need a customer id, prompt user to select customer with id - # if choice in ["7", "8"] and customer.selected_customer == None: - # print("You must select a customer before updating them or deleting them.") - # print("Let's select a customer!") - # choice = "9" - - # might not need a elif for 11 or 12 - # if the choices need a customer id, prompt user to select customer with id - # dont know if i need this whole thing - # if choice in ["11", "12"] and video_list.selected_video == None and customer_list.selected_customer == None: - # print("Let's select a customer!") - # choice = "9" - # print("Let's select a video") return choice def select_video(video): - select_by = input("Would you like to select by? Enter title or id: ") + print("Let's select a video by title or id:") + select_by = input("Which do you want to use? Enter title or id: ") if select_by == "title": title = input("Which video title would you like to select? ") video.get_video(title=title) @@ -96,47 +57,37 @@ def select_video(video): 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("Selected video: ", video.selected_video) + print(f"Selected video: \n{video.selected_video}") else: - print("ID not found") + print("Video not found. Please enter a valid title or id.") return None return video.selected_video def select_customer(customer): - select_by = input("Would you like to select by? Enter name or id: ") + print("Let's select a customer by name or id:") + select_by = input("Which do you want to use? Enter name or id: ") if select_by == "name": - name = input("Which customer name would you like to select? ") + name = input("Enter customer's name: ") customer.get_customer_by_id(name=name) elif select_by == "id": - id = input("Which customer id would you like to select? ") + id = input("Enter customer's id: ") if id.isnumeric(): id = int(id) customer.get_customer_by_id(id=id) - else: - print("Could not select. Please enter id or title.") - + if customer.selected_customer: - print("Selected customer: ", customer.selected_customer) + print(f"Selected customer: \n{customer.selected_customer}") else: - print("ID not found") + print("Customer not found. Please enter a valid name or id.") return None return customer.selected_customer -def print_stars(): - print("**************************") - def main(play=True): - # print("WELCOME TO RETRO VIDEO STORE") print(welcome_message()) - # print(blockbuster_header()) - # response = requests.get(BACKUP_URL + "/videos") - # print(response.json()) # initialize video.py & customer.py video = Video(url="https://retro-video-store-api.herokuapp.com") @@ -152,229 +103,209 @@ def main(play=True): # get input and validate choice = make_choice(options, video, customer) - # video.print_selected() # do i need this still ?? - # customer.print_selected() - if choice =='1': - print("Great! Let's add a new video.") - title=input("What is the title of the video? ") - release_date=input("When was the release_date of the video? ") - total_inventory=input("What is the total inventory of the video? ") - available_inventory=input("What is the available inventory of the video? ") + print(''' + [ ADD A VIDEO ] + ''') + print("\nGreat! Let's add a new video:") + title=input(" > What is the title of the video? ") + release_date=input(" > When was the release_date of the video? (YYYY/DD/MM) ") + total_inventory=input(" > What is the total inventory of the video? ") + available_inventory=input(" > What is the available inventory of the video? ") response = video.add_video(title=title, release_date=release_date, total_inventory=total_inventory, available_inventory=available_inventory) video_info = video.get_video(title=title, id=response["id"]) - print("Video added:", video_info) - + video.selected_video = None + print(f"Video successfully added: \n{video_info}") + elif choice =='2': - # ----- made this into helper function --------# - # 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("Selected video: ", video.selected_video) - # else: - # print("ID not found") - # break - # ----- made this into helper function --------# + print(''' + [ EDIT A VIDEO ] + ''') if select_video(video) is None: - break - print("------------------------------------") - print(f"Great! Let's update the video: {video.selected_video}") - title=input("What is the new title of the video? ") - release_date=input("What is the new release date of the video? ") - total_inventory=input("What is the new total_inventory of the video? ") - response = video.update_video(title=title, release_date=release_date, total_inventory=total_inventory) + continue + print("\nGreat! Let's edit the video:") + title=input(" > What is the new title of the video? ") + release_date=input(" > What is the new release date of the video? (YYYY/DD/MM) ") + total_inventory=input(" > What is the new total_inventory of the video? ") + print("") + response = video.edit_video(title=title, release_date=release_date, total_inventory=total_inventory) video_info = video.get_video(title=title, id=response["id"]) - print("Updated video:", video_info) + print(f"Video successfully updated: \n{video_info}") # this lines clears out the selected video after being done with the put request video.selected_video = None - # print(video.selected_video) + elif choice == '3': - # 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("Selected video: ", video.selected_video) - # else: - # print("ID not found") - # break - # ----- made this into helper function --------# + print(''' + [ DELETE A VIDEO ] + ''') if select_video(video) is None: - break - print("------------------------------------") - video.delete_video() - print("Video has been deleted") - print(video.list_videos()) + continue + print("\nYou will NEVER see this video again!!!") + response = video.delete_video() + print("Video successfully deleted.") elif choice =='4': - print("Videos:") - print_stars() + print(''' + [ GET INFORMATION ON ALL VIDEOS ] + ''') for each_video in video.list_videos(): print(each_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("Selected video: ", video.selected_video) - # try to do this to clear video after selected ... delete if it breaks - # yeah cant do this bc the others rely on it... for now. - # try to get the other options not to rely on it by doing the logic in make choice - # video.selected_video = None - - # video.print_selected() - + print(''' + [ GET INFORMATION ON ONE VIDEO ] + ''') select_video(video) # ---------------------customers---------------------- # elif choice == '6': - print("Great! Let's add a new customer.") - name=input("What is the name of the customer? ") - postal_code=input(f"What is {name}'s postal code? ") - phone=input(f"What {name}'s phone number? ") + print(''' + [ ADD A CUSTOMER ] + ''') + print("\nGreat! Let's add a new customer:") + name=input(" > What is the name of the customer? ") + postal_code=input(f" > What is {name}'s postal code? ") + phone=input(f" > What {name}'s phone number? ") + print("") response = customer.add_customer(name=name, postal_code=postal_code, phone=phone) customer_info = customer.get_customer_by_id(name=name, id=response["id"]) - print("Customer added:", customer_info) + customer.selected_customer = None + print(f"Customer was successfully added: \n{customer_info}") elif choice == '7': + print(''' + [ EDIT A CUSTOMER ] + ''') if select_customer(customer) is None: - break - print("------------------------------------") - print(f"Great! Let's update the customer: {customer.selected_customer}") - name=input("What is the new name of the customer? ") - postal_code=input("What is the new postal code of the customer? ") - phone=input("What is the new phone number of the customer? ") + continue + print(f"\nGreat! Let's update the customer:") + name=input(" > What is the new name of the customer? ") + postal_code=input(" > What is the new postal code of the customer? ") + phone=input(" > What is the new phone number of the customer? ") + print("") response = customer.update_customer(name=name, postal_code=postal_code, phone=phone) customer_info = customer.get_customer_by_id(name=name, id=response["id"]) - print("Updated customer:", customer_info) + print(f"Customer {name} was successfully updated: \n{customer_info}") customer.selected_customer = None - # print(customer.selected_customer) elif choice == '8': - if select_customer(customer) is None: - break - print("------------------------------------") + print(''' + [ DELETE A CUSTOMER ] + ''') + cancelled_customer = select_customer(customer) + if cancelled_customer is None: + # break + continue + print(f"\n{cancelled_customer['name']} found out about Netflix, huh?") customer.delete_customer() - print("Customer has been deleted") - # print(customer.list_customers()) + print("Customer successfully deleted. I may lose my job at this rate.") 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_by_id(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_by_id(id=id) - # else: - # print("Could not select. Please enter name or id.") - - # if customer.selected_customer: - # print("Selected customer: ", customer.selected_customer) - # customer.selected_customer = None + print(''' + [ GET INFORMATION ON ONE CUSTOMER ] + ''') select_customer(customer) elif choice == '10': - print("Customers:") - print_stars() + print(''' + [ GET INFORMATION ON ALL CUSTOMERS ] + ''') for each_customer in customer.list_customers(): print(each_customer) +# ---------------------rentals---------------------- # elif choice == '11': - print(rental) - print("You are checking out a video to a customer: ") - video_id = input("Enter the video id: ") + print(''' + [ CHECK OUT A VIDEO TO A CUSTOMER ] + ''') + video_id = input(" > Enter the video id: ") # check if it is a valid id if video_id.isnumeric(): video_id = int(video_id) - # assign to selected_video - video.selected_video = video.get_video(id=video_id) - print(video.selected_video) + video.get_video(id=video_id) + + if video.selected_video: + print(f"Selected video: \n{video.selected_video}") + else: + print("Video not found. Please enter a valid id.") + continue - customer_id = input("Enter the customer id: ") + video.selected_video = None + customer_id = input(" > Enter the customer id: ") # check if valid id if customer_id.isnumeric(): customer_id = int(customer_id) - # assign to selected_customer - print(f"test:{customer}") - customer.selected_customer = customer.get_customer_by_id(id=customer_id) - print(customer.selected_customer) + customer.get_customer_by_id(id=customer_id) - # make a post request for checking out the id and plugging the instance of video and customer on there + if customer.selected_customer: + print(f"Selected customer: \n{customer.selected_customer}") + else: + print("Customer not found. Please enter a valid id.") + continue + customer.selected_customer = None + + print("") checked_out = rental.check_out_video(customer_id=customer_id, video_id=video_id) - print(f"Rental info: {checked_out}") - print(f"{video.selected_video['title']} successfully checked out to {customer.selected_customer['name']}") + customer_info = customer.get_customer_by_id(id=customer_id) + video_info = video.get_video(id=video_id) + print(f"Rental info: \n{checked_out}") + print(f"{video_info['title']} successfully checked out to {customer_info['name']}!") + elif choice == '12': - print(rental) - print("You are checking in a video from a customer: ") - video_id = input("Enter the video id: ") + print(''' + [ CHECK IN A VIDEO FROM A CUSTOMER ] + ''') + video_id = input(" > Enter the video id: ") # check if it is a valid id if video_id.isnumeric(): video_id = int(video_id) - # assign to selected_video - video.selected_video = video.get_video(id=video_id) - print(video.selected_video) + video.get_video(id=video_id) + + if video.selected_video: + print(f"Selected video: \n{video.selected_video}") + else: + print("Video not found. Please enter a valid id.") + continue - customer_id = input("Enter the customer id: ") + video.selected_video = None + customer_id = input(" > Enter the customer id: ") # check if valid id if customer_id.isnumeric(): customer_id = int(customer_id) - # assign to selected_customer - customer.selected_customer = customer.get_customer_by_id(id=customer_id) - print(customer.selected_customer) + customer.get_customer_by_id(id=customer_id) + + if customer.selected_customer: + print(f"Selected customer: \n{customer.selected_customer}") + else: + print("Customer not found. Please enter a valid id.") + continue + customer.selected_customer = None + print("") checked_in = rental.check_in_video(customer_id=customer_id, video_id=video_id) - print(f"Rental info: {checked_in}") - print(f"{customer.selected_customer['name']} successfully checked in {video.selected_video['title']}") + print(f"Rental info: \n{checked_in}") + print(f"{customer.selected_customer['name']} successfully checked in {video.selected_video['title']}!") + +# ---------------------etc---------------------- # elif choice == '13': list_options() elif choice == '14': - # play=False + print(''' + [ EXIT ] + ''') consent = input("\nDo you want to exit? select y/n: ") if consent == 'y': play=False print("Thank you for using the video store CLI. Good bye!") - - if consent == 'n': - choice = 13 - + if consent == 'n': + continue if __name__ == "__main__": diff --git a/rental.py b/rental.py index a77fbe9a..0d15a85f 100644 --- a/rental.py +++ b/rental.py @@ -26,5 +26,3 @@ def check_in_video(self, customer_id=None, video_id=None): response = requests.post(self.url+"/rentals/check-in", json=query_params) return response.json() - - # get rental \ No newline at end of file diff --git a/video.py b/video.py index 22bfd742..f3b02ecd 100644 --- a/video.py +++ b/video.py @@ -36,13 +36,13 @@ def get_video(self, title=None, id=None): self.selected_video = video if self.selected_video == None: - return "Could not find video by that name or id" + return "Could not find video by that title or id" response = requests.get(self.url+f"/videos/{id}") return response.json() - # update a video - def update_video(self, title=None, release_date=None, total_inventory=None): + # edit a video + def edit_video(self, title=None, release_date=None, total_inventory=None): if not title: title = self.selected_video["title"] if not release_date: @@ -72,8 +72,8 @@ def delete_video(self): return response.json() # print selected video - def print_selected(self): - if self.selected_video: - print(f"Video with id {self.selected_video['id']} is currently selected") - else: - print("There is no selected video.") + # def print_selected(self): + # if self.selected_video: + # print(f"Video with id {self.selected_video['id']} is currently selected") + # else: + # print("There is no selected video.") From fb572358a4ac849d51bba8e454a5d43eb1296292 Mon Sep 17 00:00:00 2001 From: Hannah Lumapas Date: Sat, 29 May 2021 01:12:26 -0400 Subject: [PATCH 7/8] Refactors rentals choices --- main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 9ef968bf..9f0d5e94 100644 --- a/main.py +++ b/main.py @@ -287,8 +287,10 @@ def main(play=True): print("") checked_in = rental.check_in_video(customer_id=customer_id, video_id=video_id) + customer_info = customer.get_customer_by_id(id=customer_id) + video_info = video.get_video(id=video_id) print(f"Rental info: \n{checked_in}") - print(f"{customer.selected_customer['name']} successfully checked in {video.selected_video['title']}!") + print(f"{video_info['title']} successfully checked in {customer_info['name']}!") # ---------------------etc---------------------- # From c61ed2af876fbfab6a7f1634290770e9ebf287ac Mon Sep 17 00:00:00 2001 From: Hannah Lumapas Date: Sat, 5 Jun 2021 13:34:35 -0400 Subject: [PATCH 8/8] applies PEP 8 styling to main, customer, video, rental --- customer.py | 51 +++++++------- main.py | 196 ++++++++++++++++++++++++++++++---------------------- rental.py | 22 +++--- video.py | 55 ++++++--------- 4 files changed, 174 insertions(+), 150 deletions(-) diff --git a/customer.py b/customer.py index 09dafbf1..5abd0e43 100644 --- a/customer.py +++ b/customer.py @@ -1,16 +1,15 @@ import requests -import datetime -class Customer: - def __init__(self, url="https://retro-video-store-api.herokuapp.com",selected_customer=None): - self.url = url +class Customer: + def __init__(self, url="https://retro-video-store-api.herokuapp.com", selected_customer=None): + self.url = url self.selected_customer = selected_customer - - # add a customer + + # add a customer def add_customer(self, name=None, postal_code=None, phone=None): query_params = { - "name": name, + "name": name, "postal_code": postal_code, "phone": phone } @@ -18,62 +17,62 @@ def add_customer(self, name=None, postal_code=None, phone=None): response = requests.post(self.url+"/customers", json=query_params) return response.json() - # get info on all customers - def list_customers(self): + # get info on all customers + def list_customers(self): response = requests.get(self.url+"/customers") return response.json() - + # get a customer by id def get_customer_by_id(self, name=None, id=None): - + for customer in self.list_customers(): if name: - if customer["name"]==name: + if customer["name"] == name: id = customer["id"] # assigning attribute to the data customer (an iteration in the list of customers) self.selected_customer = customer elif id == customer["id"]: self.selected_customer = customer - # ^ if there was no customer found by id or title -> self.selected_customer = None 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() - # update a customer + # update a customer def update_customer(self, name=None, postal_code=None, phone=None): # if these attributes aren't given, will assign them the same value as before(keep it the same) if not name: name = self.selected_customer["name"] if not postal_code: postal_code = self.selected_customer["postal_code"] - if not phone: + if not phone: phone = self.selected_customer["phone"] query_params = { - "name": name, - "postal_code": postal_code, - "phone": phone + "name": name, + "postal_code": postal_code, + "phone": phone } response = requests.put( self.url+f"/customers/{self.selected_customer['id']}", json=query_params - ) + ) print("response:", response) - # not sure what next line is doing - self.selected_customer = response.json() # prints + self.selected_customer = response.json() # prints return response.json() - # delete a customer + # delete a customer def delete_customer(self): - response = requests.delete(self.url+f"/customers/{self.selected_customer['id']}") + response = requests.delete( + self.url+f"/customers/{self.selected_customer['id']}") self.selected_customer = None return response.json() - - # print selected customer + + # print selected customer def print_selected(self): if self.selected_customer: - print(f"Customer with id {self.selected_customer['id']} is currently selected") + print( + f"Customer with id {self.selected_customer['id']} is currently selected") else: print("There is no selected customer.") diff --git a/main.py b/main.py index 9f0d5e94..caaa1e58 100644 --- a/main.py +++ b/main.py @@ -1,24 +1,26 @@ import requests -from video import Video +from video import Video from customer import Customer -from rental import Rental +from rental import Rental -def welcome_message(): +def welcome_message(): return("WELCOME TO RETRO VIDEO STORE") + def print_line(): print("--------------------------------------------------") + def list_options(): print("\n---------------------- MENU ---------------------- ") options = { - "1": "Add a video", + "1": "Add a video", "2": "Edit a video", - "3": "Delete a video", - "4": "Get information on all videos", - "5": "Get information about one video", + "3": "Delete a video", + "4": "Get information on all videos", + "5": "Get information about one video", "6": "Add a customer", "7": "Edit a customer", "8": "Delete a customer", @@ -28,16 +30,17 @@ def list_options(): "12": "Check in a video from a customer", "13": "List all options", "14": "Quit" - } + } - for choice_num in options: + for choice_num in options: print(f"Option {choice_num}. {options[choice_num]}") - return options + return options + def make_choice(options, video, customer): valid_choices = options.keys() - choice = None + choice = None while choice not in valid_choices: print_line() @@ -46,46 +49,49 @@ def make_choice(options, video, customer): return choice + def select_video(video): print("Let's select a video by title or id:") select_by = input("Which do you want to use? Enter title or id: ") - if select_by == "title": + if select_by == "title": title = input("Which video title would you like to select? ") video.get_video(title=title) - elif select_by == "id": + elif select_by == "id": id = input("Which video id would you like to select? ") - if id.isnumeric(): + if id.isnumeric(): id = int(id) video.get_video(id=id) - if video.selected_video: + if video.selected_video: print(f"Selected video: \n{video.selected_video}") - else: + else: print("Video not found. Please enter a valid title or id.") return None return video.selected_video + def select_customer(customer): print("Let's select a customer by name or id:") select_by = input("Which do you want to use? Enter name or id: ") - if select_by == "name": + if select_by == "name": name = input("Enter customer's name: ") customer.get_customer_by_id(name=name) - elif select_by == "id": + elif select_by == "id": id = input("Enter customer's id: ") - if id.isnumeric(): + if id.isnumeric(): id = int(id) customer.get_customer_by_id(id=id) - if customer.selected_customer: + if customer.selected_customer: print(f"Selected customer: \n{customer.selected_customer}") - else: + else: print("Customer not found. Please enter a valid name or id.") return None return customer.selected_customer + def main(play=True): print(welcome_message()) @@ -94,47 +100,57 @@ def main(play=True): customer = Customer(url="https://retro-video-store-api.herokuapp.com") rental = Rental(url="https://retro-video-store-api.herokuapp.com") - #print choices + # print choices options = list_options() - play = True - while play == True: + play = True + while play == True: - # get input and validate + # get input and validate choice = make_choice(options, video, customer) - if choice =='1': +#=====================================================# +# CUSTOMER CHOICES # +#=====================================================# + + if choice == '1': print(''' [ ADD A VIDEO ] ''') print("\nGreat! Let's add a new video:") - title=input(" > What is the title of the video? ") - release_date=input(" > When was the release_date of the video? (YYYY/DD/MM) ") - total_inventory=input(" > What is the total inventory of the video? ") - available_inventory=input(" > What is the available inventory of the video? ") - response = video.add_video(title=title, release_date=release_date, total_inventory=total_inventory, available_inventory=available_inventory) + title = input(" > What is the title of the video? ") + release_date = input( + " > When was the release_date of the video? (YYYY/DD/MM) ") + total_inventory = input( + " > What is the total inventory of the video? ") + available_inventory = input( + " > What is the available inventory of the video? ") + response = video.add_video(title=title, release_date=release_date, + total_inventory=total_inventory, available_inventory=available_inventory) video_info = video.get_video(title=title, id=response["id"]) video.selected_video = None print(f"Video successfully added: \n{video_info}") - elif choice =='2': + elif choice == '2': print(''' [ EDIT A VIDEO ] ''') if select_video(video) is None: continue print("\nGreat! Let's edit the video:") - title=input(" > What is the new title of the video? ") - release_date=input(" > What is the new release date of the video? (YYYY/DD/MM) ") - total_inventory=input(" > What is the new total_inventory of the video? ") + title = input(" > What is the new title of the video? ") + release_date = input( + " > What is the new release date of the video? (YYYY/DD/MM) ") + total_inventory = input( + " > What is the new total_inventory of the video? ") print("") - response = video.edit_video(title=title, release_date=release_date, total_inventory=total_inventory) + response = video.edit_video( + title=title, release_date=release_date, total_inventory=total_inventory) video_info = video.get_video(title=title, id=response["id"]) print(f"Video successfully updated: \n{video_info}") # this lines clears out the selected video after being done with the put request video.selected_video = None - elif choice == '3': print(''' [ DELETE A VIDEO ] @@ -145,49 +161,57 @@ def main(play=True): response = video.delete_video() print("Video successfully deleted.") - elif choice =='4': + elif choice == '4': print(''' [ GET INFORMATION ON ALL VIDEOS ] ''') - for each_video in video.list_videos(): + for each_video in video.list_videos(): print(each_video) - elif choice == '5': + elif choice == '5': print(''' [ GET INFORMATION ON ONE VIDEO ] ''') select_video(video) -# ---------------------customers---------------------- # +#=====================================================# +# CUSTOMER CHOICES # +#=====================================================# - elif choice == '6': + elif choice == '6': print(''' [ ADD A CUSTOMER ] ''') print("\nGreat! Let's add a new customer:") - name=input(" > What is the name of the customer? ") - postal_code=input(f" > What is {name}'s postal code? ") - phone=input(f" > What {name}'s phone number? ") + name = input(" > What is the name of the customer? ") + postal_code = input(f" > What is {name}'s postal code? ") + phone = input(f" > What {name}'s phone number? ") print("") - response = customer.add_customer(name=name, postal_code=postal_code, phone=phone) - customer_info = customer.get_customer_by_id(name=name, id=response["id"]) + response = customer.add_customer( + name=name, postal_code=postal_code, phone=phone) + customer_info = customer.get_customer_by_id( + name=name, id=response["id"]) customer.selected_customer = None print(f"Customer was successfully added: \n{customer_info}") - elif choice == '7': + elif choice == '7': print(''' [ EDIT A CUSTOMER ] ''') - if select_customer(customer) is None: + if select_customer(customer) is None: continue print(f"\nGreat! Let's update the customer:") - name=input(" > What is the new name of the customer? ") - postal_code=input(" > What is the new postal code of the customer? ") - phone=input(" > What is the new phone number of the customer? ") + name = input(" > What is the new name of the customer? ") + postal_code = input( + " > What is the new postal code of the customer? ") + phone = input(" > What is the new phone number of the customer? ") print("") - response = customer.update_customer(name=name, postal_code=postal_code, phone=phone) - customer_info = customer.get_customer_by_id(name=name, id=response["id"]) - print(f"Customer {name} was successfully updated: \n{customer_info}") + response = customer.update_customer( + name=name, postal_code=postal_code, phone=phone) + customer_info = customer.get_customer_by_id( + name=name, id=response["id"]) + print( + f"Customer {name} was successfully updated: \n{customer_info}") customer.selected_customer = None elif choice == '8': @@ -195,14 +219,15 @@ def main(play=True): [ DELETE A CUSTOMER ] ''') cancelled_customer = select_customer(customer) - if cancelled_customer is None: + if cancelled_customer is None: # break continue - print(f"\n{cancelled_customer['name']} found out about Netflix, huh?") + print( + f"\n{cancelled_customer['name']} found out about Netflix, huh?") customer.delete_customer() print("Customer successfully deleted. I may lose my job at this rate.") - elif choice == '9': + elif choice == '9': print(''' [ GET INFORMATION ON ONE CUSTOMER ] ''') @@ -212,89 +237,96 @@ def main(play=True): print(''' [ GET INFORMATION ON ALL CUSTOMERS ] ''') - for each_customer in customer.list_customers(): + for each_customer in customer.list_customers(): print(each_customer) -# ---------------------rentals---------------------- # +#=====================================================# +# RENTAL CHOICES # +#=====================================================# - elif choice == '11': + elif choice == '11': print(''' [ CHECK OUT A VIDEO TO A CUSTOMER ] ''') video_id = input(" > Enter the video id: ") - # check if it is a valid id + # check if it is a valid id if video_id.isnumeric(): video_id = int(video_id) video.get_video(id=video_id) - + if video.selected_video: print(f"Selected video: \n{video.selected_video}") - else: + else: print("Video not found. Please enter a valid id.") continue video.selected_video = None customer_id = input(" > Enter the customer id: ") - # check if valid id + # check if valid id if customer_id.isnumeric(): customer_id = int(customer_id) customer.get_customer_by_id(id=customer_id) if customer.selected_customer: print(f"Selected customer: \n{customer.selected_customer}") - else: + else: print("Customer not found. Please enter a valid id.") continue customer.selected_customer = None print("") - checked_out = rental.check_out_video(customer_id=customer_id, video_id=video_id) + checked_out = rental.check_out_video( + customer_id=customer_id, video_id=video_id) customer_info = customer.get_customer_by_id(id=customer_id) video_info = video.get_video(id=video_id) print(f"Rental info: \n{checked_out}") - print(f"{video_info['title']} successfully checked out to {customer_info['name']}!") + print( + f"{video_info['title']} successfully checked out to {customer_info['name']}!") - elif choice == '12': print(''' [ CHECK IN A VIDEO FROM A CUSTOMER ] ''') video_id = input(" > Enter the video id: ") - # check if it is a valid id + # check if it is a valid id if video_id.isnumeric(): video_id = int(video_id) video.get_video(id=video_id) - + if video.selected_video: print(f"Selected video: \n{video.selected_video}") - else: + else: print("Video not found. Please enter a valid id.") continue video.selected_video = None customer_id = input(" > Enter the customer id: ") - # check if valid id + # check if valid id if customer_id.isnumeric(): customer_id = int(customer_id) customer.get_customer_by_id(id=customer_id) if customer.selected_customer: print(f"Selected customer: \n{customer.selected_customer}") - else: + else: print("Customer not found. Please enter a valid id.") continue customer.selected_customer = None print("") - checked_in = rental.check_in_video(customer_id=customer_id, video_id=video_id) + checked_in = rental.check_in_video( + customer_id=customer_id, video_id=video_id) customer_info = customer.get_customer_by_id(id=customer_id) video_info = video.get_video(id=video_id) print(f"Rental info: \n{checked_in}") - print(f"{video_info['title']} successfully checked in {customer_info['name']}!") + print( + f"{video_info['title']} successfully checked in {customer_info['name']}!") -# ---------------------etc---------------------- # +#=====================================================# +# DISPLAY/EXIT CHOICES # +#=====================================================# - elif choice == '13': + elif choice == '13': list_options() elif choice == '14': @@ -302,13 +334,13 @@ def main(play=True): [ EXIT ] ''') consent = input("\nDo you want to exit? select y/n: ") - if consent == 'y': - play=False + if consent == 'y': + play = False print("Thank you for using the video store CLI. Good bye!") - if consent == 'n': + if consent == 'n': continue if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/rental.py b/rental.py index 0d15a85f..0812b2a5 100644 --- a/rental.py +++ b/rental.py @@ -1,28 +1,30 @@ import requests -import datetime -class Rental: - def __init__(self, url="https://retro-video-store-api.herokuapp.com",selected_customer=None, selected_video=None): - self.url = url + +class Rental: + def __init__(self, url="https://retro-video-store-api.herokuapp.com", selected_customer=None, selected_video=None): + self.url = url self.selected_customer = selected_customer self.selected_video = selected_customer - # check out a video - def check_out_video(self, customer_id=None, video_id=None): + # check out a video + def check_out_video(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) + response = requests.post( + self.url+"/rentals/check-out", json=query_params) return response.json() - # check in a video - def check_in_video(self, customer_id=None, video_id=None): + # check in a video + def check_in_video(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) + response = requests.post( + self.url+"/rentals/check-in", json=query_params) return response.json() diff --git a/video.py b/video.py index f3b02ecd..df4ad846 100644 --- a/video.py +++ b/video.py @@ -1,16 +1,15 @@ import requests -import datetime -class Video: - def __init__(self, url="https://retro-video-store-api.herokuapp.com",selected_video=None): - self.url = url - self.selected_video = selected_video - - # add a video +class Video: + def __init__(self, url="https://retro-video-store-api.herokuapp.com", selected_video=None): + self.url = url + self.selected_video = selected_video + + # add a video def add_video(self, title="Default Title", release_date=None, total_inventory=0, available_inventory=0): query_params = { - "title": title, + "title": title, "release_date": release_date, "total_inventory": total_inventory, "available_inventory": available_inventory @@ -19,17 +18,17 @@ def add_video(self, title="Default Title", release_date=None, total_inventory=0, response = requests.post(self.url+"/videos", json=query_params) return response.json() - # get info on all videos - def list_videos(self): + # get info on all videos + def list_videos(self): response = requests.get(self.url+"/videos") return response.json() - - #get a video + + # get a video def get_video(self, title=None, id=None): - + for video in self.list_videos(): if title: - if video["title"]==title: + if video["title"] == title: id = video["id"] self.selected_video = video elif id == video["id"]: @@ -41,39 +40,31 @@ def get_video(self, title=None, id=None): response = requests.get(self.url+f"/videos/{id}") return response.json() - # edit a video + # edit a video def edit_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["release_date"] - if not total_inventory: + if not total_inventory: total_inventory = self.selected_video["total_inventory"] query_params = { - "title": title, - "release_date": release_date, - "total_inventory": total_inventory + "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) - # not sure what next line is doing - self.selected_video = None #response.json() # prints - # clear selected video = None + self.selected_video = None return response.json() - # delete a video + # delete a video def delete_video(self): - response = requests.delete(self.url+f"/videos/{self.selected_video['id']}") + response = requests.delete( + self.url+f"/videos/{self.selected_video['id']}") self.selected_video = None return response.json() - - # print selected video - # def print_selected(self): - # if self.selected_video: - # print(f"Video with id {self.selected_video['id']} is currently selected") - # else: - # print("There is no selected video.")