From 581a6b4ea681005e3f8add37dbed74aaec65479f Mon Sep 17 00:00:00 2001 From: essam <112789498+e55am@users.noreply.github.com> Date: Sat, 4 May 2024 18:12:41 +0000 Subject: [PATCH] Fix: correct typo prevent script from stop if response was False (#243) If the response was false, inform the user what happened example(movie not found or invalid API key) --- movies/movies | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/movies/movies b/movies/movies index 609cb59..be55fbf 100755 --- a/movies/movies +++ b/movies/movies @@ -86,8 +86,14 @@ getMovieInfo() movie=$( (echo "$@" | tr " " + ) | sed 's/-d+//g' ) ## format the inputs to use for the api. Added sed command to filter -d flag. export PYTHONIOENCODING=utf8 #necessary for python in some cases movieInfo=$(httpGet "http://www.omdbapi.com/?t=$movie&apikey=$apiKey") > /dev/null # query the server and get the JSON response - checkResponse=$(echo "$movieInfo" | python -c "import sys, json; print json.load(sys.stdin)['Response']" 2> /dev/null) - if [[ $checkResponse == "False" ]]; then { echo "No movie found" ; return 1 ;} fi ## check to see if the movie was found + + ## check to see if the movie was found + checkResponse=$(echo "$movieInfo" | python -c "from __future__ import print_function; import sys, json; print(json.load(sys.stdin)['Response'])" 2> /dev/null) + if [[ $checkResponse == "False" ]]; then + echo "$movieInfo" | python -c "from __future__ import print_function; import sys, json; print(json.load(sys.stdin)['Error'])" 2> /dev/null + return 1 + fi + # The rest of the code is just extrapolating the data with python from the JSON response title="$(AccessJsonElement "$movieInfo" "Title")" year="$(AccessJsonElement "$movieInfo" "Year")"