diff --git a/.gitignore b/.gitignore index b4d70396..7c823a15 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,145 @@ # Ada Library Information *.ali + +.vscode +.DS_Store + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ \ No newline at end of file diff --git a/__init__.py b/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/main.py b/main.py index ed3f1a77..a65c08b4 100644 --- a/main.py +++ b/main.py @@ -1,12 +1,214 @@ -import requests +from video_store import VideoStore URL = "http://127.0.0.1:5000" BACKUP_URL = "https://retro-video-store-api.herokuapp.com" -def main(): +def print_stars(): + print("\n**************************\n") + +def list_options(): + print("Thank you for being a valued member of our team!") + print("What would you like to do?") + options = { + "1": "add a video", + "2": "edit a video", + "3": "delete a video", + "4": "get information about 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": "exit this program" + } + for num in options: + print(f"Option {num}. {options[num]}") + print_stars() + return options + +def make_choice(options, video_store): + valid_choices = options.keys() + choice = None + while choice not in valid_choices: + choice = input("Make your selection using the option number: ") + return choice + + + + +def main(play=True): + #initialize task_list + video_store = VideoStore(url=BACKUP_URL) + print("WELCOME TO RETRO VIDEO STORE") - pass + options = list_options() + + while play == True: + choice = make_choice(options, video_store) + video_store.print_selected(choice) + + if choice == "1": + print(f"Let's add a new video") + title = input("What is the name of the movie? ") + release_date = input("When was the movie released? ") + total_inventory = input("How many copies of this video do we have? ") + response = video_store.create_video(title=title, release_date=release_date, total_inventory=total_inventory ) + + print_stars() + print("New movie:", response) + + if choice == "2": + print(f"Let's EDIT a video. ") + video_id=input("What is the id of the video you would like to edit? ") + original_video_response = video_store.get_video_by_id(video_id) + print("Current movie information: ", original_video_response) + title=input("What is the correct title? ") + release_date=input("What is the correct release date? ") + total_inventory=input("What is the correct inventory? ") + response = video_store.edit_video(title=title, release_date=release_date, total_inventory=total_inventory) + + print_stars() + print("Updated movie: ", response) + + if choice == "3": + print(f"Let's DELETE a video. ") + video_id=input("What is the id of the video you would like to delete? ") + movie_to_delete = video_store.get_video_by_id(video_id) + print("Current movie information: ", movie_to_delete) + confirm = input("Type 'Y' to confirm you would like to delete this video") + if confirm == "Y": + video_store.delete_video(movie_to_delete) + + print_stars() + print("Video has been deleted.") + + if choice == "4": + print(f"Let's get information about all videos. ") + print_stars() + videos = [video for video in video_store.get_all_videos()] + print(videos) + + + if choice == "5": + print(f"Let's get information about a video. ") + print_stars() + id = input("What is the id of the movie you would like information about? ") + if id.isnumeric(): + id = int(id) + video = video_store.get_video_by_id(id=id) + if video: + print_stars() + print(video) + else: + print("Please enter a numerical id. ") + + if choice == "6": + print(f"Let's add a new customer") + name = input("What is the name of the 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_stars() + print("New customer has been created and given id #", response["id"]) + + if choice == "7": + customer_id=input("What is the id of the customer you would like to edit? ") + original_customer_response = video_store.get_customer_by_id(customer_id) + print("Current movie information: ", original_customer_response) + name=input("What is the correct name of the customer? ") + postal_code=input("What is their correct postal code? ") + phone=input("What is their correct phone number? ") + response = video_store.edit_customer(name=name, postal_code=postal_code, phone=phone) + + print_stars() + print("Updated customer: ", response) + + if choice == "8": + print(f"Let's DELETE a customer. ") + customer_id=input("What is the id of the customer you would like to delete? ") + movie_to_delete = video_store.get_customer_by_id(customer_id) + print("Current movie information: ", movie_to_delete) + confirm = input("Type 'Y' to confirm you would like to delete this customer") + if confirm == "Y": + video_store.delete_customer(movie_to_delete) + + print_stars() + print("Customer has been deleted.") + + if choice == "9": + print(f"Let's get information about all customers. ") + print_stars() + customers = [customer for customer in video_store.get_all_customers()] + print(customers) + + + if choice == "10": + print(f"Let's get information about: {video_store.selected_customer} ") + print_stars() + id = input("What is the id of the customer you would like information about? ") + if id.isnumeric(): + id = int(id) + customer = video_store.get_customer_by_id(id=id) + if video_store.selected_customer: + print_stars() + print(customer) + else: + print("Please enter a numerical id. ") + + if choice == "11": + print(f"Let's check out a video to a customer. ") + print_stars() + customer_id = input("What is the id of the customer who would like to check out a video? ") + if customer_id.isnumeric(): + customer_id = int(customer_id) + customer = video_store.get_customer_by_id(id=customer_id) + + elif not customer_id.isnumeric() or not video_store.selected_customer: + print("Please enter a valid numerical id. ") + + video_id = input("What is the id of the video being checked out? ") + if video_id.isnumeric(): + video_id = int(video_id) + video = video_store.get_video_by_id(id=video_id) + + elif not video_id.isnumeric() or not video_store.video: + print("Please enter a valid numerical id. ") + + result = video_store.check_out(video_id=video_id, customer_id=customer_id) + + print(f"You checkout has been successful: {result}") + + if choice == "12": + print(f"Let's check in a video from a customer. ") + print_stars() + customer_id = input("What is the id of the customer who would like to return their video? ") + if customer_id.isnumeric(): + customer_id = int(customer_id) + customer = video_store.get_customer_by_id(id=customer_id) + + elif not customer_id.isnumeric() or not video_store.selected_customer: + print("Please enter a valid numerical id. ") + + video_id = input("What is the id of the video being checked in? ") + if video_id.isnumeric(): + video_id = int(video_id) + video = video_store.get_video_by_id(id=video_id) + + elif not video_id.isnumeric() or not video_store.video: + print("Please enter a valid numerical id. ") + + result = video_store.check_in(video_id=video_id, customer_id=customer_id) + print(f"You check-in has been successful: {result}") + + if choice == "13": + play=False + print("\nThanks for using the Video Store CLI!") if __name__ == "__main__": - main() \ No newline at end of file + main() + diff --git a/main_enhance.py b/main_enhance.py new file mode 100644 index 00000000..7b195437 --- /dev/null +++ b/main_enhance.py @@ -0,0 +1,98 @@ +import requests + +URL = "http://127.0.0.1:5000" +BACKUP_URL = "https://retro-video-store-api.herokuapp.com" + +def print_stars(): + print("\n**************************\n") + +def list_options(): + options = { + "1": "I am an Employee", + "2": "I am a Customer", + "3": "I don't want to be in this program anymore" + } + for num in options: + print(f"Option {num}. {options[num]}") + # print_stars() + return options + +def make_choice(options, video_store): + valid_choices = options.keys() + choice = None + while choice not in valid_choices: + # print("What would you like to do? Select 9 to see all options again") + choice = input("Make your selection using the option number: ") + return choice + +def list_employee_options(): + print("Thank you for being a valued member of our team!") + print("What would you like to do?") + options = { + "1": "add a video", + "2": "edit a video", + "3": "delete a video", + "4": "get information about 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": "exit this program" + } + for num in options: + print(f"Option {num}. {options[num]}") + # print_stars() + return options + + +def employee_options(play=True): + employee_option = list_employee_options() + while play == True: + employee_choice = make_choice(employee_options, video_store) + video_store.print_selected() + + if employee_choice == "2": + for task in task_list.list_tasks(): + print("add later") + + + if employee_choice == "13": + play=False + print("\nThanks for using the Video Store CLI!") + + + +def customer_options(): + pass + + + + +def main(play=True): + #I wrote URL instead of TaskList. is that right? + video_store = URL(url="BACKUP_URL") + print("WELCOME TO RETRO VIDEO STORE") + print("Please tell us a bit about yourself") + user_options = list_options() + + while play == True: + choice = make_choice(user_options, video_store) + video_store.print_selected() + + if choice == "1": + employee_options() + + if choice == "2": + customer_options() + + if choice == "3": + play=False + print("\nThanks for using the Video Store CLI!") + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/video_store.py b/video_store.py new file mode 100644 index 00000000..914edfd5 --- /dev/null +++ b/video_store.py @@ -0,0 +1,121 @@ +import requests +import datetime +from flask import json + +class VideoStore(): + def __init__(self, url="http://localhost:5000", selected_video=None, selected_customer=None): + self.url = url + self.selected_video = selected_video + self.selected_customer = selected_customer + + def print_selected(self, choice): + if choice: + print(f"You have selected #{choice}\n") + +#1 + def create_video(self, title, release_date, total_inventory): + query_params = { + "title": title, + "release_date": release_date, + "total_inventory": total_inventory + } + video_url = self.url+"/videos" + print(f"about to send request to {video_url}") + response = requests.post(video_url,json=query_params) + print(response) + # if time allows: check for: if response.status_code == 200: + return response.json() + # else: + + +#2 + def edit_video(self, title, release_date, total_inventory): + request_body = { + "title": title, + "release_date": release_date, + "total_inventory": total_inventory + } + video_url = self.url+"/videos/"+str(self.selected_video["id"]) + print(f"about to send request to {video_url}") + response = requests.put(video_url,json=request_body) + print(response) + # if time allows: check for: if response.status_code == 200: + return response.json() + +#3 - works + def delete_video(self, selected_video): + response = requests.delete(self.url+f"/videos/{self.selected_video['id']}") + self.selected_video = None + return response.json() + +#4 - basics work + def get_all_videos(self): + response = requests.get(self.url+"/videos") + return response.json() + +#5 - basics work + def get_video_by_id(self, id=id): + response = requests.get(self.url+f"/videos/{id}") + # if time allows: check for: if response.status_code == 200: + self.selected_video = response.json() + return response.json() + +#6- basics work + def create_customer(self, name, postal_code, phone): + query_params = { + "name": name, + "postal_code": postal_code, + "phone": phone + } + response = requests.post(self.url+"/customers",json=query_params) + return response.json() + +#7 - got 500 internal server error + def edit_customer(self, name, postal_code, phone): + request_body = { + "name": name, + "postal_code": postal_code, + "phone": phone + } + customer_url = self.url+"/customers/"+str(self.selected_customer["id"]) + print(f"about to send request to {customer_url}") + response = requests.put(customer_url,data=request_body) + print(response) + # if time allows: check for: if response.status_code == 200: + return response.json() + +#8- basics work + def delete_customer(self, selected_customer): + response = requests.delete(self.url+f"/customers/{self.selected_customer['id']}") + self.selected_customer = None + return response.json() + +#9- basics work + def get_all_customers(self): + response = requests.get(self.url+"/customers") + return response.json() + +#10- basics work + def get_customer_by_id(self, id=id): + response = requests.get(self.url+f"/customers/{id}") + # if time allows: check for: if response.status_code == 200: + self.selected_customer = response.json() + return response.json() + +#11 + def check_out(self, video_id, customer_id): + query_params = { + "video_id": video_id, + "customer_id": customer_id + } + response = requests.post(self.url+f"/rentals/check-out", json=query_params) + return response + +#12 + def check_in(self, video_id, customer_id): + query_params = { + "video_id": video_id, + "customer_id": customer_id + } + response = requests.post(self.url+f"/rentals/check-in", json=query_params) + return response