From ee977e8dd3eba9acdaa63cfeae906896f7cc9df6 Mon Sep 17 00:00:00 2001 From: Aida Date: Tue, 25 May 2021 21:50:24 -0700 Subject: [PATCH 1/5] General Roadmap --- main.py | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index ed3f1a77..0330da37 100644 --- a/main.py +++ b/main.py @@ -1,12 +1,37 @@ import requests URL = "http://127.0.0.1:5000" -BACKUP_URL = "https://retro-video-store-api.herokuapp.com" +BACKUP_URL = "https://aida-retro-video-store-api.herokuapp.com" def main(): print("WELCOME TO RETRO VIDEO STORE") - pass + response = requests.get(BACKUP_URL + "/videos") + print(response.json()) if __name__ == "__main__": - main() \ No newline at end of file + main() + + +roadmap = { + #Video + "1": "Create a video", + "2": "Update a video", + "3": "Delete a video", + "4": "List all videos", + "5": "Get one video", + #Customer + "6": "Create a customer", + "7": "Update a customer", + "8": "Delete a customer", + "9": "Select one customer", + "10": "List all customers", + #Rental + "11": "Check out a video to a customer", + "12": "Check in a video from a customer", + #Optional + "13": "Look up rental due", + "14": "Look up checkout videos", + "15": "Look up overdue videos", + "16": "Quit" + } \ No newline at end of file From fc6ea880e727217df4609e2effa3e6dc6af81e61 Mon Sep 17 00:00:00 2001 From: Aida Date: Fri, 28 May 2021 20:00:53 -0700 Subject: [PATCH 2/5] CRUD for Video, created customer,rental requests --- main.py | 203 ++++++++++++++++++++++++++++++----- my_retro_store_operations.py | 139 ++++++++++++++++++++++++ 2 files changed, 313 insertions(+), 29 deletions(-) create mode 100644 my_retro_store_operations.py diff --git a/main.py b/main.py index 0330da37..56b4621f 100644 --- a/main.py +++ b/main.py @@ -1,37 +1,182 @@ import requests +from my_retro_store_operations import CustomerOperations, RentalOperations +from my_retro_store_operations import VideoOperations +import time,sys +from datetime import date, datetime -URL = "http://127.0.0.1:5000" -BACKUP_URL = "https://aida-retro-video-store-api.herokuapp.com" +def print_stars(): + print("\n**********\n") -def main(): +#progress bar loading animation +def progress_bar(count, total, status=''): + bar_len = 10 + filled_len = int(round(bar_len * count / float(total))) + + percents = round(100.0 * count / float(total), 1) + bar = '=' * filled_len + '-' * (bar_len - filled_len) + + sys.stdout.write('[%s] %s%s ...%s\r' % (bar, percents, '%', status)) + sys.stdout.flush() + +def call_bar(): + total = 10 + i = 0 + while i < total: + i += 1 + progress_bar(i, total, status='Please wait. Loading options for you') + time.sleep(0.3) + progress_bar(i, total, status='Loading is complete. Thanks for waiting') + +def list_options(): + options = { + #Video + "1": "Create a video", + "2": "Update a video", + "3": "Delete a video", + "4": "List all videos", + "5": "Get one video", + #Customer + "6": "Create a customer", + "7": "Update a customer", + "8": "Delete a customer", + "9": "Select one customer", + "10": "List all customers", + #Rental + "11": "Check out a video to a customer", + "12": "Check in a video from a customer", + #Operations + "*": "List all options", + "#": "Quit" + } + print_stars() print("WELCOME TO RETRO VIDEO STORE") - response = requests.get(BACKUP_URL + "/videos") - print(response.json()) + print("These are the actions you can perform") + + for choice_num in options: + print(f"Option {choice_num}. {options[choice_num]}") + print_stars() + return options +def make_choice(options, customer_operations, video_operations, rental_operations): + valid_choices = options.keys() + choice = None -if __name__ == "__main__": - main() + while choice not in valid_choices: + choice = input("Please make your selection using the one of the listed option number: ") + + return choice + +def valid_release_date(date_string): + format = "%m-%d-%Y" + + try: + datetime.strptime(date_string, format) + return True + except ValueError: + print("Invalid entry. Please enter date as MM-DD-YYYY") + return False + +url="https://aida-retro-video-store-api.herokuapp.com" + +def main(play=True): + + print_stars() + print("... \N{smiling face with smiling eyes} ... WELCOME TO AIDA'S RETRO VIDEO STORE ... \N{hugging face}") + call_bar() + customer_operations = CustomerOperations(url) + video_operations = VideoOperations(url) + rental_operations = RentalOperations(url) + options = list_options() -roadmap = { - #Video - "1": "Create a video", - "2": "Update a video", - "3": "Delete a video", - "4": "List all videos", - "5": "Get one video", - #Customer - "6": "Create a customer", - "7": "Update a customer", - "8": "Delete a customer", - "9": "Select one customer", - "10": "List all customers", - #Rental - "11": "Check out a video to a customer", - "12": "Check in a video from a customer", - #Optional - "13": "Look up rental due", - "14": "Look up checkout videos", - "15": "Look up overdue videos", - "16": "Quit" - } \ No newline at end of file + while play==True: + + choice = make_choice(options, customer_operations, video_operations, rental_operations) + + if choice=='1': + print("Hashing it out! Let's create a new video!") + title=input("What is the name of the video: ") + release_date=input("Please enter a release date: ") + if valid_release_date(release_date): + release_date = release_date + else: + release_date=input("Please enter a date as (MM-DD-YYYY): ") + if valid_release_date(release_date): + release_date = release_date + else: + print("Oops, your entry is still invalid. Date will be stored as a default current date. You can update it later with option 2") + release_date = str(datetime.now()) + total_inventory=input("How many copies are there in total? ") + call_bar() + response = video_operations.create_video(title=title, release_date=release_date, total_inventory=total_inventory) + print_stars() + print(f"Here is the ID of new video record: {response['id']} ") + + elif choice=='2': + list_videos = video_operations.get_all_videos() + for video in list_videos: + print(f"Video Id: {video['id']}, Video Title: {video['title']}") + video_id = input("Which video would you like to update? Please enter ID: ") + if video_id.isnumeric(): + video_id = int(video_id) + else: + print("Please enter valid id") + print(f"Great, let's update the video with ID: {video_id}") + title=input("What is the new title of the movie? ") + release_date=input("Please enter a new release date: ") + if valid_release_date(release_date): + release_date = release_date + else: + release_date=input("Please enter a valid new date: ") + if valid_release_date(release_date): + release_date = release_date + else: + print("Oops, your entry is still invalid. Date will be stored as a default current date. You can update it later with option 2") + release_date = str(datetime.now()) + total_inventory=input("How many copies are there total? ") + + response = video_operations.update_video(video_id, title=title, release_date=release_date,total_inventory=total_inventory) + print_stars() + print(f"Successfully updated the video with ID: {response['id']} - title: {response['title']} - release date: {response['release_date']} - inventory: {response['total_inventory']}") + + elif choice=='3': + list_videos = video_operations.get_all_videos() + for video in list_videos: + print(f"Id:{video['id']}, Title:{video['title']}") + video_id = input("Which video would you like to delete? Please enter ID: ") + if video_id.isnumeric(): + video_id = int(video_id) + video_operations.delete_video(video_id) + print_stars() + print(f"Success! Video with ID {video_id} has been deleted") + else: + print("Id type is integer. Please enter valid id.") + + elif choice=='4': + print_stars() + for video in video_operations.get_all_videos(): + print(video) + elif choice=='5': + print("Here are the videos:") + list_videos = video_operations.get_all_videos() + for video in list_videos: + print(f"Id: {video['id']}, name: {video['title']}") + video_id = input("Which video id would you like to select? ") + if video_id.isnumeric(): + video_id = int(video_id) + video_operations.selected_video = video_operations.get_one_video(video_id=video_id) + if video_operations.selected_video: + print(f"Selected video: {video_operations.selected_video}") + else: + print("Id type is integer. Please enter valid id.") + + elif choice =='*': + list_options() + elif choice=='#': + play=False + print("... \N{smiling face with smiling eyes} ... Thanks for using the Retro Video store created by Aida ... \N{winking face}") + + print_stars() + +if __name__ == "__main__": + main() diff --git a/my_retro_store_operations.py b/my_retro_store_operations.py new file mode 100644 index 00000000..76744011 --- /dev/null +++ b/my_retro_store_operations.py @@ -0,0 +1,139 @@ +import requests + +class CustomerOperations: + def __init__(self, url="https://aida-retro-video-store-api.herokuapp.com", selected_customer=None): + self.url = url + self.selected_customer = selected_customer + + def create_customer(self,name="Default customer name",postal_code="Default postal code",phone="Default phone number"): + query_params = { + "name": name, + "postal_code": postal_code, + "phone": phone, + #"register_at": register_at + } + response = requests.post(self.url+"/customers",json=query_params) + return response.json() + + def get_all_customers(self): + response = requests.get(self.url+"/customers") + return response.json() + + def get_one_customer(self, name=None, customer_id=None): + for customer in self.get_all_customers(): + if name: + if name["name"]==name: + customer_id = customer["id"] + self.selected_customer = customer + elif customer_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/{customer_id}") + return response.json() + + def update_customer(self,customer_id, name=None,phone=None, postal_code=None): + if not name: + name = self.selected_customer["name"] + if not phone: + phone = self.selected_customer["phone"] + if not postal_code: + postal_code = self. selected_customer["postal_code"] + + query_params = { + "name": name, + "phone": phone, + "postal_code": postal_code, + } + response = requests.put( + self.url+f"/customers/{customer_id}",json=query_params) + return response.json() + + def delete_customer(self, customer_id): + response = requests.delete(self.url+f"/customers/{customer_id}") + return response.json() + + def print_selected(self): + if self.selected_customer: + print(f"Customer with id {self.selected_customer['id']} is currently selected\n") + +class VideoOperations: + def __init__(self, url="https://aida-retro-video-store-api.herokuapp.com", selected_video=None): + self.url = url + self.selected_video = selected_video + + def create_video(self,title="Default video title",release_date="Default release date",total_inventory=0): + 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 get_all_videos(self): + response = requests.get(self.url+"/videos") + return response.json() + + def get_one_video(self, title=None, video_id=None): + for video in self.get_all_videos(): + if title: + if title["title"]==title: + video_id = video["id"] + self.selected_video = video + elif video_id == video["id"]: + self.selected_video = video + + if self.selected_video == None: + return "Could not find video by that title or id" + + response = requests.get(self.url+f"/videos/{video_id}") + return response.json() + + def update_video(self,video_id, 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/{video_id}",json=query_params) + return response.json() + + def delete_video(self, video_id): + response = requests.delete(self.url+f"/videos/{video_id}") + return response.json() + + def print_selected(self): + if self.selected_video: + print(f"Video with id {self.selected_video['id']} is currently selected\n") + +class RentalOperations: + def __init__(self, url="https://aida-retro-video-store-api.herokuapp.com", selected_rental=None): + self.url = url + self.selected_rental = selected_rental + + 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() \ No newline at end of file From 12437c2409d44faa7c54167d81b5da96c3276ab4 Mon Sep 17 00:00:00 2001 From: Aida Date: Fri, 28 May 2021 20:03:01 -0700 Subject: [PATCH 3/5] CRUD for Customer and check-in/out requests --- main.py | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/main.py b/main.py index 56b4621f..b4897e38 100644 --- a/main.py +++ b/main.py @@ -169,7 +169,96 @@ def main(play=True): print(f"Selected video: {video_operations.selected_video}") else: print("Id type is integer. Please enter valid id.") + + elif choice=='6': + print("Splendid! New customer more money! ") + name=input("What is the name of the customer ") + postal_code=input("What is the postal code? ") + phone=input("Please write down a phone number to contact ") + call_bar() + response = customer_operations.create_customer(name=name, postal_code=postal_code,phone=phone) + print_stars() + print(f"Here is the ID of new customer: {response['id']}") + elif choice=='7': + list_customer = customer_operations.get_all_customers() + for customer in list_customer: + print(f"Customer Id: {customer['id']}, name: {customer['name']}") + customer_id = input("Which customer would you like to update? Please enter ID: ") + if customer_id.isnumeric(): + customer_id = int(customer_id) + else: + print("Id type is integer. Please enter valid id.") + + print(f"Great! Let's update the customer with ID: {customer_id}") + name=input("What is the new name of your customer? ") + postal_code=input("What is the new postal code of your customer? ") + phone=input("Please write down a new phone number : ") + response = customer_operations.update_customer(customer_id, name=name, postal_code=postal_code,phone=phone) + print_stars() + print(f"Successfully updated the customer with ID: {response['id']} - name: {response['name']} - postal code: {response['postal_code']} - phone: {response['phone']}") + + elif choice=='8': + list_customer = customer_operations.get_all_customers() + for customer in list_customer: + print(f"Customer Id: {customer['id']}, name: {customer['name']}") + customer_id = input("Which customer you would like to delete? Please enter ID: ") + if customer_id.isnumeric(): + customer_id = int(customer_id) + customer_operations.delete_customer(customer_id) + else: + print("Id type is integer. Please enter valid id.") + + print_stars() + print(f"Customer with ID {customer_id} has been deleted") + + elif choice=='9': + print("Here are the customers:") + list_customers = customer_operations.get_all_customers() + for customer in list_customers: + print(f"Customer 9Id: {customer['id']}, name: {customer['name']}") + + customer_id = input("Which customer id would you like to select? ") + if customer_id.isnumeric(): + customer_id = int(customer_id) + customer_operations.selected_customer = customer_operations.get_one_customer(customer_id=customer_id) + if customer_operations.selected_customer: + print(f"Selected customer: {customer_operations.selected_customer}") + else: + print("Id type is integer. Please enter valid id.") + elif choice=='10': + print_stars() + for customer in customer_operations.get_all_customers(): + print(customer) + elif choice=='11': + customer_id=input("Starting a rental procedure. Please enter a customer id: ") + video_id=input("Please enter a video id: ") + if customer_id.isnumeric(): + customer_id = int(customer_id) + else: + print("Id type is integer. Please enter valid id.") + if video_id.isnumeric(): + video_id = int(video_id) + else: + print("Id type is integer. Please enter valid id.") + call_bar() + response = rental_operations.check_out(customer_id=customer_id, video_id=video_id) + print(f"*** Calling the shots! Selected video id {video_id} has been checked out! ") + elif choice=='12': + customer_id=input("Starting a return procedure. Please enter a customer id: ") + video_id=input("Please enter a video id: ") + if customer_id.isnumeric(): + customer_id = int(customer_id) + else: + print("Id type is integer. Please enter valid id.") + if video_id.isnumeric(): + video_id = int(video_id) + else: + print("Id type is integer. Please enter valid id.") + call_bar() + response = rental_operations.check_in(customer_id=customer_id, video_id=video_id) + print("Here is the updated return report:", response) + print(f"*** Thank you customer id {customer_id}! Selected video id {video_id} has been checked in! ***") elif choice =='*': list_options() elif choice=='#': From a0796736b3bc3903d7a8a2ef79c59ee6f2180c8f Mon Sep 17 00:00:00 2001 From: Aida Date: Fri, 28 May 2021 20:23:52 -0700 Subject: [PATCH 4/5] Updated code --- .../my_retro_store_operations.cpython-39.pyc | Bin 0 -> 4994 bytes main.py | 53 +++++++++--------- 2 files changed, 25 insertions(+), 28 deletions(-) create mode 100644 __pycache__/my_retro_store_operations.cpython-39.pyc diff --git a/__pycache__/my_retro_store_operations.cpython-39.pyc b/__pycache__/my_retro_store_operations.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..255e5ca8803b340c49bf00bb911859c551b1ed16 GIT binary patch literal 4994 zcmc&%TW=f36`t7(wW26W@=bQ)q}w=2P1h2gHdiNgo!Ui#qF{m=4FUnhcEedmlviAO zX6Z!4>M8DHpYoUlkRSOHpnqpy^VGjUpl!Z0%iSfHR0|{yyu=*Nea?Jy&iQ8i_4PW# z_wASe{F{A_v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k9wPM;5rzZwZf3d33eCIi9B10&m;Im+JeG(LeMpr9zuD9mq zT&@p%O6Jb=T#3owA#}7Q)6M7cro(-bM=DH%uexRSz2%O z73h%%JH4A_jNF(Ktk!%$nv;7n4mw`YaJK85SN|X)Zfe7sXJL7jbT%?$ZXqwPk*EY{ z;;|U14A2Yiek#AdM)UoO1Svhkukt!o?vU6ep{ew3%4zrd4drf;AZj?BO513qZY7nj z7F0@YU8K3sMCmq?qMa5m{?+2eUl+KS>KFf-SP>3#wtmky(#=03#{1z@WXg?#Dd`sE zhq?7==Xf9bRZoIIIwIvWqrtQKQdOyfD;HvJ!2_>i26__XL2MkGa}Q!uKZxn=lRt>Z zhIG+il0}csv@=CjySpEBAM8Z9c++)U6Ww_FhAFzA&T*@HxQF4#7_Deq`c?a%ngx1$ zZedSF_ouWe`8zB)+N$iP*Dp6CiFqsV<1I$J2HXD~ja97|Pa^MKTsP@WyffZL!{ Date: Fri, 28 May 2021 20:29:17 -0700 Subject: [PATCH 5/5] All required CLI features created, passing tests --- main.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/main.py b/main.py index 5772ea93..6e76c3fa 100644 --- a/main.py +++ b/main.py @@ -155,6 +155,7 @@ def main(play=True): print_stars() for video in video_operations.get_all_videos(): print(video) + elif choice=='5': print("Here are the videos:") list_videos = video_operations.get_all_videos() @@ -178,6 +179,7 @@ def main(play=True): response = customer_operations.create_customer(name=name, postal_code=postal_code,phone=phone) print_stars() print(f"Here is the ID of new customer: {response['id']}") + elif choice=='7': list_customer = customer_operations.get_all_customers() for customer in list_customer: @@ -227,6 +229,7 @@ def main(play=True): print_stars() for customer in customer_operations.get_all_customers(): print(customer) + elif choice=='11': customer_id=input("Starting a rental procedure. Please enter a customer id: ") video_id=input("Please enter a video id: ") @@ -241,6 +244,7 @@ def main(play=True): call_bar() response = rental_operations.check_out(customer_id=customer_id, video_id=video_id) print(f"*** Calling the shots! Selected video id {video_id} has been checked out! ") + elif choice=='12': customer_id=input("Starting a return procedure. Please enter a customer id: ") video_id=input("Please enter a video id: ") @@ -256,6 +260,7 @@ def main(play=True): response = rental_operations.check_in(customer_id=customer_id, video_id=video_id) print("Here is the updated return report:", response) print(f"*** Thank you customer id {customer_id}! Selected video id {video_id} has been checked in! ***") + elif choice =='*': list_options() elif choice=='#':