From f7aaed704c15a3e4db42d9749c5e59ac32734474 Mon Sep 17 00:00:00 2001 From: Alex Epstein Date: Thu, 29 Jun 2017 17:50:09 -0400 Subject: [PATCH] Setting user agent for curl --- currency/currency | 5 +++-- movies/movies | 4 ++-- stocks/stocks | 6 +++--- weather/weather | 16 ++++++++-------- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/currency/currency b/currency/currency index 307520e..594a935 100755 --- a/currency/currency +++ b/currency/currency @@ -131,7 +131,7 @@ checkInternet() ## Grabs the exchange rate and does the math for converting the currency convertCurrency() { - exchangeRate=$(curl -s "http://api.fixer.io/latest?base=$base&symbols=$exchangeTo" | grep -Eo "[0-9]*[.][0-9]*") > /dev/null + exchangeRate=$(curl -Acurl -s "http://api.fixer.io/latest?base=$base&symbols=$exchangeTo" | grep -Eo "[0-9]*[.][0-9]*") > /dev/null exchangeAmount=$(echo "$exchangeRate * $amount" | bc ) echo echo "=========================" @@ -150,7 +150,7 @@ update() repositoryName="Bash-Snippets" #Name of repostiory to be updated ex. Sandman-Lite githubUserName="alexanderepstein" #username that hosts the repostiory ex. alexanderepstein nameOfInstallFile="install.sh" # change this if the installer file has a different name be sure to include file extension if there is one - latestVersion=$(curl -s 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 + latestVersion=$(curl -Acurl -s 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 == "" ]];then echo "Error: update utility has not been configured correctly." >&2 @@ -234,6 +234,7 @@ elif [[ $# == "1" ]]; then usage else echo "Not a valid argument" + exit 1 fi elif [[ $# == 3 ]];then checkBase $1 diff --git a/movies/movies b/movies/movies index d2b9a49..6700dfd 100755 --- a/movies/movies +++ b/movies/movies @@ -29,7 +29,7 @@ getMovieInfo() { apiKey=946f500a # try not to abuse this it is a key that came from the ruby-scripts repo I link to. movie="$1+$2+$3+$4+$5+$6+$7+$8+$9" ## format the inputs to use for the api - movieInfo=$(curl -s "http://www.omdbapi.com/?t=$movie&apikey=$apiKey") > /dev/null # query the server and get the JSON response + movieInfo=$(curl -Acurl -s "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']") 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 @@ -70,7 +70,7 @@ update() repositoryName="Bash-Snippets" #Name of repostiory to be updated ex. Sandman-Lite githubUserName="alexanderepstein" #username that hosts the repostiory ex. alexanderepstein nameOfInstallFile="install.sh" # change this if the installer file has a different name be sure to include file extension if there is one - latestVersion=$(curl -s 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 + latestVersion=$(curl -Acurl -s 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 == "" ]];then echo "Error: update utility has not been configured correctly." >&2 diff --git a/stocks/stocks b/stocks/stocks index 883a25e..412d478 100755 --- a/stocks/stocks +++ b/stocks/stocks @@ -26,7 +26,7 @@ checkInternet() ## JSON response to extrapolate the information for storage getStockInformation() { - stockInfo=$(curl -s "https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=$1&apikey=KPCCCRJVMOGN9L6T") > /dev/null #grab the JSON response + stockInfo=$(curl -Acurl -s "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 @@ -69,7 +69,7 @@ printStockInformation() ## and it will determine the stock symbol for apple is AAPL and move on from there getTicker() { - response=$(curl -s "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 + response=$(curl -Acurl -s "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 unset response #just unsets the entire response after using it since all I need is the stock ticker } @@ -82,7 +82,7 @@ update() repositoryName="Bash-Snippets" #Name of repostiory to be updated ex. Sandman-Lite githubUserName="alexanderepstein" #username that hosts the repostiory ex. alexanderepstein nameOfInstallFile="install.sh" # change this if the installer file has a different name be sure to include file extension if there is one - latestVersion=$(curl -s 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 + latestVersion=$(curl -Acurl -s 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 == "" ]];then echo "Error: update utility has not been configured correctly." >&2 diff --git a/weather/weather b/weather/weather index 19c668c..522b5dc 100755 --- a/weather/weather +++ b/weather/weather @@ -15,21 +15,21 @@ checkCurl() getIPWeather() { - country=$(curl -s ipinfo.io/country) > /dev/null ## grab the country + country=$(curl -Acurl -s ipinfo.io/country) > /dev/null ## grab the country if [[ $country == "US" ]];then ## if were in the us id rather not use longitude and latitude so the output is nicer - city=$(curl -s ipinfo.io/city) > /dev/null - region=$(curl -s ipinfo.io/region) > /dev/null + city=$(curl -Acurl -s ipinfo.io/city) > /dev/null + region=$(curl -Acurl -s ipinfo.io/region) > /dev/null region=$(echo "$region" | tr -dc '[:upper:]') - curl $locale.wttr.in/$city,$region$1 + curl -Acurl $locale.wttr.in/$city,$region$1 else ## otherwise we are going to use longitude and latitude - location=$(curl -s ipinfo.io/loc) > /dev/null - curl $locale.wttr.in/$location$1 + location=$(curl -Acurl-s ipinfo.io/loc) > /dev/null + curl -Acurl $locale.wttr.in/$location$1 fi } getLocationWeather() { - curl $locale.wttr.in/$1+$2+$3+$4 + curl -Acurl $locale.wttr.in/$1+$2+$3+$4 } checkInternet() @@ -51,7 +51,7 @@ update() repositoryName="Bash-Snippets" #Name of repostiory to be updated ex. Sandman-Lite githubUserName="alexanderepstein" #username that hosts the repostiory ex. alexanderepstein nameOfInstallFile="install.sh" # change this if the installer file has a different name be sure to include file extension if there is one - latestVersion=$(curl -s 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 + latestVersion=$(curl -Acurl -s 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 == "" ]];then echo "Error: update utility has not been configured correctly." >&2