Skip to content

Instantly share code, notes, and snippets.

@ehamberg
Created January 13, 2011 00:03
Show Gist options
  • Save ehamberg/777139 to your computer and use it in GitHub Desktop.
Save ehamberg/777139 to your computer and use it in GitHub Desktop.
Get temperature for current location (hopefully)
#!/bin/bash
GEOIP_API_KEY="" # http://geoio.com/signup.php
WEATHER_API_KEY="" # http://www.worldweatheronline.com/register.aspx
IP=$(curl -s "http://whatismyip.org/")
GEOIP_URL="http://api.geoio.com/q.php?key=$GEOIP_API_KEY&qt=geoip&d=comma&q=$IP"
LAT_LONG=$(curl -s "$GEOIP_URL"|awk -F, '{print $(NF-1)","$NF}')
WEATHER_URL="http://www.worldweatheronline.com/feed/weather.ashx?q=${LAT_LONG}&format=csv&num_of_days=2&key=$WEATHER_API_KEY"
TEMP=$(curl -s "$WEATHER_URL"|awk -F, '/^[^#]/ {print $2;exit}')
if [ $TEMP -gt "20" ]; then
echo "<fc=#ee4444>${TEMP}</fc>"
elif [ $TEMP -lt "0" ]; then
echo "<fc=#3bb9ff>${TEMP}</fc>"
else
echo "${TEMP}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment