From 44ce35f4be24ac30ab93427e74a867bf7d36d698 Mon Sep 17 00:00:00 2001 From: Alex Epstein Date: Mon, 3 Jul 2017 09:26:31 -0400 Subject: [PATCH] Explicity asking for python2 in all python calls --- movies/movies | 24 ++++++++++++------------ short/short | 4 ++-- stocks/stocks | 30 +++++++++++++++--------------- taste/taste | 32 ++++++++++++++++---------------- 4 files changed, 45 insertions(+), 45 deletions(-) diff --git a/movies/movies b/movies/movies index a6a0a22..675b193 100755 --- a/movies/movies +++ b/movies/movies @@ -42,25 +42,25 @@ checkInternet() fi } -## This function grabs information about a movie and using python parses the +## This function grabs information about a movie and using python2 parses the ## JSON response to extrapolate the information for storage getMovieInfo() { apiKey=946f500a # try not to abuse this it is a key that came from the ruby-scripts repo I link to. movie=$(echo $1 $2 $3 $4 $5 $6 $7 $8 $9 | tr " " + ) ## format the inputs to use for the api - export PYTHONIOENCODING=utf8 #necessary for python 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 - checkResponse=$(echo $movieInfo | python -c "import sys, json; print json.load(sys.stdin)['Response']") + checkResponse=$(echo $movieInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Response']") 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 python from the JSON response - title=$(echo $movieInfo | python -c "import sys, json; print json.load(sys.stdin)['Title']") - year=$(echo $movieInfo | python -c "import sys, json; print json.load(sys.stdin)['Year']") - score=$(echo $movieInfo | python -c "import sys, json; print json.load(sys.stdin)['Ratings'][1]['Value']") - rated=$(echo $movieInfo | python -c "import sys, json; print json.load(sys.stdin)['Rated']") - genre=$(echo $movieInfo | python -c "import sys, json; print json.load(sys.stdin)['Genre']") - director=$(echo $movieInfo | python -c "import sys, json; print json.load(sys.stdin)['Director']") - actors=$(echo $movieInfo | python -c "import sys, json; print json.load(sys.stdin)['Actors']") - plot=$(echo $movieInfo | python -c "import sys, json; print json.load(sys.stdin)['Plot']") + # 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']") + year=$(echo $movieInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Year']") + score=$(echo $movieInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Ratings'][1]['Value']") + rated=$(echo $movieInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Rated']") + genre=$(echo $movieInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Genre']") + director=$(echo $movieInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Director']") + actors=$(echo $movieInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Actors']") + plot=$(echo $movieInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Plot']") unset movieInfo # don't need this anymore unset checkResponse # don't need this anymore } diff --git a/short/short b/short/short index c37c92c..073ab8c 100755 --- a/short/short +++ b/short/short @@ -104,12 +104,12 @@ expandURL() url=$1 fi response=$(httpGet http://x.datasig.io/short?url=$url) - errorCheck=$(echo $response | python -c "import sys, json; print json.load(sys.stdin)['/short']['message']" 2> /dev/null ) + errorCheck=$(echo $response | python2 -c "import sys, json; print json.load(sys.stdin)['/short']['message']" 2> /dev/null ) if [[ $errorCheck == "Error in /short" ]];then echo "Error: 404 could not find the website" return 1 fi - expandedURL=$(echo $response | python -c "import sys, json; print json.load(sys.stdin)['/short']['destination']" 2> /dev/null ) + expandedURL=$(echo $response | python2 -c "import sys, json; print json.load(sys.stdin)['/short']['destination']" 2> /dev/null ) } diff --git a/stocks/stocks b/stocks/stocks index a5642ef..84e96d1 100755 --- a/stocks/stocks +++ b/stocks/stocks @@ -41,24 +41,24 @@ checkInternet() fi } -## This function grabs information about a stock and using python parses the +## This function grabs information about a stock and using python2 parses the ## JSON response to extrapolate the information for storage getStockInformation() { stockInfo=$(httpGet "https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=$1&apikey=KPCCCRJVMOGN9L6T") > /dev/null #grab the JSON response - export PYTHONIOENCODING=utf8 #necessary for python in some cases - echo $stockInfo | python -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['02. Exchange Name']" > /dev/null 2>&1 || { echo "Not a valid stock symbol" ; exit 1; } #checking if we get any information back from the server if not chances are it isnt a valid stock symbol - # The rest of the code is just extrapolating the data with python from the JSON response - exchangeName=$(echo $stockInfo | python -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['02. Exchange Name']") - latestPrice=$(echo $stockInfo | python -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['03. Latest Price']") - open=$(echo $stockInfo | python -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['04. Open (Current Trading Day)']") - high=$(echo $stockInfo | python -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['05. High (Current Trading Day)']") - low=$(echo $stockInfo | python -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['06. Low (Current Trading Day)']") - close=$(echo $stockInfo | python -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['07. Close (Previous Trading Day)']") - priceChange=$(echo $stockInfo | python -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['08. Price Change']") - priceChangePercentage=$(echo $stockInfo | python -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['09. Price Change Percentage']") - volume=$(echo $stockInfo | python -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['10. Volume (Current Trading Day)']") - lastUpdated=$(echo $stockInfo | python -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['11. Last Updated']") + export PYTHONIOENCODING=utf8 #necessary for python2 in some cases + echo $stockInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['02. Exchange Name']" > /dev/null 2>&1 || { echo "Not a valid stock symbol" ; exit 1; } #checking if we get any information back from the server if not chances are it isnt a valid stock symbol + # The rest of the code is just extrapolating the data with python2 from the JSON response + exchangeName=$(echo $stockInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['02. Exchange Name']") + latestPrice=$(echo $stockInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['03. Latest Price']") + open=$(echo $stockInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['04. Open (Current Trading Day)']") + high=$(echo $stockInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['05. High (Current Trading Day)']") + low=$(echo $stockInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['06. Low (Current Trading Day)']") + close=$(echo $stockInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['07. Close (Previous Trading Day)']") + priceChange=$(echo $stockInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['08. Price Change']") + priceChangePercentage=$(echo $stockInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['09. Price Change Percentage']") + volume=$(echo $stockInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['10. Volume (Current Trading Day)']") + lastUpdated=$(echo $stockInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['11. Last Updated']") unset stockInfo # done with the JSON response not needed anymore } @@ -89,7 +89,7 @@ printStockInformation() getTicker() { response=$(httpGet "http://d.yimg.com/autoc.finance.yahoo.com/autoc?query=$1+$2+$3+$4+$5+$6+$7+$8+$9®ion=1&lang=en%22") > /dev/null - symbol=$(echo $response | python -c "import sys, json; print json.load(sys.stdin)['ResultSet']['Result'][0]['symbol']") # using python to extrapolate the stock symbol + symbol=$(echo $response | python2 -c "import sys, json; print json.load(sys.stdin)['ResultSet']['Result'][0]['symbol']") # using python2 to extrapolate the stock symbol unset response #just unsets the entire response after using it since all I need is the stock ticker } diff --git a/taste/taste b/taste/taste index 5aec5f1..9ecab17 100755 --- a/taste/taste +++ b/taste/taste @@ -90,35 +90,35 @@ update() ## This function gets 3 results similar to the item of interest getSimilar() { - export PYTHONIOENCODING=utf8 #necessary for python in some cases + export PYTHONIOENCODING=utf8 #necessary for python2 in some cases media=$( echo "$1 $2 $3 $4 $5 $6 $7 $8" | tr " " + ) response=$(httpGet "https://tastedive.com/api/similar?q=$media&k=$apiKey&info=$info") ## Extrapolate the information by parsing the JSON - nameOne=$(echo $response | python -c "import sys, json; print json.load(sys.stdin)['Similar']['Results'][0]['Name']" 2> /dev/null || { echo "Error: Did you search a valid item?"; return 1; } ) - typeOne=$(echo $response | python -c "import sys, json; print json.load(sys.stdin)['Similar']['Results'][0]['Type']" 2> /dev/null) - nameTwo=$(echo $response | python -c "import sys, json; print json.load(sys.stdin)['Similar']['Results'][1]['Name']" 2> /dev/null) - typeTwo=$(echo $response | python -c "import sys, json; print json.load(sys.stdin)['Similar']['Results'][1]['Type']" 2> /dev/null) - nameThree=$(echo $response | python -c "import sys, json; print json.load(sys.stdin)['Similar']['Results'][2]['Name']" 2> /dev/null) - typeThree=$(echo $response | python -c "import sys, json; print json.load(sys.stdin)['Similar']['Results'][2]['Type']" 2> /dev/null) + nameOne=$(echo $response | python2 -c "import sys, json; print json.load(sys.stdin)['Similar']['Results'][0]['Name']" 2> /dev/null || { echo "Error: Did you search a valid item?"; return 1; } ) + typeOne=$(echo $response | python2 -c "import sys, json; print json.load(sys.stdin)['Similar']['Results'][0]['Type']" 2> /dev/null) + nameTwo=$(echo $response | python2 -c "import sys, json; print json.load(sys.stdin)['Similar']['Results'][1]['Name']" 2> /dev/null) + typeTwo=$(echo $response | python2 -c "import sys, json; print json.load(sys.stdin)['Similar']['Results'][1]['Type']" 2> /dev/null) + nameThree=$(echo $response | python2 -c "import sys, json; print json.load(sys.stdin)['Similar']['Results'][2]['Name']" 2> /dev/null) + typeThree=$(echo $response | python2 -c "import sys, json; print json.load(sys.stdin)['Similar']['Results'][2]['Type']" 2> /dev/null) if [[ $info == "1" ]];then ## if we want more detailed info we have to grab a few more fields - wikiOne=$(echo $response | python -c "import sys, json; print json.load(sys.stdin)['Similar']['Results'][0]['wTeaser']" 2> /dev/null) - wikiTwo=$(echo $response | python -c "import sys, json; print json.load(sys.stdin)['Similar']['Results'][1]['wTeaser']" 2> /dev/null) - wikiThree=$(echo $response | python -c "import sys, json; print json.load(sys.stdin)['Similar']['Results'][2]['wTeaser']" 2> /dev/null) - youtube=$(echo $response | python -c "import sys, json; print json.load(sys.stdin)['Similar']['Results'][0]['yUrl']" 2> /dev/null) + wikiOne=$(echo $response | python2 -c "import sys, json; print json.load(sys.stdin)['Similar']['Results'][0]['wTeaser']" 2> /dev/null) + wikiTwo=$(echo $response | python2 -c "import sys, json; print json.load(sys.stdin)['Similar']['Results'][1]['wTeaser']" 2> /dev/null) + wikiThree=$(echo $response | python2 -c "import sys, json; print json.load(sys.stdin)['Similar']['Results'][2]['wTeaser']" 2> /dev/null) + youtube=$(echo $response | python2 -c "import sys, json; print json.load(sys.stdin)['Similar']['Results'][0]['yUrl']" 2> /dev/null) fi } ## This function grabs all the information it can on the item of interest itself getInfo() { - export PYTHONIOENCODING=utf8 #necessary for python in some cases + export PYTHONIOENCODING=utf8 #necessary for python2 in some cases media=$( echo "$1 $2 $3 $4 $5 $6 $7 $8" | tr " " + ) response=$(httpGet "https://tastedive.com/api/similar?q=$media&k=$apiKey&info=$info") - name=$(echo $response | python -c "import sys, json; print json.load(sys.stdin)['Similar']['Info'][0]['Name']") - type=$(echo $response | python -c "import sys, json; print json.load(sys.stdin)['Similar']['Info'][0]['Type']") + name=$(echo $response | python2 -c "import sys, json; print json.load(sys.stdin)['Similar']['Info'][0]['Name']") + type=$(echo $response | python2 -c "import sys, json; print json.load(sys.stdin)['Similar']['Info'][0]['Type']") if [[ $info == "1" ]]; then - wiki=$(echo $response | python -c "import sys, json; print json.load(sys.stdin)['Similar']['Info'][0]['wTeaser']") - youtube=$(echo $response | python -c "import sys, json; print json.load(sys.stdin)['Similar']['Info'][0]['yUrl']") + wiki=$(echo $response | python2 -c "import sys, json; print json.load(sys.stdin)['Similar']['Info'][0]['wTeaser']") + youtube=$(echo $response | python2 -c "import sys, json; print json.load(sys.stdin)['Similar']['Info'][0]['yUrl']") else wiki="None" youtube="None"