-
Notifications
You must be signed in to change notification settings - Fork 70
Scissors: Mai Truong #60
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?
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 | ||||
|---|---|---|---|---|---|---|
| @@ -1,12 +1,142 @@ | ||||||
| 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(): | ||||||
| videos = VideoStore() | ||||||
| print("WELCOME TO RETRO VIDEO STORE") | ||||||
| pass | ||||||
| print("\n************************************\n") | ||||||
| print("Please choose an option") | ||||||
| print("Enter 1 to manage videos") | ||||||
| print("Enter 2 to customers") | ||||||
| print("Enter 3 to check-in/check-out") | ||||||
|
|
||||||
| main_choice = input("Enter your choice: ") | ||||||
| print("\n************************************\n") | ||||||
|
|
||||||
| if main_choice == "1": | ||||||
| print("What would you like to do in videos? ") | ||||||
|
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 recommend pulling each sub menu section into separate functions: and then also break the sub menu into helper functions: |
||||||
| print("Enter 1 to see all videos") | ||||||
| print("Enter 2 to add video") | ||||||
| print("Enter 3 to update a video") | ||||||
| print("Enter 4 to delete a video") | ||||||
| print("Enter 5 to get a video") | ||||||
| choice = input("Enter your choice: ") | ||||||
| if choice == "1": | ||||||
| print("Here is a list of all videos") | ||||||
| for video in videos.get_all_videos(): | ||||||
| print(video) | ||||||
|
|
||||||
| elif choice == "2": | ||||||
| print("You are about to add a new movie.") | ||||||
| title = input("What is the title of the movie? ") | ||||||
| release_date = input(f"When was {title} released? Please enter in yyyy-mm-dd. ") | ||||||
| total_inventory = input(f"What is the total inventory of {title}? ") | ||||||
| response = videos.add_video(title = title, release_date = release_date, total_inventory = total_inventory) | ||||||
|
|
||||||
| print(f"{title} was created") | ||||||
|
|
||||||
| elif choice == "3": | ||||||
| video_id = input("Enter a video id: ") | ||||||
| print(f"You are about to update a movie with video id: {video_id}") | ||||||
| title = input("What is the new movie title? ") | ||||||
| release_date = input(f"When was {title} released? Please enter in yyyy-mm-dd. ") | ||||||
| total_inventory = input(f"What is the total inventory of {title}? ") | ||||||
| response = videos.edit_video(video_id = video_id, title = title, release_date = release_date, total_inventory = total_inventory) | ||||||
|
|
||||||
| print(f"{title} is now updated") | ||||||
|
Comment on lines
+48
to
+50
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. This UI assumes that the user will only enter video ids that are valid. In the case where they are not valid, the return from the server will contain an error code and an error message. I recommend checking for those error messages or the error code before printing a success message. |
||||||
|
|
||||||
| elif choice == "4": | ||||||
| try: | ||||||
| print("You are about to delete a movie.") | ||||||
| video_id = input("Enter a video id: ") | ||||||
| videos.delete_video(video_id) | ||||||
| print("This video has been deleted.") | ||||||
|
|
||||||
| except: | ||||||
|
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. Unless there's some other error in the system, inputing an invalid video id will not trigger this except sequence. The request will return an error code, but that doesn't throw an exception. A secondary issue is what is the desired behavior if a user inputs a video id that does not exist multiple times? If the except block did catch an invalid id, inputing another invalid id inside the except block would not catch the error. Using a while loop with some kind of error checking makes it possible to continue to request the information from the user until they input a valid id. |
||||||
| video_id not in videos.get_all_videos() | ||||||
| print("Enter a valid video id.") | ||||||
| video_id = input("Enter a video id: ") | ||||||
| videos.delete_video(video_id) | ||||||
| print("This video has been deleted.") | ||||||
|
|
||||||
| elif choice == "5": | ||||||
| print("What video would you like to view? ") | ||||||
| video_id = input("Enter a video id: ") | ||||||
| response = videos.get_video(video_id = video_id) | ||||||
| print(response) | ||||||
|
|
||||||
| else: | ||||||
| print("Please enter a valid choice") | ||||||
|
|
||||||
| elif main_choice == "2": | ||||||
| print("What would you like to do in customers? ") | ||||||
| print("Enter 1 to see all customers") | ||||||
| print("Enter 2 to add customer") | ||||||
| print("Enter 3 to update customer") | ||||||
| print("Enter 4 to delete a customer") | ||||||
| print("Enter 5 to retrieve customer") | ||||||
| choice = input("Enter your choice: ") | ||||||
| if choice == "1": | ||||||
| print("Here is a list of all customers") | ||||||
| for customer in videos.get_all_customers(): | ||||||
| print(customer) | ||||||
|
|
||||||
| elif choice == "2": | ||||||
| print("You are about to add a new customer.") | ||||||
| name = input("What is the customer's name? ") | ||||||
| postal_code = input("What is customer's postal code? ") | ||||||
| phone = input("What is customer's phone number? ") | ||||||
| response = videos.add_customer(name = name, postal_code = postal_code, phone_number = phone) | ||||||
|
|
||||||
| print(f"{name} was created") | ||||||
|
|
||||||
| elif choice == "3": | ||||||
| customer_id = input("Enter customer's id: ") | ||||||
| print(f"You are about to update a customer with id: {customer_id}") | ||||||
| postal_code = input("What is customer's new postal code? ") | ||||||
| phone = input("What is customer's new phone? ") | ||||||
| response = videos.edit_customer(customer_id = customer_id, postal_code = postal_code, phone = phone) | ||||||
|
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.
Suggested change
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. videos.edit_customer uses a default of None for name, so this will result in the name field being set to None. |
||||||
|
|
||||||
| print(f"{customer_id} is now updated") | ||||||
|
|
||||||
| elif choice == "4": | ||||||
| try: | ||||||
| print("You are about to delete customer.") | ||||||
| customer_id = input("Enter customer's id: ") | ||||||
| videos.delete_customer(customer_id) | ||||||
| print("This customer has been deleted.") | ||||||
|
|
||||||
| except: | ||||||
| customer_id not in videos.get_all_customers() | ||||||
| print("Enter a valid customer id.") | ||||||
| customer_id = input("Enter a customer id: ") | ||||||
| videos.delete_customer(customer_id) | ||||||
| print("This customer has been deleted.") | ||||||
|
|
||||||
| elif choice == "5": | ||||||
| print("What customer would you like to view? ") | ||||||
| customer_id = input("Enter a customer id: ") | ||||||
| response = videos.get_customer(customer_id) | ||||||
| print({ | ||||||
| "id" : response["id"], | ||||||
| "name" : response["name"], | ||||||
| "phone" : response["phone_number"], | ||||||
| "postal_code" : response["postal_code"], | ||||||
| "registered_at" : response["registered_at"], | ||||||
| }) | ||||||
|
|
||||||
| else: | ||||||
| print("Please enter a valid choice") | ||||||
|
|
||||||
| elif main_choice == "3": | ||||||
| print("Would you like to check-in? ") | ||||||
|
|
||||||
| else: | ||||||
| print("Please enter a valid choice") | ||||||
|
|
||||||
|
|
||||||
| if __name__ == "__main__": | ||||||
| main() | ||||||
| main() | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,241 @@ | ||
| <# | ||
| .Synopsis | ||
| Activate a Python virtual environment for the current PowerShell session. | ||
|
|
||
| .Description | ||
| Pushes the python executable for a virtual environment to the front of the | ||
| $Env:PATH environment variable and sets the prompt to signify that you are | ||
| in a Python virtual environment. Makes use of the command line switches as | ||
| well as the `pyvenv.cfg` file values present in the virtual environment. | ||
|
|
||
| .Parameter VenvDir | ||
| Path to the directory that contains the virtual environment to activate. The | ||
| default value for this is the parent of the directory that the Activate.ps1 | ||
| script is located within. | ||
|
|
||
| .Parameter Prompt | ||
| The prompt prefix to display when this virtual environment is activated. By | ||
| default, this prompt is the name of the virtual environment folder (VenvDir) | ||
| surrounded by parentheses and followed by a single space (ie. '(.venv) '). | ||
|
|
||
| .Example | ||
| Activate.ps1 | ||
| Activates the Python virtual environment that contains the Activate.ps1 script. | ||
|
|
||
| .Example | ||
| Activate.ps1 -Verbose | ||
| Activates the Python virtual environment that contains the Activate.ps1 script, | ||
| and shows extra information about the activation as it executes. | ||
|
|
||
| .Example | ||
| Activate.ps1 -VenvDir C:\Users\MyUser\Common\.venv | ||
| Activates the Python virtual environment located in the specified location. | ||
|
|
||
| .Example | ||
| Activate.ps1 -Prompt "MyPython" | ||
| Activates the Python virtual environment that contains the Activate.ps1 script, | ||
| and prefixes the current prompt with the specified string (surrounded in | ||
| parentheses) while the virtual environment is active. | ||
|
|
||
| .Notes | ||
| On Windows, it may be required to enable this Activate.ps1 script by setting the | ||
| execution policy for the user. You can do this by issuing the following PowerShell | ||
| command: | ||
|
|
||
| PS C:\> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser | ||
|
|
||
| For more information on Execution Policies: | ||
| https://go.microsoft.com/fwlink/?LinkID=135170 | ||
|
|
||
| #> | ||
| Param( | ||
| [Parameter(Mandatory = $false)] | ||
| [String] | ||
| $VenvDir, | ||
| [Parameter(Mandatory = $false)] | ||
| [String] | ||
| $Prompt | ||
| ) | ||
|
|
||
| <# Function declarations --------------------------------------------------- #> | ||
|
|
||
| <# | ||
| .Synopsis | ||
| Remove all shell session elements added by the Activate script, including the | ||
| addition of the virtual environment's Python executable from the beginning of | ||
| the PATH variable. | ||
|
|
||
| .Parameter NonDestructive | ||
| If present, do not remove this function from the global namespace for the | ||
| session. | ||
|
|
||
| #> | ||
| function global:deactivate ([switch]$NonDestructive) { | ||
| # Revert to original values | ||
|
|
||
| # The prior prompt: | ||
| if (Test-Path -Path Function:_OLD_VIRTUAL_PROMPT) { | ||
| Copy-Item -Path Function:_OLD_VIRTUAL_PROMPT -Destination Function:prompt | ||
| Remove-Item -Path Function:_OLD_VIRTUAL_PROMPT | ||
| } | ||
|
|
||
| # The prior PYTHONHOME: | ||
| if (Test-Path -Path Env:_OLD_VIRTUAL_PYTHONHOME) { | ||
| Copy-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME -Destination Env:PYTHONHOME | ||
| Remove-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME | ||
| } | ||
|
|
||
| # The prior PATH: | ||
| if (Test-Path -Path Env:_OLD_VIRTUAL_PATH) { | ||
| Copy-Item -Path Env:_OLD_VIRTUAL_PATH -Destination Env:PATH | ||
| Remove-Item -Path Env:_OLD_VIRTUAL_PATH | ||
| } | ||
|
|
||
| # Just remove the VIRTUAL_ENV altogether: | ||
| if (Test-Path -Path Env:VIRTUAL_ENV) { | ||
| Remove-Item -Path env:VIRTUAL_ENV | ||
| } | ||
|
|
||
| # Just remove the _PYTHON_VENV_PROMPT_PREFIX altogether: | ||
| if (Get-Variable -Name "_PYTHON_VENV_PROMPT_PREFIX" -ErrorAction SilentlyContinue) { | ||
| Remove-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Scope Global -Force | ||
| } | ||
|
|
||
| # Leave deactivate function in the global namespace if requested: | ||
| if (-not $NonDestructive) { | ||
| Remove-Item -Path function:deactivate | ||
| } | ||
| } | ||
|
|
||
| <# | ||
| .Description | ||
| Get-PyVenvConfig parses the values from the pyvenv.cfg file located in the | ||
| given folder, and returns them in a map. | ||
|
|
||
| For each line in the pyvenv.cfg file, if that line can be parsed into exactly | ||
| two strings separated by `=` (with any amount of whitespace surrounding the =) | ||
| then it is considered a `key = value` line. The left hand string is the key, | ||
| the right hand is the value. | ||
|
|
||
| If the value starts with a `'` or a `"` then the first and last character is | ||
| stripped from the value before being captured. | ||
|
|
||
| .Parameter ConfigDir | ||
| Path to the directory that contains the `pyvenv.cfg` file. | ||
| #> | ||
| function Get-PyVenvConfig( | ||
| [String] | ||
| $ConfigDir | ||
| ) { | ||
| Write-Verbose "Given ConfigDir=$ConfigDir, obtain values in pyvenv.cfg" | ||
|
|
||
| # Ensure the file exists, and issue a warning if it doesn't (but still allow the function to continue). | ||
| $pyvenvConfigPath = Join-Path -Resolve -Path $ConfigDir -ChildPath 'pyvenv.cfg' -ErrorAction Continue | ||
|
|
||
| # An empty map will be returned if no config file is found. | ||
| $pyvenvConfig = @{ } | ||
|
|
||
| if ($pyvenvConfigPath) { | ||
|
|
||
| Write-Verbose "File exists, parse `key = value` lines" | ||
| $pyvenvConfigContent = Get-Content -Path $pyvenvConfigPath | ||
|
|
||
| $pyvenvConfigContent | ForEach-Object { | ||
| $keyval = $PSItem -split "\s*=\s*", 2 | ||
| if ($keyval[0] -and $keyval[1]) { | ||
| $val = $keyval[1] | ||
|
|
||
| # Remove extraneous quotations around a string value. | ||
| if ("'""".Contains($val.Substring(0, 1))) { | ||
| $val = $val.Substring(1, $val.Length - 2) | ||
| } | ||
|
|
||
| $pyvenvConfig[$keyval[0]] = $val | ||
| Write-Verbose "Adding Key: '$($keyval[0])'='$val'" | ||
| } | ||
| } | ||
| } | ||
| return $pyvenvConfig | ||
| } | ||
|
|
||
|
|
||
| <# Begin Activate script --------------------------------------------------- #> | ||
|
|
||
| # Determine the containing directory of this script | ||
| $VenvExecPath = Split-Path -Parent $MyInvocation.MyCommand.Definition | ||
| $VenvExecDir = Get-Item -Path $VenvExecPath | ||
|
|
||
| Write-Verbose "Activation script is located in path: '$VenvExecPath'" | ||
| Write-Verbose "VenvExecDir Fullname: '$($VenvExecDir.FullName)" | ||
| Write-Verbose "VenvExecDir Name: '$($VenvExecDir.Name)" | ||
|
|
||
| # Set values required in priority: CmdLine, ConfigFile, Default | ||
| # First, get the location of the virtual environment, it might not be | ||
| # VenvExecDir if specified on the command line. | ||
| if ($VenvDir) { | ||
| Write-Verbose "VenvDir given as parameter, using '$VenvDir' to determine values" | ||
| } | ||
| else { | ||
| Write-Verbose "VenvDir not given as a parameter, using parent directory name as VenvDir." | ||
| $VenvDir = $VenvExecDir.Parent.FullName.TrimEnd("\\/") | ||
| Write-Verbose "VenvDir=$VenvDir" | ||
| } | ||
|
|
||
| # Next, read the `pyvenv.cfg` file to determine any required value such | ||
| # as `prompt`. | ||
| $pyvenvCfg = Get-PyVenvConfig -ConfigDir $VenvDir | ||
|
|
||
| # Next, set the prompt from the command line, or the config file, or | ||
| # just use the name of the virtual environment folder. | ||
| if ($Prompt) { | ||
| Write-Verbose "Prompt specified as argument, using '$Prompt'" | ||
| } | ||
| else { | ||
| Write-Verbose "Prompt not specified as argument to script, checking pyvenv.cfg value" | ||
| if ($pyvenvCfg -and $pyvenvCfg['prompt']) { | ||
| Write-Verbose " Setting based on value in pyvenv.cfg='$($pyvenvCfg['prompt'])'" | ||
| $Prompt = $pyvenvCfg['prompt']; | ||
| } | ||
| else { | ||
| Write-Verbose " Setting prompt based on parent's directory's name. (Is the directory name passed to venv module when creating the virutal environment)" | ||
| Write-Verbose " Got leaf-name of $VenvDir='$(Split-Path -Path $venvDir -Leaf)'" | ||
| $Prompt = Split-Path -Path $venvDir -Leaf | ||
| } | ||
| } | ||
|
|
||
| Write-Verbose "Prompt = '$Prompt'" | ||
| Write-Verbose "VenvDir='$VenvDir'" | ||
|
|
||
| # Deactivate any currently active virtual environment, but leave the | ||
| # deactivate function in place. | ||
| deactivate -nondestructive | ||
|
|
||
| # Now set the environment variable VIRTUAL_ENV, used by many tools to determine | ||
| # that there is an activated venv. | ||
| $env:VIRTUAL_ENV = $VenvDir | ||
|
|
||
| if (-not $Env:VIRTUAL_ENV_DISABLE_PROMPT) { | ||
|
|
||
| Write-Verbose "Setting prompt to '$Prompt'" | ||
|
|
||
| # Set the prompt to include the env name | ||
| # Make sure _OLD_VIRTUAL_PROMPT is global | ||
| function global:_OLD_VIRTUAL_PROMPT { "" } | ||
| Copy-Item -Path function:prompt -Destination function:_OLD_VIRTUAL_PROMPT | ||
| New-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Description "Python virtual environment prompt prefix" -Scope Global -Option ReadOnly -Visibility Public -Value $Prompt | ||
|
|
||
| function global:prompt { | ||
| Write-Host -NoNewline -ForegroundColor Green "($_PYTHON_VENV_PROMPT_PREFIX) " | ||
| _OLD_VIRTUAL_PROMPT | ||
| } | ||
| } | ||
|
|
||
| # Clear PYTHONHOME | ||
| if (Test-Path -Path Env:PYTHONHOME) { | ||
| Copy-Item -Path Env:PYTHONHOME -Destination Env:_OLD_VIRTUAL_PYTHONHOME | ||
| Remove-Item -Path Env:PYTHONHOME | ||
| } | ||
|
|
||
| # Add the venv to the PATH | ||
| Copy-Item -Path Env:PATH -Destination Env:_OLD_VIRTUAL_PATH | ||
| $Env:PATH = "$VenvExecDir$([System.IO.Path]::PathSeparator)$Env:PATH" |
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.
Wrapping the entire sequence past this point in a while loop would allow the CLI to perform more than one operation before exiting.