Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using API in Bash without curl

Tags:

bash

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/&amp;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

like image 494
Benji Avatar asked Jan 19 '26 13:01

Benji


1 Answers

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

like image 85
hek2mgl Avatar answered Jan 21 '26 07:01

hek2mgl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!