mirror of
https://github.com/alexanderepstein/Bash-Snippets
synced 2018-11-08 02:59:35 +01:00
Explicity asking for python2 in all python calls
This commit is contained in:
parent
d04b600ad1
commit
44ce35f4be
@ -42,25 +42,25 @@ checkInternet()
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
## This function grabs information about a movie and using python parses the
|
## This function grabs information about a movie and using python2 parses the
|
||||||
## JSON response to extrapolate the information for storage
|
## JSON response to extrapolate the information for storage
|
||||||
getMovieInfo()
|
getMovieInfo()
|
||||||
{
|
{
|
||||||
apiKey=946f500a # try not to abuse this it is a key that came from the ruby-scripts repo I link to.
|
apiKey=946f500a # try not to abuse this it is a key that came from the ruby-scripts repo I link to.
|
||||||
movie=$(echo $1 $2 $3 $4 $5 $6 $7 $8 $9 | tr " " + ) ## format the inputs to use for the api
|
movie=$(echo $1 $2 $3 $4 $5 $6 $7 $8 $9 | tr " " + ) ## format the inputs to use for the api
|
||||||
export PYTHONIOENCODING=utf8 #necessary for python in some cases
|
export PYTHONIOENCODING=utf8 #necessary for python2 in some cases
|
||||||
movieInfo=$(httpGet "http://www.omdbapi.com/?t=$movie&apikey=$apiKey") > /dev/null # query the server and get the JSON response
|
movieInfo=$(httpGet "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']")
|
checkResponse=$(echo $movieInfo | python2 -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
|
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
|
# The rest of the code is just extrapolating the data with python2 from the JSON response
|
||||||
title=$(echo $movieInfo | python -c "import sys, json; print json.load(sys.stdin)['Title']")
|
title=$(echo $movieInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Title']")
|
||||||
year=$(echo $movieInfo | python -c "import sys, json; print json.load(sys.stdin)['Year']")
|
year=$(echo $movieInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Year']")
|
||||||
score=$(echo $movieInfo | python -c "import sys, json; print json.load(sys.stdin)['Ratings'][1]['Value']")
|
score=$(echo $movieInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Ratings'][1]['Value']")
|
||||||
rated=$(echo $movieInfo | python -c "import sys, json; print json.load(sys.stdin)['Rated']")
|
rated=$(echo $movieInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Rated']")
|
||||||
genre=$(echo $movieInfo | python -c "import sys, json; print json.load(sys.stdin)['Genre']")
|
genre=$(echo $movieInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Genre']")
|
||||||
director=$(echo $movieInfo | python -c "import sys, json; print json.load(sys.stdin)['Director']")
|
director=$(echo $movieInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Director']")
|
||||||
actors=$(echo $movieInfo | python -c "import sys, json; print json.load(sys.stdin)['Actors']")
|
actors=$(echo $movieInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Actors']")
|
||||||
plot=$(echo $movieInfo | python -c "import sys, json; print json.load(sys.stdin)['Plot']")
|
plot=$(echo $movieInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Plot']")
|
||||||
unset movieInfo # don't need this anymore
|
unset movieInfo # don't need this anymore
|
||||||
unset checkResponse # don't need this anymore
|
unset checkResponse # don't need this anymore
|
||||||
}
|
}
|
||||||
|
@ -104,12 +104,12 @@ expandURL()
|
|||||||
url=$1
|
url=$1
|
||||||
fi
|
fi
|
||||||
response=$(httpGet http://x.datasig.io/short?url=$url)
|
response=$(httpGet http://x.datasig.io/short?url=$url)
|
||||||
errorCheck=$(echo $response | python -c "import sys, json; print json.load(sys.stdin)['/short']['message']" 2> /dev/null )
|
errorCheck=$(echo $response | python2 -c "import sys, json; print json.load(sys.stdin)['/short']['message']" 2> /dev/null )
|
||||||
if [[ $errorCheck == "Error in /short" ]];then
|
if [[ $errorCheck == "Error in /short" ]];then
|
||||||
echo "Error: 404 could not find the website"
|
echo "Error: 404 could not find the website"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
expandedURL=$(echo $response | python -c "import sys, json; print json.load(sys.stdin)['/short']['destination']" 2> /dev/null )
|
expandedURL=$(echo $response | python2 -c "import sys, json; print json.load(sys.stdin)['/short']['destination']" 2> /dev/null )
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,24 +41,24 @@ checkInternet()
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
## This function grabs information about a stock and using python parses the
|
## This function grabs information about a stock and using python2 parses the
|
||||||
## JSON response to extrapolate the information for storage
|
## JSON response to extrapolate the information for storage
|
||||||
getStockInformation()
|
getStockInformation()
|
||||||
{
|
{
|
||||||
stockInfo=$(httpGet "https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=$1&apikey=KPCCCRJVMOGN9L6T") > /dev/null #grab the JSON response
|
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
|
export PYTHONIOENCODING=utf8 #necessary for python2 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
|
echo $stockInfo | python2 -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
|
# The rest of the code is just extrapolating the data with python2 from the JSON response
|
||||||
exchangeName=$(echo $stockInfo | python -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['02. Exchange Name']")
|
exchangeName=$(echo $stockInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['02. Exchange Name']")
|
||||||
latestPrice=$(echo $stockInfo | python -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['03. Latest Price']")
|
latestPrice=$(echo $stockInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['03. Latest Price']")
|
||||||
open=$(echo $stockInfo | python -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['04. Open (Current Trading Day)']")
|
open=$(echo $stockInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['04. Open (Current Trading Day)']")
|
||||||
high=$(echo $stockInfo | python -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['05. High (Current Trading Day)']")
|
high=$(echo $stockInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['05. High (Current Trading Day)']")
|
||||||
low=$(echo $stockInfo | python -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['06. Low (Current Trading Day)']")
|
low=$(echo $stockInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['06. Low (Current Trading Day)']")
|
||||||
close=$(echo $stockInfo | python -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['07. Close (Previous Trading Day)']")
|
close=$(echo $stockInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['07. Close (Previous Trading Day)']")
|
||||||
priceChange=$(echo $stockInfo | python -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['08. Price Change']")
|
priceChange=$(echo $stockInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['08. Price Change']")
|
||||||
priceChangePercentage=$(echo $stockInfo | python -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['09. Price Change Percentage']")
|
priceChangePercentage=$(echo $stockInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['09. Price Change Percentage']")
|
||||||
volume=$(echo $stockInfo | python -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['10. Volume (Current Trading Day)']")
|
volume=$(echo $stockInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['10. Volume (Current Trading Day)']")
|
||||||
lastUpdated=$(echo $stockInfo | python -c "import sys, json; print json.load(sys.stdin)['Realtime Global Securities Quote']['11. Last Updated']")
|
lastUpdated=$(echo $stockInfo | python2 -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
|
unset stockInfo # done with the JSON response not needed anymore
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ printStockInformation()
|
|||||||
getTicker()
|
getTicker()
|
||||||
{
|
{
|
||||||
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
|
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
|
||||||
symbol=$(echo $response | python -c "import sys, json; print json.load(sys.stdin)['ResultSet']['Result'][0]['symbol']") # using python to extrapolate the stock symbol
|
symbol=$(echo $response | python2 -c "import sys, json; print json.load(sys.stdin)['ResultSet']['Result'][0]['symbol']") # using python2 to extrapolate the stock symbol
|
||||||
unset response #just unsets the entire response after using it since all I need is the stock ticker
|
unset response #just unsets the entire response after using it since all I need is the stock ticker
|
||||||
}
|
}
|
||||||
|
|
||||||
|
32
taste/taste
32
taste/taste
@ -90,35 +90,35 @@ update()
|
|||||||
## This function gets 3 results similar to the item of interest
|
## This function gets 3 results similar to the item of interest
|
||||||
getSimilar()
|
getSimilar()
|
||||||
{
|
{
|
||||||
export PYTHONIOENCODING=utf8 #necessary for python in some cases
|
export PYTHONIOENCODING=utf8 #necessary for python2 in some cases
|
||||||
media=$( echo "$1 $2 $3 $4 $5 $6 $7 $8" | tr " " + )
|
media=$( echo "$1 $2 $3 $4 $5 $6 $7 $8" | tr " " + )
|
||||||
response=$(httpGet "https://tastedive.com/api/similar?q=$media&k=$apiKey&info=$info")
|
response=$(httpGet "https://tastedive.com/api/similar?q=$media&k=$apiKey&info=$info")
|
||||||
## Extrapolate the information by parsing the JSON
|
## 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; } )
|
nameOne=$(echo $response | python2 -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)
|
typeOne=$(echo $response | python2 -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)
|
nameTwo=$(echo $response | python2 -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)
|
typeTwo=$(echo $response | python2 -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)
|
nameThree=$(echo $response | python2 -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)
|
typeThree=$(echo $response | python2 -c "import sys, json; print json.load(sys.stdin)['Similar']['Results'][2]['Type']" 2> /dev/null)
|
||||||
if [[ $info == "1" ]];then ## if we want more detailed info we have to grab a few more fields
|
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)
|
wikiOne=$(echo $response | python2 -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)
|
wikiTwo=$(echo $response | python2 -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)
|
wikiThree=$(echo $response | python2 -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)
|
youtube=$(echo $response | python2 -c "import sys, json; print json.load(sys.stdin)['Similar']['Results'][0]['yUrl']" 2> /dev/null)
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
## This function grabs all the information it can on the item of interest itself
|
## This function grabs all the information it can on the item of interest itself
|
||||||
getInfo()
|
getInfo()
|
||||||
{
|
{
|
||||||
export PYTHONIOENCODING=utf8 #necessary for python in some cases
|
export PYTHONIOENCODING=utf8 #necessary for python2 in some cases
|
||||||
media=$( echo "$1 $2 $3 $4 $5 $6 $7 $8" | tr " " + )
|
media=$( echo "$1 $2 $3 $4 $5 $6 $7 $8" | tr " " + )
|
||||||
response=$(httpGet "https://tastedive.com/api/similar?q=$media&k=$apiKey&info=$info")
|
response=$(httpGet "https://tastedive.com/api/similar?q=$media&k=$apiKey&info=$info")
|
||||||
name=$(echo $response | python -c "import sys, json; print json.load(sys.stdin)['Similar']['Info'][0]['Name']")
|
name=$(echo $response | python2 -c "import sys, json; print json.load(sys.stdin)['Similar']['Info'][0]['Name']")
|
||||||
type=$(echo $response | python -c "import sys, json; print json.load(sys.stdin)['Similar']['Info'][0]['Type']")
|
type=$(echo $response | python2 -c "import sys, json; print json.load(sys.stdin)['Similar']['Info'][0]['Type']")
|
||||||
if [[ $info == "1" ]]; then
|
if [[ $info == "1" ]]; then
|
||||||
wiki=$(echo $response | python -c "import sys, json; print json.load(sys.stdin)['Similar']['Info'][0]['wTeaser']")
|
wiki=$(echo $response | python2 -c "import sys, json; print json.load(sys.stdin)['Similar']['Info'][0]['wTeaser']")
|
||||||
youtube=$(echo $response | python -c "import sys, json; print json.load(sys.stdin)['Similar']['Info'][0]['yUrl']")
|
youtube=$(echo $response | python2 -c "import sys, json; print json.load(sys.stdin)['Similar']['Info'][0]['yUrl']")
|
||||||
else
|
else
|
||||||
wiki="None"
|
wiki="None"
|
||||||
youtube="None"
|
youtube="None"
|
||||||
|
Loading…
Reference in New Issue
Block a user