#!/bin/bash # Author: Alexander Epstein https://github.com/alexanderepstein global currentVersion := '"1.11.1'" global configuredClient := ''"" global configuredPython := ''"" source ~/.bash_profile ## allows grabbing enviornment variable global apiKey := $TASTE_API_KEY global info := '"0'" ## indicates if we want extra info global 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 proc getConfiguredClient { if command -v curl &>/dev/null ; { global configuredClient := '"curl'" } elif command -v wget &>/dev/null ; { global configuredClient := '"wget'" } elif command -v fetch &>/dev/null ; { global configuredClient := '"fetch'" } else { echo "Error: This tool reqires either curl, wget, or fetch to be installed." return 1 } } proc getConfiguredPython { if command -v python2 &>/dev/null ; { global configuredPython := '"python2'" } elif command -v python &>/dev/null ; { global configuredPython := '"python'" } else { echo "Error: This tool requires python 2 to be installed." return 1 } } proc python { matchstr $configuredPython { python2 { python2 @Argv} python { python @Argv} } } ## Allows to call the users configured client without if statements everywhere proc httpGet { matchstr $configuredClient { curl { curl -A curl -s @Argv} wget { wget -qO- @Argv} fetch { fetch -o "..."} } } proc checkInternet { echo -e "GET http://google.com HTTP/1.0\n\n" | nc google.com 80 > /dev/null !2 > !1 # query google with a get request if test $Status -eq 0 { #check if the output is 0, if so no errors have occured and we have connected to google successfully return 0 } else { echo "Error: no active internet connection" > !2 #sent to stderr return 1 } } proc update { # Author: Alexander Epstein https://github.com/alexanderepstein # Update utility version 1.2.0 # To test the tool enter in the defualt values that are in the examples for each variable global repositoryName := '"Bash-Snippets'" #Name of repostiory to be updated ex. Sandman-Lite global githubUserName := '"alexanderepstein'" #username that hosts the repostiory ex. alexanderepstein global nameOfInstallFile := '"install.sh'" # change this if the installer file has a different name be sure to include file extension if there is one global latestVersion := $[httpGet https://api.github.com/repos/$githubUserName/$repositoryName/tags | grep -Eo '"name":.*?[^\\]",'| head -1 | grep -Eo "[0-9.]+] #always grabs the tag without the v option if [[ $currentVersion == "" || $repositoryName == "" || $githubUserName == "" || $nameOfInstallFile == "" ]]{ echo "Error: update utility has not been configured correctly." > !2 exit 1 } elif [[ $latestVersion == "" ]]{ echo "Error: no active internet connection" > !2 exit 1 } else { if [[ "$latestVersion" != "$currentVersion" ]] { echo "Version $latestVersion available" echo -n "Do you wish to update $repositoryName [Y/n]: " read -r answer if [[ "$answer" == "Y" || "$answer" == "y" ]] { cd ~ || do { echo 'Update Failed' ; exit 1 ; } if [[ -d ~/$repositoryName ]] { rm -r -f $repositoryName || do { echo "Permissions Error: try running the update as sudo"; exit 1; } ; } git clone "https://github.com/$githubUserName/$repositoryName" || do { echo "Couldn't download latest version" ; exit 1; } cd $repositoryName || do { echo 'Update Failed' ; exit 1 ;} git checkout "v$latestVersion" !2 > /dev/null || git checkout $latestVersion !2 > /dev/null || echo "Couldn't git checkout to stable release, updating to latest commit." chmod a+x install.sh #this might be necessary in your case but wasnt in mine. ./$nameOfInstallFile "update" || exit 1 cd .. rm -r -f $repositoryName || do { echo "Permissions Error: update succesfull but cannot delete temp files located at ~/$repositoryName delete this directory with sudo"; exit 1; } } else { exit 1 } } else { echo "$repositoryName is already the latest version" } } } ## This function gets 3 results similar to the item of interest proc getSimilar { export PYTHONIOENCODING=utf8 #necessary for python in some cases global media := $[ echo @Argv | tr " " +] global response := $[httpGet "https://tastedive.com/api/similar?q=$media&k=$apiKey&info=$info] ## Extrapolate the information by parsing the JSON global nameOne := $[echo $response | python -c "import sys, json; print json.load(sys.stdin)['Similar']['Results'][0]['Name']" !2 > /dev/null || do { echo "Error: Did you search a valid item?] global typeOne := $[echo $response | python -c "import sys, json; print json.load(sys.stdin)['Similar']['Results'][0]['Type']" !2 > /dev/null] global nameTwo := $[echo $response | python -c "import sys, json; print json.load(sys.stdin)['Similar']['Results'][1]['Name']" !2 > /dev/null] global typeTwo := $[echo $response | python -c "import sys, json; print json.load(sys.stdin)['Similar']['Results'][1]['Type']" !2 > /dev/null] global nameThree := $[echo $response | python -c "import sys, json; print json.load(sys.stdin)['Similar']['Results'][2]['Name']" !2 > /dev/null] global typeThree := $[echo $response | python -c "import sys, json; print json.load(sys.stdin)['Similar']['Results'][2]['Type']" !2 > /dev/null] if [[ $info == "1" ]]{ ## if we want more detailed info we have to grab a few more fields global wikiOne := $[echo $response | python -c "import sys, json; print json.load(sys.stdin)['Similar']['Results'][0]['wTeaser']" !2 > /dev/null] global wikiTwo := $[echo $response | python -c "import sys, json; print json.load(sys.stdin)['Similar']['Results'][1]['wTeaser']" !2 > /dev/null] global wikiThree := $[echo $response | python -c "import sys, json; print json.load(sys.stdin)['Similar']['Results'][2]['wTeaser']" !2 > /dev/null] global youtube := $[echo $response | python -c "import sys, json; print json.load(sys.stdin)['Similar']['Results'][0]['yUrl']" !2 > /dev/null] } } ## This function grabs all the information it can on the item of interest itself proc getInfo { export PYTHONIOENCODING=utf8 #necessary for python in some cases global media := $[ echo @Argv | tr " " +] global response := $[httpGet "https://tastedive.com/api/similar?q=$media&k=$apiKey&info=$info] global name := $[echo $response | python -c "import sys, json; print json.load(sys.stdin)['Similar']['Info'][0]['Name']] global type := $[echo $response | python -c "import sys, json; print json.load(sys.stdin)['Similar']['Info'][0]['Type']] if [[ $info == "1" ]] { global wiki := $[echo $response | python -c "import sys, json; print json.load(sys.stdin)['Similar']['Info'][0]['wTeaser']] global youtube := $[echo $response | python -c "import sys, json; print json.load(sys.stdin)['Similar']['Info'][0]['yUrl']] } else { global wiki := '"None'" global youtube := '"None'" } } proc printResults { if [[ $info == "1" ]]{ echo "===================================" echo echo $nameOne: $typeOne echo $wikiOne echo echo echo $nameTwo: $typeTwo echo $wikiTwo echo echo echo $nameThree: $typeThree echo $wikiThree echo if [[ $youtube != "None" ]]{ echo $youtube;} echo echo "===================================" } else { echo "===================================" echo $nameOne: $typeOne echo $nameTwo: $typeTwo echo $nameThree: $typeThree echo "===================================" } } proc printInfo { echo "===================================" echo echo $name: $type echo $wiki echo if [[ $youtube != "None" ]]{ echo $youtube;} echo "===================================" } proc usage { echo "Taste" echo "Description: A recommendation engine that provides 3 similar items based on some input topic." echo " Taste also has the ability to provide information on the item of interest." echo " Supports: shows, books, music, artists, movies, authors, games" echo "Usage: taste [flag] [item]" echo " -i Get more information on similar items" echo " -s Get information on the item itself" echo " -u Update Bash-Snippet Tools" echo " -h Show the help" echo " -v Get the tool version" echo "Examples:" echo " taste -i Kendrick Lamar" echo " taste Catcher in the Rye" echo " taste -s Red Hot Chili Peppers" } if [[ $apiKey == "" ]]{ echo "Error: API key not setup properly" echo "To get an API key visit https://tastedive.com/account/api_access" echo 'After getting the API key run the following command: export TASTE_API_KEY="yourAPIKeyGoesHere"' echo "After following all the steps and issues still persist try adding export TASTE_API_KEY manually to your .bash_profile" exit 1 } getConfiguredPython || exit 1 getConfiguredClient || exit 1 checkInternet || exit 1 while getopts "uvhis" opt { matchstr $opt { \? { echo "Invalid option: -$OPTARG" > !2 exit 1 } h { usage exit 0 } v { echo "Version $currentVersion" exit 0 } u { update exit 0 } i { if [[ $search == "0" ]]{ global info := '"1'" } else { echo "Error: the options -i and -s are mutually exclusive (-s already uses -i)" exit 1 } } s { if [[ $info != "1" ]]{ global search := '"1'" global info := '"1'" } else { echo "Error: the options -i and -s are mutually exclusive (-s already uses -i)" exit 1 } } : { echo "Option -$OPTARG requires an argument." > !2 exit 1 } } } if [[ $# == 0 ]] { usage } elif [[ $1 == "update" ]]{ update } elif [[ $1 == "help" ]]{ usage } else { if [[ $search == "0" ]]{ if [[ $info == "0" ]]{ getSimilar @Argv || exit 1 ## exit if we return 1 (chances are movie was not found) printResults } else { getSimilar $(@:2) || exit 1 printResults } } else { getInfo $(@:2) || exit 1 ## exit if we return 1 (chances are movie was not found) printInfo } } (CommandList children: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:currentVersion) op:Equal rhs:{(DQ (1.11.1))} spids:[7])] spids: [7] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:configuredClient) op:Equal rhs:{(DQ )} spids:[12])] spids: [12] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:configuredPython) op:Equal rhs:{(DQ )} spids:[16])] spids: [16] ) (C {(source)} {(TildeSubPart prefix:"") (/.bash_profile)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:apiKey) op: Equal rhs: {($ VSub_Name "$TASTE_API_KEY")} spids: [28] ) ] spids: [28] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:info) op:Equal rhs:{(DQ (0))} spids:[31])] spids: [31] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:search) op:Equal rhs:{(DQ (0))} spids:[39])] spids: [39] ) (FuncDef name: getConfiguredClient body: (BraceGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (C {(command)} {(-v)} {(curl)}) terminator: ) (Sentence child: (SimpleCommand redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [67] ) ] ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:configuredClient) op: Equal rhs: {(DQ (curl))} spids: [75] ) ] spids: [75] ) ] spids: [-1 72] ) (if_arm cond: [ (Sentence child: (C {(command)} {(-v)} {(wget)}) terminator: ) (Sentence child: (SimpleCommand redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [90] ) ] ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:configuredClient) op: Equal rhs: {(DQ (wget))} spids: [98] ) ] spids: [98] ) ] spids: [81 95] ) (if_arm cond: [ (Sentence child: (C {(command)} {(-v)} {(fetch)}) terminator: ) (Sentence child: (SimpleCommand redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [113] ) ] ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:configuredClient) op: Equal rhs: {(DQ (fetch))} spids: [121] ) ] spids: [121] ) ] spids: [104 118] ) ] else_action: [ (C {(echo)} {(DQ ("Error: This tool reqires either curl, wget, or fetch to be installed."))} ) (ControlFlow token: arg_word:{(1)}) ] spids: [127 142] ) ] spids: [55] ) spids: [51 54] ) (FuncDef name: getConfiguredPython body: (BraceGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (C {(command)} {(-v)} {(python2)}) terminator: ) (Sentence child: (SimpleCommand redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [163] ) ] ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:configuredPython) op: Equal rhs: {(DQ (python2))} spids: [171] ) ] spids: [171] ) ] spids: [-1 168] ) (if_arm cond: [ (Sentence child: (C {(command)} {(-v)} {(python)}) terminator: ) (Sentence child: (SimpleCommand redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [186] ) ] ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:configuredPython) op: Equal rhs: {(DQ (python))} spids: [194] ) ] spids: [194] ) ] spids: [177 191] ) ] else_action: [ (C {(echo)} {(DQ ("Error: This tool requires python 2 to be installed."))}) (ControlFlow token: arg_word:{(1)}) ] spids: [200 215] ) ] spids: [151] ) spids: [147 150] ) (FuncDef name: python body: (BraceGroup children: [ (Case to_match: {(DQ ($ VSub_Name "$configuredPython"))} arms: [ (case_arm pat_list: [{(python2)}] action: [(C {(python2)} {(DQ ($ VSub_At "$@"))})] spids: [237 238 245 -1] ) (case_arm pat_list: [{(python)}] action: [(C {(python)} {(DQ ($ VSub_At "$@"))})] spids: [248 249 256 -1] ) ] spids: [228 234 259] ) ] spids: [225] ) spids: [221 224] ) (FuncDef name: httpGet body: (BraceGroup children: [ (Case to_match: {(DQ ($ VSub_Name "$configuredClient"))} arms: [ (case_arm pat_list: [{(curl)}] action: [(C {(curl)} {(-A)} {(curl)} {(-s)} {(DQ ($ VSub_At "$@"))})] spids: [283 284 297 -1] ) (case_arm pat_list: [{(wget)}] action: [(C {(wget)} {(-qO-)} {(DQ ($ VSub_At "$@"))})] spids: [300 301 310 -1] ) (case_arm pat_list: [{(fetch)}] action: [(C {(fetch)} {(-o)} {(DQ (...))})] spids: [313 314 323 -1] ) ] spids: [274 280 326] ) ] spids: [271] ) spids: [267 270] ) (FuncDef name: checkInternet body: (BraceGroup children: [ (Pipeline children: [ (C {(echo)} {(-e)} { (DQ ("GET http://google.com HTTP/1.0") (EscapedLiteralPart token:) (EscapedLiteralPart token:) ) } ) (SimpleCommand words: [{(nc)} {(google.com)} {(80)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [357] ) (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[361]) ] ) ] negated: False ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {($ VSub_QMark "$?")} {(-eq)} {(0)} {(Lit_Other "]")}) terminator: ) ] action: [(ControlFlow token: arg_word:{(0)})] spids: [-1 381] ) ] else_action: [ (SimpleCommand words: [{(echo)} {(DQ ("Error: no active internet connection"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[401])] ) (ControlFlow token: arg_word:{(1)}) ] spids: [392 413] ) ] spids: [336] ) spids: [332 335] ) (FuncDef name: update body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:repositoryName) op: Equal rhs: {(DQ (Bash-Snippets))} spids: [437] ) ] spids: [437] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:githubUserName) op: Equal rhs: {(DQ (alexanderepstein))} spids: [446] ) ] spids: [446] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:nameOfInstallFile) op: Equal rhs: {(DQ (install.sh))} spids: [455] ) ] spids: [455] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:latestVersion) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(httpGet)} {(https) (Lit_Other ":") (//api.github.com/repos/) ($ VSub_Name "$githubUserName") (/) ($ VSub_Name "$repositoryName") (/tags) } ) (C {(grep)} {(-Eo)} {(SQ <"\"name\":.*?[^\\\\]\",">)}) (C {(head)} {(-1)}) (C {(grep)} {(-Eo)} {(DQ ("[0-9.]+"))}) ] negated: False ) ] ) left_token: spids: [465 501] ) } spids: [464] ) ] spids: [464] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (LogicalOr left: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$currentVersion")} right: {(DQ )} ) right: (LogicalOr left: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$repositoryName")} right: {(DQ )} ) right: (LogicalOr left: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$githubUserName")} right: {(DQ )} ) right: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$nameOfInstallFile")} right: {(DQ )} ) ) ) ) ) terminator: ) ] action: [ (SimpleCommand words: [ {(echo)} {(DQ ("Error: update utility has not been configured correctly."))} ] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[557])] ) (C {(exit)} {(1)}) ] spids: [-1 548] ) (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$latestVersion")} right: {(DQ )} ) ) terminator: ) ] action: [ (SimpleCommand words: [{(echo)} {(DQ ("Error: no active internet connection"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[588])] ) (C {(exit)} {(1)}) ] spids: [566 579] ) ] else_action: [ (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobNEqual left: {(DQ ($ VSub_Name "$latestVersion"))} right: {(DQ ($ VSub_Name "$currentVersion"))} ) ) terminator: ) ] action: [ (C {(echo)} {(DQ ("Version ") ($ VSub_Name "$latestVersion") (" available"))}) (C {(echo)} {(-n)} { (DQ ("Do you wish to update ") ($ VSub_Name "$repositoryName") (" [Y/n]: ")) } ) (C {(read)} {(-r)} {(answer)}) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (LogicalOr left: (BoolBinary op_id: BoolBinary_GlobDEqual left: {(DQ ($ VSub_Name "$answer"))} right: {(DQ (Y))} ) right: (BoolBinary op_id: BoolBinary_GlobDEqual left: {(DQ ($ VSub_Name "$answer"))} right: {(DQ (y))} ) ) ) terminator: ) ] action: [ (AndOr children: [ (C {(cd)} {(TildeSubPart prefix:"")}) (BraceGroup children: [ (Sentence child: (C {(echo)} {(SQ <"Update Failed">)}) terminator: ) (Sentence child: (C {(exit)} {(1)}) terminator: ) ] spids: [685] ) ] op_id: Op_DPipe ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolUnary op_id: BoolUnary_d child: {(Lit_Tilde "~") (/) ($ VSub_Name "$repositoryName") } ) ) terminator: ) ] action: [ (Sentence child: (AndOr children: [ (C {(rm)} {(-r)} {(-f)} {($ VSub_Name "$repositoryName")}) (BraceGroup children: [ (Sentence child: (C {(echo)} { (DQ ( "Permissions Error: try running the update as sudo" ) ) } ) terminator: ) (Sentence child: (C {(exit)} {(1)}) terminator: ) ] spids: [729] ) ] op_id: Op_DPipe ) terminator: ) ] spids: [-1 717] ) ] spids: [-1 747] ) (AndOr children: [ (C {(git)} {(clone)} { (DQ ("https://github.com/") ($ VSub_Name "$githubUserName") (/) ($ VSub_Name "$repositoryName") ) } ) (BraceGroup children: [ (Sentence child: (C {(echo)} {(DQ ("Couldn't download latest version"))}) terminator: ) (Sentence child: (C {(exit)} {(1)}) terminator: ) ] spids: [763] ) ] op_id: Op_DPipe ) (AndOr children: [ (C {(cd)} {($ VSub_Name "$repositoryName")}) (BraceGroup children: [ (Sentence child: (C {(echo)} {(SQ <"Update Failed">)}) terminator: ) (Sentence child: (C {(exit)} {(1)}) terminator: ) ] spids: [787] ) ] op_id: Op_DPipe ) (AndOr children: [ (SimpleCommand words: [ {(git)} {(checkout)} {(DQ (v) ($ VSub_Name "$latestVersion"))} ] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [814] ) ] ) (AndOr children: [ (SimpleCommand words: [ {(git)} {(checkout)} {(DQ ($ VSub_Name "$latestVersion"))} ] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [828] ) ] ) (C {(echo)} { (DQ ( "Couldn't git checkout to stable release, updating to latest commit." ) ) } ) ] op_id: Op_DPipe ) ] op_id: Op_DPipe ) (C {(chmod)} {(a) (Lit_Other "+") (x)} {(install.sh)}) (AndOr children: [ (C {(./) ($ VSub_Name "$nameOfInstallFile")} {(DQ (update))}) (C {(exit)} {(1)}) ] op_id: Op_DPipe ) (C {(cd)} {(..)}) (AndOr children: [ (C {(rm)} {(-r)} {(-f)} {($ VSub_Name "$repositoryName")}) (BraceGroup children: [ (Sentence child: (C {(echo)} { (DQ ( "Permissions Error: update succesfull but cannot delete temp files located at ~/" ) ($ VSub_Name "$repositoryName") (" delete this directory with sudo") ) } ) terminator: ) (Sentence child: (C {(exit)} {(1)}) terminator: ) ] spids: [882] ) ] op_id: Op_DPipe ) ] spids: [-1 676] ) ] else_action: [(C {(exit)} {(1)})] spids: [901 909] ) ] spids: [-1 617] ) ] else_action: [ (C {(echo)} {(DQ ($ VSub_Name "$repositoryName") (" is already the latest version"))} ) ] spids: [912 923] ) ] spids: [597 926] ) ] spids: [422] ) spids: [418 421] ) (FuncDef name: getSimilar body: (BraceGroup children: [ (C {(export)} {(Lit_VarLike "PYTHONIOENCODING=") (utf8)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:media) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {(DQ ($ VSub_At "$@"))}) (C {(tr)} {(DQ (" "))} {(Lit_Other "+")}) ] negated: False ) ] ) left_token: spids: [952 970] ) } spids: [951] ) ] spids: [951] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:response) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (C {(httpGet)} { (DQ ("https://tastedive.com/api/similar?q=") ($ VSub_Name "$media") ("&k=") ($ VSub_Name "$apiKey") ("&info=") ($ VSub_Name "$info") ) } ) ] ) left_token: spids: [974 985] ) } spids: [973] ) ] spids: [973] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:nameOne) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (AndOr children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$response")}) (SimpleCommand words: [ {(python)} {(-c)} { (DQ ( "import sys, json; print json.load(sys.stdin)['Similar']['Results'][0]['Name']" ) ) } ] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [1008] ) ] ) ] negated: False ) (BraceGroup children: [ (Sentence child: (C {(echo)} {(DQ ("Error: Did you search a valid item?"))}) terminator: ) (Sentence child: (ControlFlow token: arg_word: {(1)} ) terminator: ) ] spids: [1014] ) ] op_id: Op_DPipe ) ] ) left_token: spids: [993 1030] ) } spids: [992] ) ] spids: [992] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:typeOne) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$response")}) (SimpleCommand words: [ {(python)} {(-c)} { (DQ ( "import sys, json; print json.load(sys.stdin)['Similar']['Results'][0]['Type']" ) ) } ] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [1049] ) ] ) ] negated: False ) ] ) left_token: spids: [1034 1052] ) } spids: [1033] ) ] spids: [1033] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:nameTwo) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$response")}) (SimpleCommand words: [ {(python)} {(-c)} { (DQ ( "import sys, json; print json.load(sys.stdin)['Similar']['Results'][1]['Name']" ) ) } ] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [1071] ) ] ) ] negated: False ) ] ) left_token: spids: [1056 1074] ) } spids: [1055] ) ] spids: [1055] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:typeTwo) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$response")}) (SimpleCommand words: [ {(python)} {(-c)} { (DQ ( "import sys, json; print json.load(sys.stdin)['Similar']['Results'][1]['Type']" ) ) } ] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [1093] ) ] ) ] negated: False ) ] ) left_token: spids: [1078 1096] ) } spids: [1077] ) ] spids: [1077] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:nameThree) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$response")}) (SimpleCommand words: [ {(python)} {(-c)} { (DQ ( "import sys, json; print json.load(sys.stdin)['Similar']['Results'][2]['Name']" ) ) } ] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [1115] ) ] ) ] negated: False ) ] ) left_token: spids: [1100 1118] ) } spids: [1099] ) ] spids: [1099] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:typeThree) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$response")}) (SimpleCommand words: [ {(python)} {(-c)} { (DQ ( "import sys, json; print json.load(sys.stdin)['Similar']['Results'][2]['Type']" ) ) } ] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [1137] ) ] ) ] negated: False ) ] ) left_token: spids: [1122 1140] ) } spids: [1121] ) ] spids: [1121] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$info")} right: {(DQ (1))} ) ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:wikiOne) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$response")}) (SimpleCommand words: [ {(python)} {(-c)} { (DQ ( "import sys, json; print json.load(sys.stdin)['Similar']['Results'][0]['wTeaser']" ) ) } ] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [1179] ) ] ) ] negated: False ) ] ) left_token: spids: [1164 1182] ) } spids: [1163] ) ] spids: [1163] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:wikiTwo) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$response")}) (SimpleCommand words: [ {(python)} {(-c)} { (DQ ( "import sys, json; print json.load(sys.stdin)['Similar']['Results'][1]['wTeaser']" ) ) } ] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [1201] ) ] ) ] negated: False ) ] ) left_token: spids: [1186 1204] ) } spids: [1185] ) ] spids: [1185] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:wikiThree) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$response")}) (SimpleCommand words: [ {(python)} {(-c)} { (DQ ( "import sys, json; print json.load(sys.stdin)['Similar']['Results'][2]['wTeaser']" ) ) } ] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [1223] ) ] ) ] negated: False ) ] ) left_token: spids: [1208 1226] ) } spids: [1207] ) ] spids: [1207] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:youtube) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$response")}) (SimpleCommand words: [ {(python)} {(-c)} { (DQ ( "import sys, json; print json.load(sys.stdin)['Similar']['Results'][0]['yUrl']" ) ) } ] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [1245] ) ] ) ] negated: False ) ] ) left_token: spids: [1230 1248] ) } spids: [1229] ) ] spids: [1229] ) ] spids: [-1 1157] ) ] spids: [-1 1251] ) ] spids: [939] ) spids: [935 938] ) (FuncDef name: getInfo body: (BraceGroup children: [ (C {(export)} {(Lit_VarLike "PYTHONIOENCODING=") (utf8)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:media) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {(DQ ($ VSub_At "$@"))}) (C {(tr)} {(DQ (" "))} {(Lit_Other "+")}) ] negated: False ) ] ) left_token: spids: [1276 1294] ) } spids: [1275] ) ] spids: [1275] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:response) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (C {(httpGet)} { (DQ ("https://tastedive.com/api/similar?q=") ($ VSub_Name "$media") ("&k=") ($ VSub_Name "$apiKey") ("&info=") ($ VSub_Name "$info") ) } ) ] ) left_token: spids: [1298 1309] ) } spids: [1297] ) ] spids: [1297] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:name) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$response")}) (C {(python)} {(-c)} { (DQ ( "import sys, json; print json.load(sys.stdin)['Similar']['Info'][0]['Name']" ) ) } ) ] negated: False ) ] ) left_token: spids: [1313 1327] ) } spids: [1312] ) ] spids: [1312] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:type) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$response")}) (C {(python)} {(-c)} { (DQ ( "import sys, json; print json.load(sys.stdin)['Similar']['Info'][0]['Type']" ) ) } ) ] negated: False ) ] ) left_token: spids: [1331 1345] ) } spids: [1330] ) ] spids: [1330] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$info")} right: {(DQ (1))} ) ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:wiki) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$response")}) (C {(python)} {(-c)} { (DQ ( "import sys, json; print json.load(sys.stdin)['Similar']['Info'][0]['wTeaser']" ) ) } ) ] negated: False ) ] ) left_token: spids: [1367 1381] ) } spids: [1366] ) ] spids: [1366] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:youtube) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$response")}) (C {(python)} {(-c)} { (DQ ( "import sys, json; print json.load(sys.stdin)['Similar']['Info'][0]['yUrl']" ) ) } ) ] negated: False ) ] ) left_token: spids: [1385 1399] ) } spids: [1384] ) ] spids: [1384] ) ] spids: [-1 1363] ) ] else_action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:wiki) op: Equal rhs: {(DQ (None))} spids: [1405] ) ] spids: [1405] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:youtube) op: Equal rhs: {(DQ (None))} spids: [1411] ) ] spids: [1411] ) ] spids: [1402 1417] ) ] spids: [1263] ) spids: [1259 1262] ) (FuncDef name: printResults body: (BraceGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$info")} right: {(DQ (1))} ) ) terminator: ) ] action: [ (C {(echo)} {(DQ ("==================================="))}) (C {(echo)}) (C {(echo)} {($ VSub_Name "$nameOne") (Lit_Other ":")} {($ VSub_Name "$typeOne")}) (C {(echo)} {($ VSub_Name "$wikiOne")}) (C {(echo)}) (C {(echo)}) (C {(echo)} {($ VSub_Name "$nameTwo") (Lit_Other ":")} {($ VSub_Name "$typeTwo")}) (C {(echo)} {($ VSub_Name "$wikiTwo")}) (C {(echo)}) (C {(echo)}) (C {(echo)} {($ VSub_Name "$nameThree") (Lit_Other ":")} {($ VSub_Name "$typeThree")} ) (C {(echo)} {($ VSub_Name "$wikiThree")}) (C {(echo)}) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobNEqual left: {($ VSub_Name "$youtube")} right: {(DQ (None))} ) ) terminator: ) ] action: [ (Sentence child: (C {(echo)} {($ VSub_Name "$youtube")}) terminator: ) ] spids: [-1 1524] ) ] spids: [-1 1530] ) (C {(echo)}) (C {(echo)} {(DQ ("==================================="))}) ] spids: [-1 1443] ) ] else_action: [ (C {(echo)} {(DQ ("==================================="))}) (C {(echo)} {($ VSub_Name "$nameOne") (Lit_Other ":")} {($ VSub_Name "$typeOne")}) (C {(echo)} {($ VSub_Name "$nameTwo") (Lit_Other ":")} {($ VSub_Name "$typeTwo")}) (C {(echo)} {($ VSub_Name "$nameThree") (Lit_Other ":")} {($ VSub_Name "$typeThree")}) (C {(echo)} {(DQ ("==================================="))}) ] spids: [1543 1584] ) ] spids: [1426] ) spids: [1422 1425] ) (FuncDef name: printInfo body: (BraceGroup children: [ (C {(echo)} {(DQ ("==================================="))}) (C {(echo)}) (C {(echo)} {($ VSub_Name "$name") (Lit_Other ":")} {($ VSub_Name "$type")}) (C {(echo)} {($ VSub_Name "$wiki")}) (C {(echo)}) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobNEqual left: {($ VSub_Name "$youtube")} right: {(DQ (None))} ) ) terminator: ) ] action: [ (Sentence child: (C {(echo)} {($ VSub_Name "$youtube")}) terminator: ) ] spids: [-1 1636] ) ] spids: [-1 1642] ) (C {(echo)} {(DQ ("==================================="))}) ] spids: [1593] ) spids: [1589 1592] ) (FuncDef name: usage body: (BraceGroup children: [ (C {(echo)} {(DQ (Taste))}) (C {(echo)} { (DQ ( "Description: A recommendation engine that provides 3 similar items based on some input topic." ) ) } ) (C {(echo)} {(DQ (" Taste also has the ability to provide information on the item of interest."))} ) (C {(echo)} {(DQ (" Supports: shows, books, music, artists, movies, authors, games"))}) (C {(echo)} {(DQ ("Usage: taste [flag] [item]"))}) (C {(echo)} {(DQ (" -i Get more information on similar items"))}) (C {(echo)} {(DQ (" -s Get information on the item itself"))}) (C {(echo)} {(DQ (" -u Update Bash-Snippet Tools"))}) (C {(echo)} {(DQ (" -h Show the help"))}) (C {(echo)} {(DQ (" -v Get the tool version"))}) (C {(echo)} {(DQ ("Examples:"))}) (C {(echo)} {(DQ (" taste -i Kendrick Lamar"))}) (C {(echo)} {(DQ (" taste Catcher in the Rye"))}) (C {(echo)} {(DQ (" taste -s Red Hot Chili Peppers"))}) ] spids: [1659] ) spids: [1655 1658] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id:BoolBinary_GlobDEqual left:{($ VSub_Name "$apiKey")} right:{(DQ )}) ) terminator: ) ] action: [ (C {(echo)} {(DQ ("Error: API key not setup properly"))}) (C {(echo)} {(DQ ("To get an API key visit https://tastedive.com/account/api_access"))}) (C {(echo)} { (SQ < "After getting the API key run the following command: export TASTE_API_KEY=\"yourAPIKeyGoesHere\"" > ) } ) (C {(echo)} { (DQ ( "After following all the steps and issues still persist try adding export TASTE_API_KEY manually to your .bash_profile" ) ) } ) (C {(exit)} {(1)}) ] spids: [-1 1775] ) ] spids: [-1 1810] ) (AndOr children:[(C {(getConfiguredPython)})(C {(exit)} {(1)})] op_id:Op_DPipe) (AndOr children:[(C {(getConfiguredClient)})(C {(exit)} {(1)})] op_id:Op_DPipe) (AndOr children:[(C {(checkInternet)})(C {(exit)} {(1)})] op_id:Op_DPipe) (While cond: [(Sentence child:(C {(getopts)} {(DQ (uvhis))} {(opt)}) terminator:)] body: (DoGroup children: [ (Case to_match: {($ VSub_Name "$opt")} arms: [ (case_arm pat_list: [{(EscapedLiteralPart token:)}] action: [ (SimpleCommand words: [{(echo)} {(DQ ("Invalid option: -") ($ VSub_Name "$OPTARG"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[1870])] ) (C {(exit)} {(1)}) ] spids: [1859 1860 1879 -1] ) (case_arm pat_list: [{(h)}] action: [(C {(usage)}) (C {(exit)} {(0)})] spids: [1882 1883 1894 -1] ) (case_arm pat_list: [{(v)}] action: [ (C {(echo)} {(DQ ("Version ") ($ VSub_Name "$currentVersion"))}) (C {(exit)} {(0)}) ] spids: [1897 1898 1914 -1] ) (case_arm pat_list: [{(u)}] action: [(C {(update)}) (C {(exit)} {(0)})] spids: [1917 1918 1929 -1] ) (case_arm pat_list: [{(i)}] action: [ (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$search")} right: {(DQ (0))} ) ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:info) op: Equal rhs: {(DQ (1))} spids: [1953] ) ] spids: [1953] ) ] spids: [-1 1950] ) ] else_action: [ (C {(echo)} { (DQ ( "Error: the options -i and -s are mutually exclusive (-s already uses -i)" ) ) } ) (C {(exit)} {(1)}) ] spids: [1959 1974] ) ] spids: [1932 1933 1977 -1] ) (case_arm pat_list: [{(s)}] action: [ (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobNEqual left: {($ VSub_Name "$info")} right: {(DQ (1))} ) ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:search) op: Equal rhs: {(DQ (1))} spids: [2001] ) ] spids: [2001] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:info) op: Equal rhs: {(DQ (1))} spids: [2007] ) ] spids: [2007] ) ] spids: [-1 1998] ) ] else_action: [ (C {(echo)} { (DQ ( "Error: the options -i and -s are mutually exclusive (-s already uses -i)" ) ) } ) (C {(exit)} {(1)}) ] spids: [2013 2028] ) ] spids: [1980 1981 2031 -1] ) (case_arm pat_list: [{(Lit_Other ":")}] action: [ (SimpleCommand words: [ {(echo)} {(DQ ("Option -") ($ VSub_Name "$OPTARG") (" requires an argument."))} ] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[2046])] ) (C {(exit)} {(1)}) ] spids: [2034 2035 2055 -1] ) ] spids: [1852 1856 2058] ) ] spids: [1849 2060] ) ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id:BoolBinary_GlobDEqual left:{($ VSub_Pound "$#")} right:{(0)}) ) terminator: ) ] action: [(C {(usage)})] spids: [-1 2076] ) (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Number "$1")} right: {(DQ (update))} ) ) terminator: ) ] action: [(C {(update)})] spids: [2081 2095] ) (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Number "$1")} right: {(DQ (help))} ) ) terminator: ) ] action: [(C {(usage)})] spids: [2100 2114] ) ] else_action: [ (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$search")} right: {(DQ (0))} ) ) terminator: ) ] action: [ (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$info")} right: {(DQ (0))} ) ) terminator: ) ] action: [ (AndOr children: [(C {(getSimilar)} {(DQ ($ VSub_At "$@"))}) (C {(exit)} {(1)})] op_id: Op_DPipe ) (C {(printResults)}) ] spids: [-1 2153] ) ] else_action: [ (AndOr children: [ (C {(getSimilar)} { (DQ (BracedVarSub token: suffix_op: (Slice begin:(ArithWord w:{(Lit_Digits 2)})) spids: [2181 2185] ) ) } ) (C {(exit)} {(1)}) ] op_id: Op_DPipe ) (C {(printResults)}) ] spids: [2175 2198] ) ] spids: [-1 2136] ) ] else_action: [ (AndOr children: [ (C {(getInfo)} { (DQ (BracedVarSub token: suffix_op: (Slice begin:(ArithWord w:{(Lit_Digits 2)})) spids: [2207 2211] ) ) } ) (C {(exit)} {(1)}) ] op_id: Op_DPipe ) (C {(printInfo)}) ] spids: [2201 2227] ) ] spids: [2119 2229] ) ] )