Skip to content

Instantly share code, notes, and snippets.

@napcae
Created January 29, 2014 16:11
Show Gist options
  • Save napcae/8691290 to your computer and use it in GitHub Desktop.
Save napcae/8691290 to your computer and use it in GitHub Desktop.
#!/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