Hello, this may be my first Code Gallery contribution.
I got inspired by Jerret's (fowlplay4)
Translate script that used
Google as it's engine.
So, I've made a Google Currency Converter out of Jerret's Script!
Class "class_currency":*
PHP Code:
function onCreated() {
// For Server's running on the 64-bit NPC-Server
addDNSEntry("www.google.com", "72.14.213.95");
}
function Convert(amount, from, to) {
// Make from and To UpperCase
temp.f = from.upper();
temp.t = to.upper();
// Determine URL
temp.site = "http://www.google.com/finance/converter";
temp.url = temp.site @ "?a=" @ amount @ "&from=" @ temp.f @ "&to=" @ temp.t;
// Request URL
temp.req = requesturl(temp.url);
this.catchevent(temp.req, "onReceiveData", "onConvert");
}
function onConvert(obj) {
// Perseing Time!
temp.parse = obj.fulldata.substring(obj.fulldata.pos("<!DOCTYPE") + obj.fulldata.pos("<div id=currency_converter_result>") );
temp.parse2 = temp.parse.substring(0, temp.parse.pos("</span>"));
temp.parse3 = temp.parse2.substring("<div id=currency_converter_result>".length());
temp.parse4 = temp.parse3.substring(0, temp.parse3.pos("<span class=bld>")) @
temp.parse3.substring(temp.parse3.pos("<span class=bld>") + "<span class=bld>".length());
// Echo Parsed Data
echo(temp.parse4);
}
*
=The class can be named anything you want,
but I named it for the Example usage.
Example Usage:
PHP Code:
function onCreated() {
this.join("class_currency");
Convert(1, "Eur", "UsD");
// Would echo "1 EUR = 1.4632 USD"
}
Currency list at Attachment.
Cheers