I'm writing a script that has a function using a weather API. for now I only managed to solve this problem with curl but I recently noticed I don have access to curl where I need the script to run. Is there any other way I can solve this? The code I have is this:
weatherLondon()
{
echo "<h3>Weather in London</h3>"
(( $# )) || set -- "London,UK"
echo "Location: ${1//,/, }"
curl -s "http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query=$1" | perl -ne 's/&deg;/°/g;
s/ \(\d+°F\)//g;
/<title>([^<]+)/ && printf "%s: ",$1;
/<fcttext>([^<]+)/ && print $1,"\n"';
}
I found this code at http://www.commandlinefu.com/commands/view/4821/get-the-weather-forecast-for-the-next-24-to-48-for-your-location
I'm very new with both bash and API's
You can use good old wget. It should be part of almost every Linux distribution (unless not administratively removed). Replace your curl statement with:
wget -q -O - "http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query=$1"
-O - sets the output to standard output, -q suppresses debugging output like curl's -s
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With