Preventing all erros in python calls in movies
This commit is contained in:
parent
2d9037c1a2
commit
69466559dc
|
@ -50,17 +50,17 @@ getMovieInfo()
|
||||||
movie=$(echo "$@" | tr " " + ) ## format the inputs to use for the api
|
movie=$(echo "$@" | tr " " + ) ## format the inputs to use for the api
|
||||||
export PYTHONIOENCODING=utf8 #necessary for python2 in some cases
|
export PYTHONIOENCODING=utf8 #necessary for python2 in some cases
|
||||||
movieInfo=$(httpGet "http://www.omdbapi.com/?t=$movie&apikey=$apiKey") > /dev/null # query the server and get the JSON response
|
movieInfo=$(httpGet "http://www.omdbapi.com/?t=$movie&apikey=$apiKey") > /dev/null # query the server and get the JSON response
|
||||||
checkResponse=$(echo $movieInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Response']")
|
checkResponse=$(echo $movieInfo | python2 -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
|
if [[ $checkResponse == "False" ]];then { echo "No movie found" ; return 1 ;} fi ## check to see if the movie was found
|
||||||
# The rest of the code is just extrapolating the data with python2 from the JSON response
|
# The rest of the code is just extrapolating the data with python2 from the JSON response
|
||||||
title=$(echo $movieInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Title']")
|
title=$(echo $movieInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Title']" 2> /dev/null)
|
||||||
year=$(echo $movieInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Year']")
|
year=$(echo $movieInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Year']" 2> /dev/null)
|
||||||
score=$(echo $movieInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Ratings'][1]['Value']")
|
score=$(echo $movieInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Ratings'][1]['Value']" 2> /dev/null)
|
||||||
rated=$(echo $movieInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Rated']")
|
rated=$(echo $movieInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Rated']" 2> /dev/null)
|
||||||
genre=$(echo $movieInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Genre']")
|
genre=$(echo $movieInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Genre']" 2> /dev/null)
|
||||||
director=$(echo $movieInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Director']")
|
director=$(echo $movieInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Director']" 2> /dev/null)
|
||||||
actors=$(echo $movieInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Actors']")
|
actors=$(echo $movieInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Actors']" 2> /dev/null)
|
||||||
plot=$(echo $movieInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Plot']")
|
plot=$(echo $movieInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Plot']" 2> /dev/null)
|
||||||
unset movieInfo # don't need this anymore
|
unset movieInfo # don't need this anymore
|
||||||
unset checkResponse # don't need this anymore
|
unset checkResponse # don't need this anymore
|
||||||
}
|
}
|
||||||
|
@ -72,12 +72,12 @@ printMovieInfo()
|
||||||
echo '=================================================='
|
echo '=================================================='
|
||||||
echo "| Title: $title"
|
echo "| Title: $title"
|
||||||
echo "| Year: $year"
|
echo "| Year: $year"
|
||||||
echo "| Tomato: $score"
|
if [[ $score != "" ]];then echo "| Tomato: $score";fi
|
||||||
echo "| Rated: $rated"
|
if [[ $rated != "N/A" && $rated != "" ]];then echo "| Rated: $rated";fi
|
||||||
echo "| Genre: $genre"
|
echo "| Genre: $genre"
|
||||||
echo "| Director: $director"
|
echo "| Director: $director"
|
||||||
echo "| Actors: $actors"
|
echo "| Actors: $actors"
|
||||||
echo "| Plot: $plot"
|
if [[ $plot != "N/A" && $plot != "" ]];then echo "| Plot: $plot"; fi
|
||||||
echo '=================================================='
|
echo '=================================================='
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue