From 34b0244b3195066a6eca5b842bd52506207c9e42 Mon Sep 17 00:00:00 2001 From: Adelaide Date: Tue, 25 May 2021 19:12:48 -0600 Subject: [PATCH 1/5] create rough draft of not-yet-functional video-store CLI with processes for all 13 options --- main.py | 316 +++++++++++++++++++++++++++++++++++++++++++++++- main_enhance.py | 218 +++++++++++++++++++++++++++++++++ 2 files changed, 531 insertions(+), 3 deletions(-) create mode 100644 main_enhance.py diff --git a/main.py b/main.py index ed3f1a77..6aa93e2c 100644 --- a/main.py +++ b/main.py @@ -1,12 +1,322 @@ import requests URL = "http://127.0.0.1:5000" +# URL_customers = "http://127.0.0.1:5000/customers" 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: + # 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 main(play=True): + #I wrote URL instead of TaskList. is that right? + # video_store_customers = URL_customer(url="BACKUP_URL") + video_store = URL(url="BACKUP_URL") print("WELCOME TO RETRO VIDEO STORE") - pass + user_options = list_options() + + while play == True: + choice = make_choice(user_options, video_store) + video_store.print_selected() + + 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? ") + available_inventory = input("How many copies of this video do we have? ") + response = video_store.create_video(title=title, release_date=release_date, available_inventory=available_inventory ) + + print_stars() + print("New movie:", response["title"]) + + if choice == "2": + print(f"Let's EDIT a video: {video_store.selected_video}") + title=input("What is the updated title of the movie? ") + release_date=input("What is the updated release date of the movie? ") + available_inventory=input("What is the updated number of videos we have? ") + response = video_store.save(title=title, release_date=release_date, available_inventory=available_inventory ) + + print_stars() + print("Updated movie:", response["title"]["release_date"]["available_inventory"]) + + if choice == "3": + print(f"Let's DELETE a video: {video_store.selected_video}") + video_store.delete() + + print_stars() + print("Video has been deleted.") + + if choice == "4": + print(f"Let's get information about all videos. ") + print_stars() + videos = [video.to_json() for video in video_store.get_all_videos()] + print(videos) + + + if choice == "5": + print(f"Let's get information about: {video_store.selected_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_store.selected_video: + print_stars() + print(video.to_json()) + 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:", response["name"]) + + if choice == "7": + print(f"Let's EDIT a customer's info: {video_store.selected_customer}") + name = input("What is the updated name of the customer? ") + postal_code = input("What is their updated postal code? ") + phone = input("What is their updated phone number? ") + response = video_store.save(name=name, postal_code=postal_code, phone=phone) + + print_stars() + print("Updated customer:", response["name"]["postal_code"]["phone"]) + + if choice == "8": + print(f"Let's DELETE a customer: {video_store.selected_customer}") + video_store.delete() + + print_stars() + print("Customer has been deleted.") + + if choice == "9": + print(f"Let's get information about all customers. ") + print_stars() + customers = [customer.to_json() 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.to_json()) + 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) + + if 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) + + if not video_id.isnumeric() or not video_store.selected_video: + print("Please enter a valid numerical id. ") + + result = video_store.customer.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 inm 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) + + if 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) + + if not video_id.isnumeric() or not video_store.selected_video: + print("Please enter a valid numerical id. ") + + result = video_store.customer.check_out(video_id=video.id, customer_id=customer.id) + #delete rental? + print(f"You checkout 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() + + + + + # def run_cli(play=True): + +# #initialize task_list +# task_list = TaskList(url="https://beccas-task-list-c15.herokuapp.com/") + +# # print choices +# options = list_options() + +# while play==True: + +# # get input and validate +# choice = make_choice(options, task_list) + +# task_list.print_selected() + +# if choice=='1': +# print_stars() +# for task in task_list.list_tasks(): +# print(task) +# elif choice=='2': +# print("Great! Let's create a new task.") +# title=input("What is the title of your task? ") +# description=input("What is the description of your task? ") +# response = task_list.create_task(title=title, description=description) + +# print_stars() +# print("New task:", response["task"]) + +# elif choice=='3': +# select_by = input("Would you like to select by? Enter title or id: ") +# if select_by=="title": +# title = input("Which task title would you like to select? ") +# task_list.get_task(title=title) +# elif select_by=="id": +# id = input("Which task id would you like to select? ") +# if id.isnumeric(): +# id = int(id) +# task_list.get_task(id=id) +# else: +# print("Could not select. Please enter id or title.") + +# if task_list.selected_task: +# print_stars() +# print("Selected task: ", task_list.selected_task) + +# elif choice=='4': +# print(f"Great! Let's update the task: {task_list.selected_task}") +# title=input("What is the new title of your task? ") +# description=input("What is the new description of your task? ") +# response = task_list.update_task(title=title, description=description) + +# print_stars() +# print("Updated task:", response["task"]) +# elif choice=='5': +# task_list.delete_task() + +# print_stars() +# print("Task has been deleted.") + +# print_stars() +# print(task_list.list_tasks()) + +# elif choice=='6': +# response = task_list.mark_complete() + +# print_stars() +# print("Completed task: ", response["task"]) + +# elif choice=='7': +# response = task_list.mark_incomplete() + +# print_stars() +# print("Incomplete task: ", response["task"]) + +# elif choice=='8': +# for task in task_list.list_tasks(): +# task_list.get_task(id=task['id']) +# task_list.delete_task() + +# print_stars() +# print("Deleted all tasks.") +# elif choice=='9': +# list_options() +# elif choice=='10': +# play=False +# print("\nThanks for using the Task List CLI!") + +# print_stars() + +# run_cli() + + # for choice_num in options: + # print(f"Option {choice_num}. {options[choice_num]}") + + # print_stars() + + # return options + + +# def make_choice(options, task_list): +# 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: ") + +# if choice in ['4','5','6','7'] and task_list.selected_task == None: +# print("You must select a task before updating it, deleting it, marking it complete, or marking it incomplete.") +# print("Let's select a task!") +# choice = "3" + +# return choice + + diff --git a/main_enhance.py b/main_enhance.py new file mode 100644 index 00000000..25a85f96 --- /dev/null +++ b/main_enhance.py @@ -0,0 +1,218 @@ +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!") + + + + + + + # def run_cli(play=True): + +# #initialize task_list +# task_list = TaskList(url="https://beccas-task-list-c15.herokuapp.com/") + +# # print choices +# options = list_options() + +# while play==True: + +# # get input and validate +# choice = make_choice(options, task_list) + +# task_list.print_selected() + +# if choice=='1': +# print_stars() +# for task in task_list.list_tasks(): +# print(task) +# elif choice=='2': +# print("Great! Let's create a new task.") +# title=input("What is the title of your task? ") +# description=input("What is the description of your task? ") +# response = task_list.create_task(title=title, description=description) + +# print_stars() +# print("New task:", response["task"]) + +# elif choice=='3': +# select_by = input("Would you like to select by? Enter title or id: ") +# if select_by=="title": +# title = input("Which task title would you like to select? ") +# task_list.get_task(title=title) +# elif select_by=="id": +# id = input("Which task id would you like to select? ") +# if id.isnumeric(): +# id = int(id) +# task_list.get_task(id=id) +# else: +# print("Could not select. Please enter id or title.") + +# if task_list.selected_task: +# print_stars() +# print("Selected task: ", task_list.selected_task) + +# elif choice=='4': +# print(f"Great! Let's update the task: {task_list.selected_task}") +# title=input("What is the new title of your task? ") +# description=input("What is the new description of your task? ") +# response = task_list.update_task(title=title, description=description) + +# print_stars() +# print("Updated task:", response["task"]) +# elif choice=='5': +# task_list.delete_task() + +# print_stars() +# print("Task has been deleted.") + +# print_stars() +# print(task_list.list_tasks()) + +# elif choice=='6': +# response = task_list.mark_complete() + +# print_stars() +# print("Completed task: ", response["task"]) + +# elif choice=='7': +# response = task_list.mark_incomplete() + +# print_stars() +# print("Incomplete task: ", response["task"]) + +# elif choice=='8': +# for task in task_list.list_tasks(): +# task_list.get_task(id=task['id']) +# task_list.delete_task() + +# print_stars() +# print("Deleted all tasks.") +# elif choice=='9': +# list_options() +# elif choice=='10': +# play=False +# print("\nThanks for using the Task List CLI!") + +# print_stars() + +# run_cli() + + # for choice_num in options: + # print(f"Option {choice_num}. {options[choice_num]}") + + # print_stars() + + # return options + + +# def make_choice(options, task_list): +# 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: ") + +# if choice in ['4','5','6','7'] and task_list.selected_task == None: +# print("You must select a task before updating it, deleting it, marking it complete, or marking it incomplete.") +# print("Let's select a task!") +# choice = "3" + +# return choice + + + +if __name__ == "__main__": + main() \ No newline at end of file From 71a5d1d13200bc2b7251caa4ec9ea034e9e29ab0 Mon Sep 17 00:00:00 2001 From: Adelaide Date: Tue, 25 May 2021 22:20:31 -0600 Subject: [PATCH 2/5] populate gitignore --- .gitignore | 142 +++++++++++++++++++++++++++++++++++++++++++++++++ __init__.py | 42 +++++++++++++++ main.py | 121 +---------------------------------------- video_store.py | 2 + 4 files changed, 187 insertions(+), 120 deletions(-) create mode 100644 __init__.py create mode 100644 video_store.py 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..dc450e7a --- /dev/null +++ b/__init__.py @@ -0,0 +1,42 @@ +# from flask import Flask +# from flask_sqlalchemy import SQLAlchemy +# from flask_migrate import Migrate +# import os +# from dotenv import load_dotenv + +# load_dotenv() + +# db = SQLAlchemy() +# migrate = Migrate() + + + +# def create_app(test_config=None): +# app = Flask(__name__) +# app.url_map.strict_slashes = False +# app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False + +# if test_config is None: +# app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get( +# "SQLALCHEMY_DATABASE_URI") +# else: +# app.config["TESTING"] = True +# app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get( +# "SQLALCHEMY_TEST_DATABASE_URI") + + +# # import models for Alembic Setup +# from app.models.customer import Customer +# from app.models.video import Video +# from app.models.rental import Rental + +# # Setup DB +# db.init_app(app) +# migrate.init_app(app, db) + +# from .routes import videos_bp, customers_bp, rentals_bp +# app.register_blueprint(videos_bp) +# app.register_blueprint(customers_bp) +# app.register_blueprint(rentals_bp) + +# return app \ No newline at end of file diff --git a/main.py b/main.py index 6aa93e2c..84af2414 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,6 @@ import requests URL = "http://127.0.0.1:5000" -# URL_customers = "http://127.0.0.1:5000/customers" BACKUP_URL = "https://retro-video-store-api.herokuapp.com" def print_stars(): @@ -46,7 +45,7 @@ def make_choice(options, video_store): def main(play=True): #I wrote URL instead of TaskList. is that right? # video_store_customers = URL_customer(url="BACKUP_URL") - video_store = URL(url="BACKUP_URL") + video_store = TaskList(url="BACKUP_URL") print("WELCOME TO RETRO VIDEO STORE") user_options = list_options() @@ -202,121 +201,3 @@ def main(play=True): if __name__ == "__main__": main() - - - - # def run_cli(play=True): - -# #initialize task_list -# task_list = TaskList(url="https://beccas-task-list-c15.herokuapp.com/") - -# # print choices -# options = list_options() - -# while play==True: - -# # get input and validate -# choice = make_choice(options, task_list) - -# task_list.print_selected() - -# if choice=='1': -# print_stars() -# for task in task_list.list_tasks(): -# print(task) -# elif choice=='2': -# print("Great! Let's create a new task.") -# title=input("What is the title of your task? ") -# description=input("What is the description of your task? ") -# response = task_list.create_task(title=title, description=description) - -# print_stars() -# print("New task:", response["task"]) - -# elif choice=='3': -# select_by = input("Would you like to select by? Enter title or id: ") -# if select_by=="title": -# title = input("Which task title would you like to select? ") -# task_list.get_task(title=title) -# elif select_by=="id": -# id = input("Which task id would you like to select? ") -# if id.isnumeric(): -# id = int(id) -# task_list.get_task(id=id) -# else: -# print("Could not select. Please enter id or title.") - -# if task_list.selected_task: -# print_stars() -# print("Selected task: ", task_list.selected_task) - -# elif choice=='4': -# print(f"Great! Let's update the task: {task_list.selected_task}") -# title=input("What is the new title of your task? ") -# description=input("What is the new description of your task? ") -# response = task_list.update_task(title=title, description=description) - -# print_stars() -# print("Updated task:", response["task"]) -# elif choice=='5': -# task_list.delete_task() - -# print_stars() -# print("Task has been deleted.") - -# print_stars() -# print(task_list.list_tasks()) - -# elif choice=='6': -# response = task_list.mark_complete() - -# print_stars() -# print("Completed task: ", response["task"]) - -# elif choice=='7': -# response = task_list.mark_incomplete() - -# print_stars() -# print("Incomplete task: ", response["task"]) - -# elif choice=='8': -# for task in task_list.list_tasks(): -# task_list.get_task(id=task['id']) -# task_list.delete_task() - -# print_stars() -# print("Deleted all tasks.") -# elif choice=='9': -# list_options() -# elif choice=='10': -# play=False -# print("\nThanks for using the Task List CLI!") - -# print_stars() - -# run_cli() - - # for choice_num in options: - # print(f"Option {choice_num}. {options[choice_num]}") - - # print_stars() - - # return options - - -# def make_choice(options, task_list): -# 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: ") - -# if choice in ['4','5','6','7'] and task_list.selected_task == None: -# print("You must select a task before updating it, deleting it, marking it complete, or marking it incomplete.") -# print("Let's select a task!") -# choice = "3" - -# return choice - - diff --git a/video_store.py b/video_store.py new file mode 100644 index 00000000..dc934641 --- /dev/null +++ b/video_store.py @@ -0,0 +1,2 @@ +class VideoStore(): + \ No newline at end of file From 6a0d11c550186211e192df7237262f1695275886 Mon Sep 17 00:00:00 2001 From: Adelaide Date: Fri, 28 May 2021 16:41:19 -0600 Subject: [PATCH 3/5] created CLI code for 13 user options, and VideoStore model with basic working code for 11 of the options, not yet accounting for edge cases --- __init__.py | 42 -------------- main.py | 82 ++++++++++++++++----------- main_enhance.py | 120 --------------------------------------- video_store.py | 147 +++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 194 insertions(+), 197 deletions(-) diff --git a/__init__.py b/__init__.py index dc450e7a..e69de29b 100644 --- a/__init__.py +++ b/__init__.py @@ -1,42 +0,0 @@ -# from flask import Flask -# from flask_sqlalchemy import SQLAlchemy -# from flask_migrate import Migrate -# import os -# from dotenv import load_dotenv - -# load_dotenv() - -# db = SQLAlchemy() -# migrate = Migrate() - - - -# def create_app(test_config=None): -# app = Flask(__name__) -# app.url_map.strict_slashes = False -# app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False - -# if test_config is None: -# app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get( -# "SQLALCHEMY_DATABASE_URI") -# else: -# app.config["TESTING"] = True -# app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get( -# "SQLALCHEMY_TEST_DATABASE_URI") - - -# # import models for Alembic Setup -# from app.models.customer import Customer -# from app.models.video import Video -# from app.models.rental import Rental - -# # Setup DB -# db.init_app(app) -# migrate.init_app(app, db) - -# from .routes import videos_bp, customers_bp, rentals_bp -# app.register_blueprint(videos_bp) -# app.register_blueprint(customers_bp) -# app.register_blueprint(rentals_bp) - -# return app \ No newline at end of file diff --git a/main.py b/main.py index 84af2414..9abe2473 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,4 @@ -import requests +from video_store import VideoStore URL = "http://127.0.0.1:5000" BACKUP_URL = "https://retro-video-store-api.herokuapp.com" @@ -40,19 +40,17 @@ def make_choice(options, video_store): - - def main(play=True): - #I wrote URL instead of TaskList. is that right? - # video_store_customers = URL_customer(url="BACKUP_URL") - video_store = TaskList(url="BACKUP_URL") + #initialize task_list + video_store = VideoStore(url=BACKUP_URL) + print("WELCOME TO RETRO VIDEO STORE") - user_options = list_options() + options = list_options() while play == True: - choice = make_choice(user_options, video_store) - video_store.print_selected() + choice = make_choice(options, video_store) + video_store.print_selected(choice) if choice == "1": print(f"Let's add a new video") @@ -65,18 +63,26 @@ def main(play=True): print("New movie:", response["title"]) if choice == "2": - print(f"Let's EDIT a video: {video_store.selected_video}") - title=input("What is the updated title of the movie? ") - release_date=input("What is the updated release date of the movie? ") - available_inventory=input("What is the updated number of videos we have? ") - response = video_store.save(title=title, release_date=release_date, available_inventory=available_inventory ) + 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? ") + available_inventory=input("What is the correct inventory? ") + response = video_store.edit_video(title=title, release_date=release_date, available_inventory=available_inventory) print_stars() - print("Updated movie:", response["title"]["release_date"]["available_inventory"]) + print("Updated movie: ", response) if choice == "3": - print(f"Let's DELETE a video: {video_store.selected_video}") - video_store.delete() + 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.") @@ -84,20 +90,21 @@ def main(play=True): if choice == "4": print(f"Let's get information about all videos. ") print_stars() - videos = [video.to_json() for video in video_store.get_all_videos()] + videos = [video for video in video_store.get_all_videos()] print(videos) if choice == "5": - print(f"Let's get information about: {video_store.selected_video} ") + # print(f"Let's get information about: {video_store.selected_video} ") + 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_store.selected_video: + if video: print_stars() - print(video.to_json()) + print(video) else: print("Please enter a numerical id. ") @@ -109,21 +116,28 @@ def main(play=True): response = video_store.create_customer(name=name, postal_code=postal_code, phone=phone) print_stars() - print("New customer:", response["name"]) + print("New customer has been created and given id #", response["id"]) if choice == "7": - print(f"Let's EDIT a customer's info: {video_store.selected_customer}") - name = input("What is the updated name of the customer? ") - postal_code = input("What is their updated postal code? ") - phone = input("What is their updated phone number? ") - response = video_store.save(name=name, postal_code=postal_code, phone=phone) + 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["name"]["postal_code"]["phone"]) + print("Updated customer: ", response) if choice == "8": - print(f"Let's DELETE a customer: {video_store.selected_customer}") - video_store.delete() + 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.") @@ -131,7 +145,7 @@ def main(play=True): if choice == "9": print(f"Let's get information about all customers. ") print_stars() - customers = [customer.to_json() for customer in video_store.get_all_customers()] + customers = [customer for customer in video_store.get_all_customers()] print(customers) @@ -144,7 +158,7 @@ def main(play=True): customer = video_store.get_customer_by_id(id=id) if video_store.selected_customer: print_stars() - print(customer.to_json()) + print(customer) else: print("Please enter a numerical id. ") @@ -164,7 +178,7 @@ def main(play=True): video_id = int(video_id) video = video_store.get_video_by_id(id=video_id) - if not video_id.isnumeric() or not video_store.selected_video: + if not video_id.isnumeric() or not video_store.video: print("Please enter a valid numerical id. ") result = video_store.customer.check_out(video_id=video.id, customer_id=customer.id) @@ -187,7 +201,7 @@ def main(play=True): video_id = int(video_id) video = video_store.get_video_by_id(id=video_id) - if not video_id.isnumeric() or not video_store.selected_video: + if not video_id.isnumeric() or not video_store.video: print("Please enter a valid numerical id. ") result = video_store.customer.check_out(video_id=video.id, customer_id=customer.id) diff --git a/main_enhance.py b/main_enhance.py index 25a85f96..7b195437 100644 --- a/main_enhance.py +++ b/main_enhance.py @@ -94,125 +94,5 @@ def main(play=True): print("\nThanks for using the Video Store CLI!") - - - - - # def run_cli(play=True): - -# #initialize task_list -# task_list = TaskList(url="https://beccas-task-list-c15.herokuapp.com/") - -# # print choices -# options = list_options() - -# while play==True: - -# # get input and validate -# choice = make_choice(options, task_list) - -# task_list.print_selected() - -# if choice=='1': -# print_stars() -# for task in task_list.list_tasks(): -# print(task) -# elif choice=='2': -# print("Great! Let's create a new task.") -# title=input("What is the title of your task? ") -# description=input("What is the description of your task? ") -# response = task_list.create_task(title=title, description=description) - -# print_stars() -# print("New task:", response["task"]) - -# elif choice=='3': -# select_by = input("Would you like to select by? Enter title or id: ") -# if select_by=="title": -# title = input("Which task title would you like to select? ") -# task_list.get_task(title=title) -# elif select_by=="id": -# id = input("Which task id would you like to select? ") -# if id.isnumeric(): -# id = int(id) -# task_list.get_task(id=id) -# else: -# print("Could not select. Please enter id or title.") - -# if task_list.selected_task: -# print_stars() -# print("Selected task: ", task_list.selected_task) - -# elif choice=='4': -# print(f"Great! Let's update the task: {task_list.selected_task}") -# title=input("What is the new title of your task? ") -# description=input("What is the new description of your task? ") -# response = task_list.update_task(title=title, description=description) - -# print_stars() -# print("Updated task:", response["task"]) -# elif choice=='5': -# task_list.delete_task() - -# print_stars() -# print("Task has been deleted.") - -# print_stars() -# print(task_list.list_tasks()) - -# elif choice=='6': -# response = task_list.mark_complete() - -# print_stars() -# print("Completed task: ", response["task"]) - -# elif choice=='7': -# response = task_list.mark_incomplete() - -# print_stars() -# print("Incomplete task: ", response["task"]) - -# elif choice=='8': -# for task in task_list.list_tasks(): -# task_list.get_task(id=task['id']) -# task_list.delete_task() - -# print_stars() -# print("Deleted all tasks.") -# elif choice=='9': -# list_options() -# elif choice=='10': -# play=False -# print("\nThanks for using the Task List CLI!") - -# print_stars() - -# run_cli() - - # for choice_num in options: - # print(f"Option {choice_num}. {options[choice_num]}") - - # print_stars() - - # return options - - -# def make_choice(options, task_list): -# 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: ") - -# if choice in ['4','5','6','7'] and task_list.selected_task == None: -# print("You must select a task before updating it, deleting it, marking it complete, or marking it incomplete.") -# print("Let's select a task!") -# choice = "3" - -# return choice - - - if __name__ == "__main__": main() \ No newline at end of file diff --git a/video_store.py b/video_store.py index dc934641..66e55458 100644 --- a/video_store.py +++ b/video_store.py @@ -1,2 +1,147 @@ +import requests +import datetime + class VideoStore(): - \ No newline at end of file + 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 self.choice: + # print(f"You have selected #{self.choice}\n") + if choice: + print(f"You have selected #{choice}\n") + +#1 - got 500 internal server error + def create_video(self, title, release_date, available_inventory=None): + query_params = { + "title": title, + "release_date": release_date, + "available_inventory": available_inventory + } + video_url = self.url+"/videos" + print(f"about to send request to {video_url}") + response = requests.post(video_url,data=query_params) + print(response) + if response.status_code == 200: + return response.json() + # else: + + +#2 - got 500 internal server error + def edit_video(self, title, release_date, available_inventory): + request_body = { + "title": title, + "release_date": release_date, + "available_inventory": available_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,data=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 post req to api +# video_store.save(name=name, postal_code=postal_code, phone=phone) + +# video_store.customer.check_out(video_id=video.id, customer_id=customer.id) + + + + + # def update_task(self,title=None,description=None): + # if not title: + # title = self.selected_task["title"] + # if not description: + # description = self.selected_task["description"] + + # query_params = { + # "title": title, + # "description": description + # #"completed_at": self.selected_task["is_complete"] + # } + # response = requests.put( + # self.url+f"/tasks/{self.selected_task['id']}", + # json=query_params + # ) + # print("response:", response) + # self.selected_task = response.json()["task"] + # 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() + + + From a6bc375ea99782c769d3638b3800690e65f4902e Mon Sep 17 00:00:00 2001 From: Adelaide Date: Wed, 2 Jun 2021 22:21:32 -0700 Subject: [PATCH 4/5] add functioning options for 11 and 12, and fix 500 errors in options 1 and 2 --- main.py | 26 ++++++++++++------------ video_store.py | 55 ++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 53 insertions(+), 28 deletions(-) diff --git a/main.py b/main.py index 9abe2473..a532e788 100644 --- a/main.py +++ b/main.py @@ -56,11 +56,11 @@ def main(play=True): 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? ") - available_inventory = input("How many copies of this video do we have? ") - response = video_store.create_video(title=title, release_date=release_date, available_inventory=available_inventory ) + 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["title"]) + print("New movie:", response) if choice == "2": print(f"Let's EDIT a video. ") @@ -69,8 +69,8 @@ def main(play=True): print("Current movie information: ", original_video_response) title=input("What is the correct title? ") release_date=input("What is the correct release date? ") - available_inventory=input("What is the correct inventory? ") - response = video_store.edit_video(title=title, release_date=release_date, available_inventory=available_inventory) + 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) @@ -170,7 +170,7 @@ def main(play=True): customer_id = int(customer_id) customer = video_store.get_customer_by_id(id=customer_id) - if not customer_id.isnumeric() or not video_store.selected_customer: + 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? ") @@ -178,22 +178,22 @@ def main(play=True): video_id = int(video_id) video = video_store.get_video_by_id(id=video_id) - if not video_id.isnumeric() or not video_store.video: + elif not video_id.isnumeric() or not video_store.video: print("Please enter a valid numerical id. ") - result = video_store.customer.check_out(video_id=video.id, customer_id=customer.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 inm a video from a customer. ") + 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) - if not customer_id.isnumeric() or not video_store.selected_customer: + 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? ") @@ -201,12 +201,12 @@ def main(play=True): video_id = int(video_id) video = video_store.get_video_by_id(id=video_id) - if not video_id.isnumeric() or not video_store.video: + elif not video_id.isnumeric() or not video_store.video: print("Please enter a valid numerical id. ") - result = video_store.customer.check_out(video_id=video.id, customer_id=customer.id) + result = video_store.check_in(video_id=video_id, customer_id=customer_id) #delete rental? - print(f"You checkout has been successful: {result}") + print(f"You checkin has been successful: {result}") if choice == "13": play=False diff --git a/video_store.py b/video_store.py index 66e55458..5cf93f9d 100644 --- a/video_store.py +++ b/video_store.py @@ -1,5 +1,6 @@ import requests import datetime +from flask import json class VideoStore(): def __init__(self, url="http://localhost:5000", selected_video=None, selected_customer=None): @@ -13,32 +14,32 @@ def print_selected(self, choice): if choice: print(f"You have selected #{choice}\n") -#1 - got 500 internal server error - def create_video(self, title, release_date, available_inventory=None): +#1 + def create_video(self, title, release_date, total_inventory): query_params = { "title": title, "release_date": release_date, - "available_inventory": available_inventory + "total_inventory": total_inventory } video_url = self.url+"/videos" print(f"about to send request to {video_url}") - response = requests.post(video_url,data=query_params) + response = requests.post(video_url,json=query_params) print(response) - if response.status_code == 200: - return response.json() + # if time allows: check for: if response.status_code == 200: + return response.json() # else: #2 - got 500 internal server error - def edit_video(self, title, release_date, available_inventory): + def edit_video(self, title, release_date, total_inventory): request_body = { "title": title, "release_date": release_date, - "available_inventory": available_inventory + "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,data=request_body) + response = requests.put(video_url,json=request_body) print(response) # if time allows: check for: if response.status_code == 200: return response.json() @@ -103,13 +104,37 @@ def get_customer_by_id(self, id=id): 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 -#11 post req to api -# video_store.save(name=name, postal_code=postal_code, phone=phone) - -# video_store.customer.check_out(video_id=video.id, customer_id=customer.id) - - +#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 + + + + # query_params = { + # "title": title, + # "release_date": release_date, + # "available_inventory": available_inventory + # } + # video_url = self.url+"/videos" + # print(f"about to send request to {video_url}") + # response = requests.post(video_url,data=query_params) + # print(response) + # # if time allows: check for: if response.status_code == 200: + # return response.json() # def update_task(self,title=None,description=None): From 2850aab07b3951aa54c8800f6735cb3da17e9042 Mon Sep 17 00:00:00 2001 From: Adelaide Date: Wed, 2 Jun 2021 22:24:34 -0700 Subject: [PATCH 5/5] delete unnecessary comments --- main.py | 5 +---- video_store.py | 53 +------------------------------------------------- 2 files changed, 2 insertions(+), 56 deletions(-) diff --git a/main.py b/main.py index a532e788..a65c08b4 100644 --- a/main.py +++ b/main.py @@ -33,7 +33,6 @@ 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 @@ -95,7 +94,6 @@ def main(play=True): if choice == "5": - # print(f"Let's get information about: {video_store.selected_video} ") 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? ") @@ -205,8 +203,7 @@ def main(play=True): print("Please enter a valid numerical id. ") result = video_store.check_in(video_id=video_id, customer_id=customer_id) - #delete rental? - print(f"You checkin has been successful: {result}") + print(f"You check-in has been successful: {result}") if choice == "13": play=False diff --git a/video_store.py b/video_store.py index 5cf93f9d..914edfd5 100644 --- a/video_store.py +++ b/video_store.py @@ -9,8 +9,6 @@ def __init__(self, url="http://localhost:5000", selected_video=None, selected_cu self.selected_customer = selected_customer def print_selected(self, choice): - # if self.choice: - # print(f"You have selected #{self.choice}\n") if choice: print(f"You have selected #{choice}\n") @@ -30,7 +28,7 @@ def create_video(self, title, release_date, total_inventory): # else: -#2 - got 500 internal server error +#2 def edit_video(self, title, release_date, total_inventory): request_body = { "title": title, @@ -121,52 +119,3 @@ def check_in(self, video_id, customer_id): } response = requests.post(self.url+f"/rentals/check-in", json=query_params) return response - - - - # query_params = { - # "title": title, - # "release_date": release_date, - # "available_inventory": available_inventory - # } - # video_url = self.url+"/videos" - # print(f"about to send request to {video_url}") - # response = requests.post(video_url,data=query_params) - # print(response) - # # if time allows: check for: if response.status_code == 200: - # return response.json() - - - # def update_task(self,title=None,description=None): - # if not title: - # title = self.selected_task["title"] - # if not description: - # description = self.selected_task["description"] - - # query_params = { - # "title": title, - # "description": description - # #"completed_at": self.selected_task["is_complete"] - # } - # response = requests.put( - # self.url+f"/tasks/{self.selected_task['id']}", - # json=query_params - # ) - # print("response:", response) - # self.selected_task = response.json()["task"] - # 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() - - -