mirror of
https://github.com/alexanderepstein/Bash-Snippets
synced 2018-11-08 02:59:35 +01:00
Added ability to grab static map of location and route map of route
This commit is contained in:
parent
684a962eb3
commit
c17839f558
82
maps/maps
82
maps/maps
@ -5,7 +5,7 @@ currentVersion="1.11.0"
|
|||||||
configuredClient=""
|
configuredClient=""
|
||||||
configuredPython=""
|
configuredPython=""
|
||||||
source ~/.bash_profile ## allows grabbing enviornment variable
|
source ~/.bash_profile ## allows grabbing enviornment variable
|
||||||
apiKey=$MAPQUEST_API_KEY
|
MAPQUEST_API_KEY=$MAPQUEST_API_KEY
|
||||||
|
|
||||||
## This function determines which http get tool the system has installed and returns an error if there isnt one
|
## This function determines which http get tool the system has installed and returns an error if there isnt one
|
||||||
getConfiguredClient()
|
getConfiguredClient()
|
||||||
@ -105,28 +105,46 @@ update()
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
#first direction not grepped correctly cannot grep distances correctly all other directionms are grepped correctly.
|
|
||||||
getDirections()
|
getDirections()
|
||||||
{
|
{
|
||||||
response=$(httpGet "https://www.mapquestapi.com/directions/v2/route?key=$MAPQUEST_API_KEY&from=$1&to=$2&outFormat=json&ambiguities=ignore&routeType=fastest&doReverseGeocode=false&enhancedNarrative=true&avoidTimedConditions=false")
|
response=$(httpGet "https://www.mapquestapi.com/directions/v2/route?key=$MAPQUEST_API_KEY&from=$1&to=$2&outFormat=json&ambiguities=ignore&routeType=fastest&doReverseGeocode=false&enhancedNarrative=true&avoidTimedConditions=false")
|
||||||
firstDirection=$(echo $response | grep -Eo "origNarrative\":\"[a-Z -./0-9]*" | grep -Eo "[^origNarrative\":][a-Z -./0-9]*" )
|
firstDirection=$(echo $response | grep -Eo "origNarrative\":\"[a-Z -./0-9]*" | grep -Eo "[^origNarrative\":][a-Z -./0-9]*" )
|
||||||
tempDirections=($(echo $response | grep -Eo "\"narrative\":\"[a-Z -./0-9]*"))
|
tempDirections=($(echo $response | grep -Eo "\"narrative\":\"[a-Z -./0-9]*"))
|
||||||
distances=($(echo $response | grep -Eo "distance\":[0-9]*[.][0-9]*" | grep -Eo "[^distance\":][0-9]*[.][0-9]*" ))
|
distances=($(echo $response | grep -Eo "distance\":[0-9]*[.][0-9]*" | grep -Eo "[^distance\":][0-9]*[.][0-9]*" ))
|
||||||
count="-1"
|
count="-1"
|
||||||
temp=${tempDirections[0]}
|
temp=${tempDirections[0]}
|
||||||
for direct in "${tempDirections[@]}"
|
for direct in "${tempDirections[@]}"
|
||||||
do
|
do
|
||||||
if [[ $(echo $direct | grep -Eo "narrative" ) == "narrative" ]];then
|
if [[ $(echo $direct | grep -Eo "narrative" ) == "narrative" ]];then
|
||||||
count=$(echo $count + 1 | bc )
|
count=$(echo $count + 1 | bc )
|
||||||
directions[$count]=$temp
|
directions[$count]=$temp
|
||||||
temp=$(echo $direct | grep -Eo "[^\"narrative:\"][a-Z 0-9./]*")
|
temp=$(echo $direct | grep -Eo "[^\"narrative:\"][a-Z 0-9./]*")
|
||||||
else
|
else
|
||||||
temp="$temp $direct"
|
temp="$temp $direct"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
#for distance in $tempDistances
|
#for distance in $tempDistances
|
||||||
directions[0]=$firstDirection
|
directions[0]=$firstDirection
|
||||||
|
}
|
||||||
|
|
||||||
|
getDirectionsMap()
|
||||||
|
{
|
||||||
|
echo "Generating route map from $1 to $2"
|
||||||
|
if [[ "$OSTYPE" == "linux"* ]];then
|
||||||
|
if command -v display &>/dev/null ;then
|
||||||
|
mkdir ~/temp || return 1
|
||||||
|
httpGet "https://www.mapquestapi.com/staticmap/v5/map?start=$1&end=$2&size=600,400@2x&key=$MAPQUEST_API_KEY" >> ~/temp/routeImage.png || return 1
|
||||||
|
display ~/temp/routeImage.png > /dev/null || return 1
|
||||||
|
else
|
||||||
|
echo "To use the map image features you must install imagemagick"
|
||||||
|
fi
|
||||||
|
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||||
|
mkdir ~/temp
|
||||||
|
httpGet "https://www.mapquestapi.com/staticmap/v5/map?start=$1&end=$2&size=600,400@2x&key=$MAPQUEST_API_KEY" >> ~/temp/routeImage.png || return 1
|
||||||
|
open ~/temp/routeImage.png > /dev/null
|
||||||
|
fi
|
||||||
|
rm -rf ~/temp > /dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
printDirections()
|
printDirections()
|
||||||
@ -135,7 +153,7 @@ printDirections()
|
|||||||
totalDist="0"
|
totalDist="0"
|
||||||
for dist in "${distances[@]}"
|
for dist in "${distances[@]}"
|
||||||
do
|
do
|
||||||
totalDist=$(echo $totalDist + $dist | bc)
|
totalDist=$(echo $totalDist + $dist | bc)
|
||||||
done
|
done
|
||||||
echo "From $1 to $2 ($totalDist mi)"
|
echo "From $1 to $2 ($totalDist mi)"
|
||||||
echo "==================================================="
|
echo "==================================================="
|
||||||
@ -144,18 +162,40 @@ printDirections()
|
|||||||
do
|
do
|
||||||
echo -n "$(echo $count + 1 | bc)). "
|
echo -n "$(echo $count + 1 | bc)). "
|
||||||
if [[ $direct != "" ]];then # sometimes original Narrative is blank
|
if [[ $direct != "" ]];then # sometimes original Narrative is blank
|
||||||
direct="$direct (${distances[$count]} mi)"
|
direct="$direct (${distances[$count]} mi)"
|
||||||
count=$(echo $count + 1 | bc )
|
count=$(echo $count + 1 | bc )
|
||||||
echo $direct
|
echo $direct
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
echo "Welcome to $2"
|
echo "Welcome to $2"
|
||||||
echo "==================================================="
|
echo "==================================================="
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
getStaticMap()
|
||||||
|
{
|
||||||
|
echo "Generating static map for $1"
|
||||||
|
if [[ "$OSTYPE" == "linux"* ]];then
|
||||||
|
if command -v display &>/dev/null ;then
|
||||||
|
mkdir ~/temp || return 1
|
||||||
|
httpGet "https://www.mapquestapi.com/staticmap/v5/map?key=$MAPQUEST_API_KEY¢er=$1&zoom=15&type=hyb&size=600,400@2x" >> ~/temp/mapImage.png || return 1
|
||||||
|
display ~/temp/mapImage.png > /dev/null || return 1
|
||||||
|
else
|
||||||
|
echo "To use the map image features you must install imagemagick"
|
||||||
|
fi
|
||||||
|
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||||
|
mkdir ~/temp || return 1
|
||||||
|
httpGet "https://www.mapquestapi.com/staticmap/v5/map?key=$MAPQUEST_API_KEY¢er=$1&zoom=15&type=hyb&size=600,400@2x" >> ~/temp/mapImage.png || return 1
|
||||||
|
open ~/temp/mapImage.png > /dev/null || return 1
|
||||||
|
fi
|
||||||
|
rm -rf ~/temp > /dev/null || return 1
|
||||||
|
}
|
||||||
|
|
||||||
getConfiguredPython || exit 1
|
getConfiguredPython || exit 1
|
||||||
getConfiguredClient || exit 1
|
getConfiguredClient || exit 1
|
||||||
checkInternet || exit 1
|
checkInternet || exit 1
|
||||||
getDirections Denver Boulder || exit 1
|
getDirections Denver Boulder || exit 1
|
||||||
printDirections Denver Boulder || exit 1
|
printDirections Denver Boulder || exit 1
|
||||||
|
getDirectionsMap Denver Boulder || exit 1
|
||||||
|
getStaticMap Paramus || exit 1
|
||||||
|
Loading…
Reference in New Issue
Block a user