Skip to content

Commit

Permalink
Adding some comments to taste
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Epstein committed Jun 30, 2017
1 parent ccb751e commit ce876cb
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions taste/taste
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

currentVersion="1.4.0"
configuredClient=""
source ~/.bashrc
source ~/.bashrc ## allows grabbing enviornment variable
apiKey=$TASTE_API_KEY
info="0"
search="0"
info="0" ## indicates if we want extra info
search="0" ## indivates that we want results on the item itself

## This function determines which http get tool the system has installed and returns an error if there isnt one
getConfiguredClient()
Expand Down Expand Up @@ -87,25 +87,28 @@ update()

}

## This function gets 3 results similar to the item of interest
getSimilar()
{
export PYTHONIOENCODING=utf8 #necessary for python 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)
if [[ $info == "1" ]];then
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)
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
Expand Down

0 comments on commit ce876cb

Please sign in to comment.