Currency Converter Dialog

By vaseline28 on May 25, 2008

My Currency Converter dialog for mIRC.
I have recently re-done the script to take out favorites, killed the problem with the timers to make the whole script much more efficient and less annoying!

Converts X number from one currency to another one.

Thanks to Lindrian for help with the on *:SOCKREAD: event and $regex !

If script says converting for long time, close it and start again (should only happen first time you run)

Image

Image

menu status,channel,nicklist {
  [Currency Converter]: $iif(!$dialog(CurrencyConverter),dialog -mied CurrencyConverter CurrencyConverter,halt)
}
alias currencyconverter $iif(!$dialog(CurrencyConverter),dialog -mied CurrencyConverter CurrencyConverter,halt)
dialog CurrencyConverter {
  title "Currency Converter"
  size -1 -1 240 280
  text "Currency Converter ~Vaseline28", 1, 35 4 200 20
  text "Information thanks to: finance.yahoo.com", 2, 20 20 230 20 
  tab "Custom", 3, 10 50 220 220
  button "New Conversion", 5, 20 80 200 40, left, tab 3
  box "Results", 6, 20 125 200 130, tab 3
  text "From:", 7, 30 150 80 20, tab 3
  text "To:", 8, 30 170 80 20, tab 3
  text "Amount:", 9, 30 190 80 20, tab 3
  text "Converts to:", 10, 30 210 80 20, tab 3
  text "Exchange Rate:", 11, 30 230 80 20, tab 3
  text "**", 12, 80 150 80 20, tab 3
  text "**", 13, 70 170 80 20, tab 3
  text "**", 14, 90 190 80 20, tab 3
  text "**", 15, 105 210 80 20, tab 3
  text "**", 16, 120 230 80 20, tab 3
  box "Conversion Information", 17, 10 280 220 160
  box "From", 18, 20 300 90 90
  box "To", 19, 130 300 90 90
  box "Amount", 20, 20 390 200 45
  edit "Replace with Number. No symbols", 21, 30 408 180 20
  button "Go!", 22, 200 445 30 20
  button "Cancel", 23, 155 445 40 20
  combo 24, 30 318 70 70
  combo 25, 140 318 70 70
  text "", 26, 15 445 140 20, hide
}
on *:dialog:CurrencyConverter:init:*: {
  var %i GBP USD EUR ARS BBD BZB BOB BRL CAD CLP COP CRC CUP ECS MXN PAB PYG BZD BWP DJF DOP EGP ERN ETP FJD GMD GHC GYD HKD INR IDR IRR IQD ILS JPY KES KRW NAD NPR NZDNIO NGN PKR PHR RUB SOS ZAR SGD LKR
  var %x 0
  while (%x < $numtok(%i,32)) {
    inc %x
    did -i $dname 24 %x $gettok(%i,%x,32)
    did -i $dname 25 %x $gettok(%i,%x,32)
  }
  if (%CurrencyFavoriteOn != $null) { did -h $dname 27-43 | did -v $dname 44 }
}
on *:dialog:CurrencyConverter:sclick:5: {
  dialog -s $dname -1 -1 240 470
}
on *:dialog:CurrencyConverter:sclick:23: {
  dialog -s $dname -1 -1 240 280
}
on *:dialog:CurrencyConverter:sclick:22: {
  timercurrency off
  $iif(!$did($dname,24).seltext, customconvertwrong, did -h $dname 26)
  $iif(!$did($dname,25).seltext, customconvertwrong, did -h $dname 26)
  $iif($did($dname,21).edited == $false, customconvertwrong, did -h $dname 26)
  dialog -s $dname  -1 -1 240 280
  did -av $dname 12 $did($dname,24).seltext | did -av $dname 13 $did($dname,25).seltext | did -av $dname 14 $didtok($dname,21,32) | did -av $dname 15 ...Converting... | did -av $dname 16 ...Converting...
  currency $didtok($dname,21,32) $did($dname,24).seltext $did($dname,25).seltext

  did -u $dname 24 | did -u $dname 25 | did -o $dname 21 1 Replace with Number. No symbols
}
alias customconvertwrong {
  did -av $dname 26 Invalid Parameters selected.
  halt
}
on *:dialog:CurrencyConverter:close:*: {
  /timercurrency off
}
alias currency {
  if ($sock(currency)) .sockclose $v1
  sockopen currency finance.yahoo.com 80
  set %Currency amt= $+ $1 $+ &from= $+ $2 $+ &to= $+ $3 $+ &submit=Convert
}
on *:SOCKOPEN:currency: {
  sockwrite -n $sockname GET /currency/convert? $+ %Currency HTTP/1.1   
  sockwrite -n $sockname Host: finance.yahoo.com
  sockwrite -n $sockname User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8)
  sockwrite -n $sockname $crlf
}
on *:SOCKREAD:currency: {
  var %x
  sockread %x
  if ($regex(%x,/<td class="w+"><b>(d+)</b></td><td class="w+">(.*?)</td><td class="w+">(d+(?:.d+)?)</td>/i)) {
    did -av CurrencyConverter 14 $ $+ $regml(1)
    var %Amount $regml(1)
  }
  if ($regex(%x,/<td class="w+">(d+(?:.d+)?)</td>/ig)) {
    did -av CurrencyConverter 15 $calc($regml(3) * %Amount)
    did -av CurrencyConverter 16 $regml(3) 
  }
  unset %Currency
} 

Comments

Sign in to comment.
christina2011   -  Jul 07, 2010

The above statement is seen to be contradictory. The situation is very critical and need an experience complainer to resolve it.

Currency Trading Center


Christina

 Respond  
vaseline28   -  Jul 25, 2009

Yeah, that's because yahoo have changed their currency converter online to a new AJAX system and i haven't yet worked out which page I need to grab the data from.

 Respond  
Toby3   -  Jul 19, 2009

I dont seem to be able to get this working, as mentioned, it converts for a lonnnnnng time. Shut it down, try again, same again.

 Respond  
Vlada_bgd   -  Jun 23, 2008

RSD a.k.a. Serbian Dinar :)
Atm 1€=78.2RSD

 Respond  
vaseline28   -  Jun 21, 2008

Thank you, if anyone knows of any currencies not included, please let me know!

 Respond  
greenlanter420   -  Jun 21, 2008

looks really good well done

 Respond  
vaseline28   -  Jun 21, 2008

Deleted all comments for the revised version of the script, things which have changed:

No Favorites - seemed to be annoying than useful
Timers are off - There are no timers anymore
Compact - Script is much more compact

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.