From b273d23d77696b4c6ddabe14e68102e2d46120e7 Mon Sep 17 00:00:00 2001 From: Alex Epstein Date: Mon, 26 Jun 2017 20:45:42 -0400 Subject: [PATCH] Can now enter company name It will grab ticker automatically by using most relevant result from yahoo finance. --- stocks/stocks | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/stocks/stocks b/stocks/stocks index cda23c1..61407a3 100755 --- a/stocks/stocks +++ b/stocks/stocks @@ -13,8 +13,8 @@ checkInternet() getStockInformation() { - symbol=$1 - stockInfo=$(curl -s "https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=$symbol&apikey=KPCCCRJVMOGN9L6T") > /dev/null + symb=$1 + stockInfo=$(curl -s "https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=$symb&apikey=KPCCCRJVMOGN9L6T") > /dev/null export PYTHONIOENCODING=utf8 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; } exchangeName=$(echo $stockInfo | python -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['02. Exchange Name']") @@ -47,6 +47,14 @@ printStockInformation() echo } +getTicker() +{ + response=$(curl -s "http://d.yimg.com/autoc.finance.yahoo.com/autoc?query=$1®ion=1&lang=en%22") > /dev/null + symbol=$(echo $response | python -c "import sys, json; print json.load(sys.stdin)['ResultSet']['Result'][0]['symbol']") + unset response +} + checkInternet || exit 1 -getStockInformation $1 +getTicker $1 +getStockInformation $symbol printStockInformation