webERP Forum

Full Version: Currencies Maintenance: graphs no longer work
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Not critical, but currencies graphs are no longer displayed as Google seems to have updated its API for these:

Setup > Currencies maintenance : click on "Graph" for the currency that is not a "functional" one: displays a broken image

Thank you for looking into this
Yeah the Google api calls no longer work. I wrote a function to use another provider. I will upload the function later when I am I front of a computer

Tim
Great, Thank you Tim!
Below is my yahoo function. It would be really nice if anybody knows of an open data source for this information where the APIs wouldn't get arbitrarily removed or changed regularly.

Tim

function yahoo_currency_rate($CurrCode) {
if (http_file_exists('https://finance.yahoo.com/webservice/v1/symbols/allcurrencies/quote')) {
$xml = file_get_contents('https://finance.yahoo.com/webservice/v1/symbols/allcurrencies/quote');
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($parser, $xml, $tags);
xml_parser_free($parser);

$elements = array(); // the currently filling [child] XmlElement array
$stack = array();
foreach ($tags as $tag) {
$index = count($elements);
if ($tag['type'] == 'complete' or $tag['type'] == 'open') {
$elements[$index] = new XmlElement;
$elements[$index]->name = $tag['tag'];
if (isset($tag['attributes'])) {
$elements[$index]->attributes = $tag['attributes'];
}
if (isset($tag['value'])) {
$elements[$index]->content = $tag['value'];
}
if ($tag['type'] == 'open') { // push
$elements[$index]->children = array();
$stack[count($stack)] =& $elements;
$elements =& $elements[$index]->children;
}
}
if ($tag['type'] == 'close') { // pop
$elements =& $stack[count($stack) - 1];
unset($stack[count($stack) - 1]);
}
}
$Currencies = array();
foreach ($elements[0]->children[1]->children as $CurrencyDetails) {
foreach ($CurrencyDetails as $CurrencyDetail) {
if (is_array($CurrencyDetail) and isset($CurrencyDetail[0])) {
$Currencies[mb_substr($CurrencyDetail[0]->content, 4)] = $CurrencyDetail[1]->content;
}
}
}
$Currencies['USD'] = 1; //ECB delivers no rate for Euro
//return an array of the currencies and rates
return $Currencies;
} else {
return false;
}
}
(12-22-2017, 09:05 AM)falkoner Wrote: [ -> ]Below is my yahoo function. It would be really nice if anybody knows of an open data source for this information where the APIs wouldn't get arbitrarily removed or changed regularly.

Tim

function yahoo_currency_rate($CurrCode) {
if (http_file_exists('https://finance.yahoo.com/webservice/v1/symbols/allcurrencies/quote')) {
$xml = file_get_contents('https://finance.yahoo.com/webservice/v1/symbols/allcurrencies/quote');
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($parser, $xml, $tags);
xml_parser_free($parser);

$elements = array(); // the currently filling [child] XmlElement array
$stack = array();
foreach ($tags as $tag) {
$index = count($elements);
if ($tag['type'] == 'complete' or $tag['type'] == 'open') {
$elements[$index] = new XmlElement;
$elements[$index]->name = $tag['tag'];
if (isset($tag['attributes'])) {
$elements[$index]->attributes = $tag['attributes'];
}
if (isset($tag['value'])) {
$elements[$index]->content = $tag['value'];
}
if ($tag['type'] == 'open') { // push
$elements[$index]->children = array();
$stack[count($stack)] =& $elements;
$elements =& $elements[$index]->children;
}
}
if ($tag['type'] == 'close') { // pop
$elements =& $stack[count($stack) - 1];
unset($stack[count($stack) - 1]);
}
}
$Currencies = array();
foreach ($elements[0]->children[1]->children as $CurrencyDetails) {
foreach ($CurrencyDetails as $CurrencyDetail) {
if (is_array($CurrencyDetail) and isset($CurrencyDetail[0])) {
$Currencies[mb_substr($CurrencyDetail[0]->content, 4)] = $CurrencyDetail[1]->content;
}
}
}
$Currencies['USD'] = 1; //ECB delivers no rate for Euro
//return an array of the currencies and rates
return $Currencies;
} else {
return false;
}
}


how about this one:? did anybody try it?

https://openexchangerates.org