-
Notifications
You must be signed in to change notification settings - Fork 70
Paper - Karla T. #68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Paper - Karla T. #68
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,3 +3,5 @@ | |
|
|
||
| # Ada Library Information | ||
| *.ali | ||
| .vscode | ||
| venv | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| { | ||
| // Use IntelliSense to learn about possible attributes. | ||
| // Hover to view descriptions of existing attributes. | ||
| // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
| "version": "0.2.0", | ||
| "configurations": [ | ||
| { | ||
| "name": "Python: Current File", | ||
| "type": "python", | ||
| "request": "launch", | ||
| "program": "${file}", | ||
| "console": "integratedTerminal" | ||
| } | ||
| ] | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "python.pythonPath": "venv/bin/python" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,203 @@ | ||
| import requests | ||
| import pprint | ||
| from video_store import VideoStore | ||
|
|
||
|
|
||
| URL = "http://127.0.0.1:5000" | ||
| BACKUP_URL = "https://retro-video-store-api.herokuapp.com" | ||
|
|
||
| def main(): | ||
| print("WELCOME TO RETRO VIDEO STORE") | ||
| pass | ||
| video_store = VideoStore(url=BACKUP_URL) | ||
|
|
||
|
|
||
| def run_cli(): | ||
|
|
||
| print("WELCOME TO RETRO VIDEO STORE!\n" | ||
| "These are the actions you can perform:") | ||
|
|
||
| while True: | ||
| options = list_options() | ||
| choice = input('Which activity would you like to do? (select the option number): ') | ||
| print() # Linebreak | ||
| if choice not in options.keys(): | ||
| print('Invalid option.') | ||
| continue | ||
| if choice == '20': | ||
| break | ||
| if choice in ['4', '5', '6'] and video_store.selected_video == None: | ||
| print("You must select a video before using it in any way") | ||
| print("Let's select a video!") | ||
| choice = "3" | ||
| if choice in ['12', '13'] and video_store.selected_customer == None: | ||
| print("You must selected a customer before using it in any way") | ||
| print("Let's select a customer") | ||
| choice = "9" | ||
|
|
||
|
|
||
| action = options[choice] | ||
| action() | ||
|
|
||
|
|
||
| def list_options(): | ||
|
|
||
| options = { | ||
| "1": list_videos, | ||
| "2": create_video, | ||
| "3": select_video, | ||
| "4": update_video, | ||
| "5": delete_video, | ||
| "6": checkout_video, | ||
| "7": checkin_video, | ||
| "8": list_customers, | ||
| "9": get_customer_info, | ||
| "10": list_customers_rentals, | ||
| "11": create_customer, | ||
| "12": update_customer, | ||
| "13": delete_customer, | ||
| "20": "Quit" | ||
| } | ||
|
|
||
|
|
||
| print() # Linebreak | ||
| for key, action in options.items(): | ||
| action_desc = action if type(action) is str else action.__doc__ | ||
| print(f'Option {key}. {action_desc}') | ||
| print() # Linebreak | ||
|
|
||
| return options | ||
|
|
||
|
|
||
| def list_videos(): | ||
| """List all videos""" | ||
|
|
||
| print(*video_store.list_videos(), sep='\n') | ||
|
|
||
|
|
||
| def create_video(): | ||
| """Create a video""" | ||
|
|
||
| print("Great! Let's create a new video.") | ||
| title = input("What is the title of your video? ") | ||
| total_inventory = input("How many copies of this movie are we adding? ") | ||
| release_date = input("What was the movie's release date? ") | ||
| response = video_store.create_video(title=title, total_inventory=total_inventory, release_date=release_date) | ||
| print("New video id:", response["id"]) | ||
|
|
||
|
|
||
| def select_video(): | ||
| """Select a video""" | ||
|
|
||
| select_by = input("In order to select a video, write out title or id: ") | ||
| if select_by == "title": | ||
| title = input("Which title would you like to select? ") | ||
| video_store.get_video(title=title) | ||
| elif select_by == "id": | ||
| id = input("Which video id would you like to select? ") | ||
| if id.isnumeric(): | ||
| id = int(id) | ||
| video_store.get_video(id=id) | ||
| else: | ||
| print("Could not select. Please enter id or title.") | ||
| if video_store.selected_video != None: | ||
| print("Selected video: ", video_store.selected_video) | ||
|
|
||
|
|
||
| def update_video(): | ||
| """Update selected video""" | ||
|
|
||
| print(f"Great! Let's update the video: {video_store.selected_video}") | ||
| title = input("What is the new title of your video? ") | ||
| release_date = input("What is the release date of your video? ") | ||
| total_inventory = input("What is the new total inventory?") | ||
| response = video_store.update_video(title=title, release_date=release_date, total_inventory=total_inventory) | ||
| print("Updated video:", response) | ||
|
|
||
|
|
||
| def delete_video(): | ||
| """Delete a selected video""" | ||
|
|
||
| id = input("Enter video id for deletion: ") | ||
| if id.isnumeric(): | ||
| id = int(id) | ||
| video_store.delete_video(id=id) | ||
| print(f"Video id {id} has been deleted.") | ||
| pprint.pprint(video_store.list_videos()) | ||
|
|
||
|
|
||
| def checkout_video(): | ||
| """Check out a video""" | ||
|
|
||
| print(f"Great! Let's grab some customer information for rental video: {video_store.selected_video}") | ||
| customer_id = input("What is your id?") | ||
| video_id = input("What is the video_id you want to check out?") | ||
| due_date = input("when is the video due?") | ||
| video_store.check_out_video(customer_id=customer_id, video_id=video_id, due_date=due_date) | ||
| print(f"Customer {customer_id} checked out {video_id}, {due_date}") | ||
|
Comment on lines
+128
to
+133
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a little confused, first I had to select a video then I'm asked for the customer and video id separately. Shouldn't you just use the selected video? |
||
|
|
||
|
|
||
| def checkin_video(): | ||
| """Check in in a video""" | ||
|
|
||
| customer_id = input("what is the customer's id that checked out the video?: ") | ||
| current = video_store.get_customer_rentals(customer_id) | ||
| print(f"Above are the videos customer with ID# {customer_id} has currently checked out.\n" | ||
| f"To check in a video lets collect some info: ") | ||
| video_id = input("What is the id of the video you want to check in?: ") | ||
| video_store.check_in_video(customer_id=customer_id, video_id=video_id) | ||
| print(f"Customer {customer_id} has returned {video_id}") | ||
|
|
||
|
|
||
| def list_customers(): | ||
| """Get list of customers""" | ||
|
|
||
| print(*video_store.list_customers(), sep='\n') | ||
|
|
||
|
|
||
| def get_customer_info(): | ||
| """Get info on one customer by ID""" | ||
|
|
||
| id = input("Type out customer's ID ") | ||
| if id.isnumeric(): | ||
| id = int(id) | ||
| video_store.get_customer(id) | ||
| else: | ||
| print("Could not find customer with that ID") | ||
| if video_store.selected_customer != None: | ||
| print("Selected customer:", video_store.selected_customer) | ||
|
|
||
|
|
||
| def list_customers_rentals(): | ||
| """Get customer's rental list""" | ||
|
|
||
| id = input("Type out customer's ID ") | ||
| if id.isnumeric(): | ||
| id = int(id) | ||
| video_store.get_customer_rentals(id) | ||
|
|
||
| def create_customer(): | ||
| """Create a new customer""" | ||
| print("Great! Let's create a new customer!") | ||
| name = input("What is the name of our new customer? ") | ||
| postal_code = input("What is their postal code? ") | ||
| phone = input("What is their phone number? ") | ||
| response = video_store.create_customer(name=name, postal_code=postal_code, phone=phone) | ||
| print("New customer id:", response["id"]) | ||
|
|
||
| def update_customer(): | ||
| """Update customer information""" | ||
| print(f"Great! Let's edit the customer info: {video_store.selected_customer}") | ||
| name = input("What is the new name of this customer? ") | ||
| postal_code = input("What is the new postal code? ") | ||
| phone = input("What is the new phone number? ") | ||
| response = video_store.update_customer(name=name, postal_code=postal_code, phone=phone) | ||
| print("Updated customer info:", response) | ||
|
|
||
| def delete_customer(): | ||
| """Delete a customer""" | ||
| id = input("Enter customer id for deletion: ") | ||
| if id.isnumeric(): | ||
| id = int(id) | ||
| video_store.delete_customer(id) | ||
| print(f"Customer id {id} has been deleted.") | ||
| pprint.pprint(video_store.list_customers()) | ||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
| run_cli() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| import requests | ||
| import datetime | ||
| import pprint | ||
|
|
||
| class VideoStore: | ||
| def __init__(self, url, selected_video=None, selected_customer=None): | ||
| self.url = url | ||
| self.selected_video = selected_video | ||
| self.selected_customer = selected_customer | ||
|
|
||
| def create_video(self,title="Default Video",total_inventory="Default total inventory",release_date=None): | ||
| query_params = { | ||
| "title": title, | ||
| "total_inventory": total_inventory, | ||
| "release_date": release_date | ||
| } | ||
| response = requests.post(self.url+"/videos",json=query_params) | ||
| return response.json() | ||
|
|
||
| def list_videos(self): | ||
| response = requests.get(self.url+"/videos") | ||
| return response.json() | ||
|
|
||
| def get_video(self, title=None, id=None): | ||
| for video in self.list_videos(): | ||
| if video: | ||
| if video["title"]==title: | ||
| id = video["id"] | ||
| self.selected_video = video | ||
| elif id == video["id"]: | ||
| self.selected_video = video | ||
|
|
||
| if self.selected_video is None: | ||
| print("Could not find video by that name or id" ) | ||
|
|
||
| '''response = requests.get(self.url+f"/videos/{id}") | ||
| return response.json()''' | ||
|
|
||
| def list_customers(self): | ||
| response = requests.get(self.url+"/customers") | ||
| return response.json() | ||
|
|
||
| def get_customer_rentals(self, id): | ||
| response = requests.get(self.url+f"/customers/{id}/rentals") | ||
| print(response) | ||
| pprint.pprint(response.json()) | ||
|
Comment on lines
+45
to
+46
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest moving the prints out of these classes and doing the prints into the
|
||
|
|
||
| def get_customer(self, id): | ||
| for customer in self.list_customers(): | ||
| if customer["id"]==id: | ||
| self.selected_customer = customer | ||
| return self.selected_customer | ||
| if self.selected_customer==None: | ||
| print ("Could not find customer by that id") | ||
|
|
||
|
|
||
| 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.release_date["description"] | ||
| if not total_inventory: | ||
| total_inventory = self.total_inventory["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) | ||
| self.selected_video = response.json() | ||
| return response.json() | ||
|
|
||
| def delete_video(self, id=None): | ||
| response = requests.delete(self.url+f"/videos/{self.selected_video['id']}") | ||
| self.selected_video = None | ||
| return response.json() | ||
|
|
||
| def check_out_video(self,customer_id,video_id,due_date): | ||
| query_params = { | ||
| "customer_id": customer_id, | ||
| "video_id": video_id, | ||
| "due_date": due_date, | ||
| } | ||
| response = requests.post(self.url+"/rentals/check-out",json=query_params) | ||
| return response.json() | ||
|
|
||
| def check_in_video(self, customer_id, video_id): | ||
| query_params = { | ||
| "customer_id": customer_id, | ||
| "video_id": video_id | ||
| } | ||
| response = requests.post(self.url+"/rentals/check-in",json=query_params) | ||
|
|
||
| print("Some string") | ||
| print(response) | ||
| print(response.json()) | ||
|
|
||
| def print_selected(self): | ||
| if self.selected_video: | ||
| print(f"Video with id {self.selected_video['id']} is currently selected\n") | ||
|
|
||
| def create_customer(self, name="Default Name", postal_code="Default Postal-Code", phone="phone"): | ||
| query_params = { | ||
| "name": name, | ||
| "postal_code": postal_code, | ||
| "phone": phone | ||
| } | ||
| response = requests.post(self.url+"/customers",json=query_params) | ||
| return response.json() | ||
|
|
||
| def update_customer(self, name=None, postal_code=None, phone=None): | ||
| if not name: | ||
| name = self.selected_customer["name"] | ||
| if not postal_code: | ||
| postal_code = self.postal_code["postal code"] | ||
| if not phone: | ||
| phone = self.phone["phone number"] | ||
| 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) | ||
| self.selected_customer = response.json() | ||
| return response.json() | ||
|
|
||
| def delete_customer(self, id=None): | ||
| response = requests.delete(self.url+f"/customers/{self.selected_customer['id']}") | ||
| self.selected_customer = None | ||
| return response.json() | ||
|
|
||
| ''' | ||
| def mark_complete(self): | ||
| response = requests.patch(self.url+f"/tasks/{self.selected_task['id']}/mark_complete") | ||
| self.selected_task = response.json()["task"] | ||
| return response.json() | ||
|
|
||
| def mark_incomplete(self): | ||
| response = requests.patch(self.url+f"/tasks/{self.selected_task['id']}/mark_incomplete") | ||
| self.selected_task = response.json()["task"] | ||
| return response.json() | ||
| ''' | ||
|
|
||
| # def print_selected(self): | ||
| # if self.selected_video: | ||
| # print(f"Video with id {self.selected_video['id']} is currently selected\n") | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file can probably be put into your
.gitignorefile.