Created
January 29, 2014 16:11
-
-
Save napcae/8691290 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function dateISO { | |
date -u +"%Y-%m-%dT%H:%M:%S"; | |
} | |
function externalIP { | |
curl -s http://checkip.dyndns.org | sed 's/[a-zA-Z/<> :]//g' | tr -d '\r' | |
} | |
function geoIP { | |
curl -s ipinfo.io/$(externalIP) | |
} | |
function getLocation { | |
geoIP | grep -Po '(?<="loc": ")[^"]*' | |
} | |
function createForecastAPI { | |
curl -s https://api.forecast.io/forecast/XXXXXXXXXXX/$(getLocation),$(dateISO)?units=si | |
} | |
function getMaxTemp { | |
createForecastAPI | grep -Po '(?<="temperatureMax":)[^,]*' | |
} | |
function getMinTemp { | |
createForecastAPI | grep -Po '(?<="temperatureMin":)[^,]*' | |
} | |
function getCurTemp { | |
createForecastAPI | grep -Po '(?<="temperature":)[^,]*' | head -1 | |
} | |
usage="Dummy help" | |
while getopts "mic" opt; do | |
case $opt in | |
m) | |
getMaxTemp | |
;; | |
i) | |
getMinTemp | |
;; | |
c) | |
getCurTemp | |
;; | |
\?) | |
echo "Invalid option: -$OPTARG" >&2 | |
;; | |
esac | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment