How can I get exchange rates after google retired iGoogle?

264 views Asked by At

I used this link to fetch the pound to euro exchange rate on a daily (nightly) basis:

http://www.google.com/ig/calculator?hl=en&q=1pound=?euro

This returned an array which I then stripped and used the data I needed.

Since the first of November they retired iGoogle resulting in the URL to forward to: https://support.google.com/websearch/answer/2664197

Anyone knows an alternative URL that won't require me to rewrite the whole function? I'm sure google didn't stop providing this service entirely.

1

There are 1 answers

1
IncredibleHat On BEST ANSWER

I started getting cronjob errors today on this very issue. So I fell back to a prior URL I was using before I switched to the faster/reliable iGoogle.

Url to programmatically hit (USD to EUR): http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=USD&ToCurrency=EUR

Details about it: http://www.webservicex.net/ws/WSDetails.aspx?CATID=2&WSID=10

It works for now, but its prone to be slow at times, and used to respond with an "Out of space" error randomly. Just be sure to code in a way to handle that, and maybe run the cron four times a day instead of once. I run ours every hour.

Example code to get the rate out of the return (there is probably a more elegant way):

$ci = curl_init($accessurl);
curl_setopt($ci, CURLOPT_HTTPGET, 1);
curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);
$rawreturn = curl_exec($ci);
curl_close($ci);
$rate = trim(preg_replace("/.*<double[^>]*>([^<]*)<\/double[^>]*>.*/i","$1",$rawreturn));