#!/bin/bash # Author: Alexander Epstein https://github.com/alexanderepstein global currentVersion := '"1.11.1'" global configuredClient := ''"" global configuredPython := ''"" ## 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 } } ## This function grabs information about a stock and using python parses the ## JSON response to extrapolate the information for storage proc getStockInformation { global 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 || do { 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 global exchangeName := $[echo $stockInfo | python -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['02. Exchange Name']] global latestPrice := $[echo $stockInfo | python -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['03. Latest Price']] global open := $[echo $stockInfo | python -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['04. Open (Current Trading Day)']] global high := $[echo $stockInfo | python -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['05. High (Current Trading Day)']] global low := $[echo $stockInfo | python -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['06. Low (Current Trading Day)']] global close := $[echo $stockInfo | python -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['07. Close (Previous Trading Day)']] global priceChange := $[echo $stockInfo | python -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['08. Price Change']] global priceChangePercentage := $[echo $stockInfo | python -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['09. Price Change Percentage']] global volume := $[echo $stockInfo | python -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['10. Volume (Current Trading Day)']] global lastUpdated := $[echo $stockInfo | python -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 } ## This function uses all the variables that are set by getStockInformation and ## prints them out to the user in a human readable format proc printStockInformation { echo echo $symbol stock info echo "=============================================" echo "| Exchange Name: $exchangeName" echo "| Latest Price: $latestPrice" if [[ $open != "--" ]]{ echo "| Open (Current Trading Day): $open"; } ## sometime this is blank only print if value is present if [[ $high != "--" ]]{ echo "| High (Current Trading Day): $high"; } ## sometime this is blank only print if value is present if [[ $low != "--" ]]{ echo "| Low (Current Trading Day): $low"; } ## sometime this is blank only print if value is present echo "| Close (Previous Trading Day): $close" echo "| Price Change: $priceChange" if [[ $priceChangePercentage != "%" ]]{ echo "| Price Change Percentage: $priceChangePercentage"; } ## sometime this is blank only print if value is present if [[ $volume != "--" ]]{ echo "| Volume (Current Trading Day): $volume"; } ## sometime this is blank only print if value is present echo "| Last Updated: $lastUpdated" echo "=============================================" echo } ## This function queries google to determine the stock ticker for a certain company ## this allows the usage of stocks to be extended where now you can enter stocks appple ## and it will determine the stock symbol for apple is AAPL and move on from there proc getTicker { global 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 global symbol := $[echo $response | python -c "import sys, json; print json.load(sys.stdin)['ResultSet']['Result'][0]['symbol']] # using python to extrapolate the stock symbol unset response #just unsets the entire response after using it since all I need is the stock ticker } 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" } } } proc usage { echo "Stocks" echo "Description: Finds the latest information on a certain stock." echo "Usage: stocks [flag] or stocks [company/ticker]" echo " -u Update Bash-Snippet Tools" echo " -h Show the help" echo " -v Get the tool version" echo "Examples:" echo " stocks AAPL" echo " stocks Tesla" } getConfiguredPython || exit 1 getConfiguredClient || exit 1 checkInternet || exit 1 # check if we have a valid internet connection if this isnt true the rest of the script will not work so stop here while getopts "uvh" opt { matchstr $opt { \? { echo "Invalid option: -$OPTARG" > !2 exit 1 } h { usage exit 0 } v { echo "Version $currentVersion" exit 0 } u { update exit 0 } : { echo "Option -$OPTARG requires an argument." > !2 exit 1 } } } if [[ $1 == "update" ]]{ update exit 0 } elif [[ $1 == "help" ]]{ usage exit 0 } elif [[ $# == "0" ]]{ usage exit 0 } else { getTicker @Argv # the company name might have spaces so passing in all args allows for this getStockInformation $symbol # based on the stock symbol exrapolated by the getTicker function get information on the stock printStockInformation # print this information out to the user in a human readable format exit 0 } (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] ) (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: [40] ) ] ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:configuredClient) op: Equal rhs: {(DQ (curl))} spids: [48] ) ] spids: [48] ) ] spids: [-1 45] ) (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: [63] ) ] ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:configuredClient) op: Equal rhs: {(DQ (wget))} spids: [71] ) ] spids: [71] ) ] spids: [54 68] ) (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: [86] ) ] ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:configuredClient) op: Equal rhs: {(DQ (fetch))} spids: [94] ) ] spids: [94] ) ] spids: [77 91] ) ] else_action: [ (C {(echo)} {(DQ ("Error: This tool reqires either curl, wget, or fetch to be installed."))} ) (ControlFlow token: arg_word:{(1)}) ] spids: [100 115] ) ] spids: [28] ) spids: [24 27] ) (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: [137] ) ] ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:configuredPython) op: Equal rhs: {(DQ (python2))} spids: [145] ) ] spids: [145] ) ] spids: [-1 142] ) (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: [160] ) ] ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:configuredPython) op: Equal rhs: {(DQ (python))} spids: [168] ) ] spids: [168] ) ] spids: [151 165] ) ] else_action: [ (C {(echo)} {(DQ ("Error: This tool requires python 2 to be installed."))}) (ControlFlow token: arg_word:{(1)}) ] spids: [174 189] ) ] spids: [125] ) spids: [121 124] ) (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: [211 212 219 -1] ) (case_arm pat_list: [{(python)}] action: [(C {(python)} {(DQ ($ VSub_At "$@"))})] spids: [222 223 230 -1] ) ] spids: [202 208 233] ) ] spids: [199] ) spids: [195 198] ) (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: [257 258 271 -1] ) (case_arm pat_list: [{(wget)}] action: [(C {(wget)} {(-qO-)} {(DQ ($ VSub_At "$@"))})] spids: [274 275 284 -1] ) (case_arm pat_list: [{(fetch)}] action: [(C {(fetch)} {(-o)} {(DQ (...))})] spids: [287 288 297 -1] ) ] spids: [248 254 300] ) ] spids: [245] ) spids: [241 244] ) (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: [330] ) (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[334]) ] ) ] 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 354] ) ] else_action: [ (SimpleCommand words: [{(echo)} {(DQ ("Error: no active internet connection"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[374])] ) (ControlFlow token: arg_word:{(1)}) ] spids: [365 386] ) ] spids: [309] ) spids: [305 308] ) (FuncDef name: getStockInformation body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:stockInfo) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (C {(httpGet)} { (DQ ( "https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=" ) ($ VSub_Number "$1") ("&apikey=KPCCCRJVMOGN9L6T") ) } ) ] ) left_token: spids: [405 413] ) } spids: [404] ) ] spids: [404] ) (C {(export)} {(Lit_VarLike "PYTHONIOENCODING=") (utf8)}) (AndOr children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$stockInfo")}) (SimpleCommand words: [ {(python)} {(-c)} { (DQ ( "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['02. Exchange Name']" ) ) } ] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [446] ) (Redir op_id: Redir_GreatAnd fd: 2 arg_word: {(1)} spids: [450] ) ] ) ] negated: False ) (BraceGroup children: [ (Sentence child: (C {(echo)} {(DQ ("Not a valid stock symbol"))}) terminator: ) (Sentence child:(C {(exit)} {(1)}) terminator:) ] spids: [455] ) ] op_id: Op_DPipe ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:exchangeName) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$stockInfo")}) (C {(python)} {(-c)} { (DQ ( "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['02. Exchange Name']" ) ) } ) ] negated: False ) ] ) left_token: spids: [481 495] ) } spids: [480] ) ] spids: [480] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:latestPrice) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$stockInfo")}) (C {(python)} {(-c)} { (DQ ( "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['03. Latest Price']" ) ) } ) ] negated: False ) ] ) left_token: spids: [499 513] ) } spids: [498] ) ] spids: [498] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:open) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$stockInfo")}) (C {(python)} {(-c)} { (DQ ( "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['04. Open (Current Trading Day)']" ) ) } ) ] negated: False ) ] ) left_token: spids: [517 531] ) } spids: [516] ) ] spids: [516] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:high) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$stockInfo")}) (C {(python)} {(-c)} { (DQ ( "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['05. High (Current Trading Day)']" ) ) } ) ] negated: False ) ] ) left_token: spids: [535 549] ) } spids: [534] ) ] spids: [534] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:low) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$stockInfo")}) (C {(python)} {(-c)} { (DQ ( "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['06. Low (Current Trading Day)']" ) ) } ) ] negated: False ) ] ) left_token: spids: [553 567] ) } spids: [552] ) ] spids: [552] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:close) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$stockInfo")}) (C {(python)} {(-c)} { (DQ ( "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['07. Close (Previous Trading Day)']" ) ) } ) ] negated: False ) ] ) left_token: spids: [571 585] ) } spids: [570] ) ] spids: [570] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:priceChange) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$stockInfo")}) (C {(python)} {(-c)} { (DQ ( "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['08. Price Change']" ) ) } ) ] negated: False ) ] ) left_token: spids: [589 603] ) } spids: [588] ) ] spids: [588] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:priceChangePercentage) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$stockInfo")}) (C {(python)} {(-c)} { (DQ ( "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['09. Price Change Percentage']" ) ) } ) ] negated: False ) ] ) left_token: spids: [607 621] ) } spids: [606] ) ] spids: [606] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:volume) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$stockInfo")}) (C {(python)} {(-c)} { (DQ ( "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['10. Volume (Current Trading Day)']" ) ) } ) ] negated: False ) ] ) left_token: spids: [625 639] ) } spids: [624] ) ] spids: [624] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:lastUpdated) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$stockInfo")}) (C {(python)} {(-c)} { (DQ ( "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['11. Last Updated']" ) ) } ) ] negated: False ) ] ) left_token: spids: [643 657] ) } spids: [642] ) ] spids: [642] ) (C {(unset)} {(stockInfo)}) ] spids: [401] ) spids: [397 400] ) (FuncDef name: printStockInformation body: (BraceGroup children: [ (C {(echo)}) (C {(echo)} {($ VSub_Name "$symbol")} {(stock)} {(info)}) (C {(echo)} {(DQ ("============================================="))}) (C {(echo)} {(DQ ("| Exchange Name: ") ($ VSub_Name "$exchangeName"))}) (C {(echo)} {(DQ ("| Latest Price: ") ($ VSub_Name "$latestPrice"))}) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobNEqual left: {($ VSub_Name "$open")} right: {(DQ (--))} ) ) terminator: ) ] action: [ (Sentence child: (C {(echo)} {(DQ ("| Open (Current Trading Day): ") ($ VSub_Name "$open"))}) terminator: ) ] spids: [-1 732] ) ] spids: [-1 742] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobNEqual left: {($ VSub_Name "$high")} right: {(DQ (--))} ) ) terminator: ) ] action: [ (Sentence child: (C {(echo)} {(DQ ("| High (Current Trading Day): ") ($ VSub_Name "$high"))}) terminator: ) ] spids: [-1 762] ) ] spids: [-1 772] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobNEqual left: {($ VSub_Name "$low")} right: {(DQ (--))} ) ) terminator: ) ] action: [ (Sentence child: (C {(echo)} {(DQ ("| Low (Current Trading Day): ") ($ VSub_Name "$low"))}) terminator: ) ] spids: [-1 792] ) ] spids: [-1 802] ) (C {(echo)} {(DQ ("| Close (Previous Trading Day): ") ($ VSub_Name "$close"))}) (C {(echo)} {(DQ ("| Price Change: ") ($ VSub_Name "$priceChange"))}) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobNEqual left: {($ VSub_Name "$priceChangePercentage")} right: {(DQ ("%"))} ) ) terminator: ) ] action: [ (Sentence child: (C {(echo)} { (DQ ("| Price Change Percentage: ") ($ VSub_Name "$priceChangePercentage")) } ) terminator: ) ] spids: [-1 838] ) ] spids: [-1 848] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobNEqual left: {($ VSub_Name "$volume")} right: {(DQ (--))} ) ) terminator: ) ] action: [ (Sentence child: (C {(echo)} {(DQ ("| Volume (Current Trading Day): ") ($ VSub_Name "$volume"))}) terminator: ) ] spids: [-1 868] ) ] spids: [-1 878] ) (C {(echo)} {(DQ ("| Last Updated: ") ($ VSub_Name "$lastUpdated"))}) (C {(echo)} {(DQ ("============================================="))}) (C {(echo)}) ] spids: [680] ) spids: [676 679] ) (FuncDef name: getTicker body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:response) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (C {(httpGet)} { (DQ ("http://d.yimg.com/autoc.finance.yahoo.com/autoc?query=") ($ VSub_Number "$1") ("+") ($ VSub_Number "$2") ("+") ($ VSub_Number "$3") ("+") ($ VSub_Number "$4") ("+") ($ VSub_Number "$5") ("+") ($ VSub_Number "$6") ("+") ($ VSub_Number "$7") ("+") ($ VSub_Number "$8") ("+") ($ VSub_Number "$9") ("®ion=1&lang=en%22") ) } ) ] ) left_token: spids: [921 945] ) } spids: [920] ) ] spids: [920] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:symbol) 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)['ResultSet']['Result'][0]['symbol']" ) ) } ) ] negated: False ) ] ) left_token: spids: [953 967] ) } spids: [952] ) ] spids: [952] ) (C {(unset)} {(response)}) ] spids: [917] ) spids: [913 916] ) (FuncDef name: update body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:repositoryName) op: Equal rhs: {(DQ (Bash-Snippets))} spids: [1002] ) ] spids: [1002] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:githubUserName) op: Equal rhs: {(DQ (alexanderepstein))} spids: [1011] ) ] spids: [1011] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:nameOfInstallFile) op: Equal rhs: {(DQ (install.sh))} spids: [1020] ) ] spids: [1020] ) (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: [1030 1066] ) } spids: [1029] ) ] spids: [1029] ) (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:[1122])] ) (C {(exit)} {(1)}) ] spids: [-1 1113] ) (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:[1153])] ) (C {(exit)} {(1)}) ] spids: [1131 1144] ) ] 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: [1250] ) ] 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: [1294] ) ] op_id: Op_DPipe ) terminator: ) ] spids: [-1 1282] ) ] spids: [-1 1312] ) (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: [1328] ) ] 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: [1352] ) ] 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: [1379] ) ] ) (AndOr children: [ (SimpleCommand words: [ {(git)} {(checkout)} {(DQ ($ VSub_Name "$latestVersion"))} ] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [1393] ) ] ) (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: [1447] ) ] op_id: Op_DPipe ) ] spids: [-1 1241] ) ] else_action: [(C {(exit)} {(1)})] spids: [1466 1474] ) ] spids: [-1 1182] ) ] else_action: [ (C {(echo)} {(DQ ($ VSub_Name "$repositoryName") (" is already the latest version"))} ) ] spids: [1477 1488] ) ] spids: [1162 1491] ) ] spids: [987] ) spids: [983 986] ) (FuncDef name: usage body: (BraceGroup children: [ (C {(echo)} {(DQ (Stocks))}) (C {(echo)} {(DQ ("Description: Finds the latest information on a certain stock."))}) (C {(echo)} {(DQ ("Usage: stocks [flag] or stocks [company/ticker]"))}) (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 (" stocks AAPL"))}) (C {(echo)} {(DQ (" stocks Tesla"))}) ] spids: [1501] ) spids: [1497 1500] ) (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 (uvh))} {(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:[1630])] ) (C {(exit)} {(1)}) ] spids: [1619 1620 1639 -1] ) (case_arm pat_list: [{(h)}] action: [(C {(usage)}) (C {(exit)} {(0)})] spids: [1642 1643 1654 -1] ) (case_arm pat_list: [{(v)}] action: [ (C {(echo)} {(DQ ("Version ") ($ VSub_Name "$currentVersion"))}) (C {(exit)} {(0)}) ] spids: [1657 1658 1674 -1] ) (case_arm pat_list: [{(u)}] action: [(C {(update)}) (C {(exit)} {(0)})] spids: [1677 1678 1689 -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:[1704])] ) (C {(exit)} {(1)}) ] spids: [1692 1693 1713 -1] ) ] spids: [1612 1616 1716] ) ] spids: [1609 1718] ) ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Number "$1")} right: {(DQ (update))} ) ) terminator: ) ] action: [(C {(update)}) (C {(exit)} {(0)})] spids: [-1 1736] ) (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Number "$1")} right: {(DQ (help))} ) ) terminator: ) ] action: [(C {(usage)}) (C {(exit)} {(0)})] spids: [1746 1760] ) (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Pound "$#")} right: {(DQ (0))} ) ) terminator: ) ] action: [(C {(usage)}) (C {(exit)} {(0)})] spids: [1770 1784] ) ] else_action: [ (C {(getTicker)} {(DQ ($ VSub_At "$@"))}) (C {(getStockInformation)} {($ VSub_Name "$symbol")}) (C {(printStockInformation)}) (C {(exit)} {(0)}) ] spids: [1794 1825] ) ] )