views:

49

answers:

2

Hi,

I am interested in possible methods of automatically converting the prices given when a web page is loaded from the currency given to a specified currency. Ideally, the conversion would also make use of the current exchange rate to give valid prices.

For example, in my specific case, I would like to convert the prices given in Euros (€) on this web site to Sterling (£).

I am looking at using a GreaseMonkey script for this conversion, but can anyone suggest other methods?

Thanks, MagicAndi.

A: 

The quick and easy answer is to make use of a Firefox add-on. There are a number of currency converters available as add-ons, but I ended up using Exch, as it suited my needs best.

MagicAndi
+1  A: 

Since I dabble in AutoHotkey here's a potential solution using that scripting language, it retrieves the page source from a webpage that does the conversion and parses out the converted value. This requires the httpQuery library to be included:

#Include httpQuery.ahk

InputBox, n, EUR to GBP, Enter the number., , 150, 120
if (ErrorLevel || !n)
    return
url :=  "http://www.xe.com/ucc/convert.cgi?Amount=" n "&From=EUR&To=GBP&image.x=55&image.y=8"
html := URLDownloadToVar(url)
Gui, Add, Edit, w125, % RegExMatch(html,"[\d\.]+(?= GBP)",m) ? m "£" : "The value could not be retrieved."
Gui, Show, AutoSize Center, GBP
VarSetCapacity(html,0)
Return

GuiClose: 
GuiEscape: 
Gui, Destroy
return

URLDownloadToVar(url){ 
    if !RegExMatch(url,"^http://") 
        url :=  "http://" url 
    httpQuery(html,url) 
    VarSetCapacity(html, -1) 
    Return html 
}

There are obviously more thorough (and complex) methods for solving this problem but this at least solves it with minimal effort.

southstexit, interesting, looking forward to trying it out. +1 Also, I'm a big believer in the KISS principle - http://en.wikipedia.org/wiki/KISS_principle.
MagicAndi