Skip to content

Instantly share code, notes, and snippets.

Created November 16, 2015 19:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/b6ca367ced12b4136744 to your computer and use it in GitHub Desktop.
Save anonymous/b6ca367ced12b4136744 to your computer and use it in GitHub Desktop.
döviz.tcl
namespace eval doviz {
package require http
# komut
variable kurkmt "döviz"
# pref
variable kurpref "."
# kullanan flaglar
variable kurflag "-|-"
# .chanset #kanal +doviz
setudef flag doviz
variable kurtr
array set kurtr {
"amerikan dolar" "usd" "İsviçre Frank" "chf" "İsrail Yeni Şekel" "ILS" "İsveç Kron" "sek"
"Türk liras" "try" "Şili Pesos" "clp" "Hindistan Rupis" "INR" "Singapur Dolar" "sgd"
"euro" "eur" "Kıbrıs Liras" "cyp" "Irak Dinar" "IQD" "Tolar" "SIT" "Dong" "vnd"
"afgan" "afn" "Çek Korunas" "czk" "İran Riyal" "IRR" "Slovak Korunas" "skk"
"lek" "all" "Danimarka Kron" "dkk" "İzlanda Kronas" "ISK" "Suriye Liras" "syp"
"arjantin pezos" "ars" "Cezayir Dinar" "dzd" "Ürdün Dinar" "jod" "Baht" "thb"
"avustralya dolar" "aud" "Estonya Kron" "eek" "Japon Yen" "jpy" "Tayvan Dolar" "twd"
"Azerbaycan Manat" "azn" "avro" "eur" "Kuveyt Dinar" "kwd" "Ukrayna Grivnas" "uah"
"Konvertible Mark" "bam" "Mısır Liras" "egp" "Lübnan Liras" "lbp" "Özbekistan Som" "uzs"
"Bulgaristan Lev" "bgn" "İngiliz Sterlin" "gbp" "Litvanya Litas" "ltl" "türk lira" "try"
"Bahreyn Dinar" "bhd" "sterlin" "gbp" "Libya Dinar" "lyd" "Turkmenistan Manat" "tmm"
"Brazilya Real" "brl" "Hırvatistan Kunas" "hrk" "Makedon Dinar" "mkd"
"Belarus Rubles" "byr" "Macar Forint" "huf" "Moldovya Leus" "mdl" "Yemen Riyal" "yer"
"Kanada Dolar" "cad" "Rupiah" "IDR" "Meksika Pesos" "mxn" "Tunus Dinar" "tnd"
"Norveç Kron" "nok" "Pakistan Rupis" "pkr" "Leh Zlotis" "pln" "Uruguay Pesos" "uyu"
"Romanya Ley" "ron" "Sırbistan Dinar" "rsd" "Rus Rubles" "rub" "Güney Afrika Rand" "zar"
}
bind pub $kurflag $kurpref$kurkmt [namespace current]::kur_pub
proc kur_pub {nick uhost hand chan text} {
if {![channel get $chan doviz]} { return 0 }
set text [regsub -line -nocase {^(.*)[ıiüu]$} $text \\1]
variable kurtr
foreach {orj tur} [array get kurtr] {
set text [string map -nocase [list $orj $tur] [join $text]]
}
set kac [lindex [split $text] 0]
set from [lindex [split $text] 1]
set to [lindex [split $text] 2]
if {[string is space -strict $kac] || [regexp {^[a-zA-ZğüışçöÖÜĞİŞÇ_-]+$} $kac]} {
#::doviz::putmsg $chan "\002$::lastbind <100 try usd>\002 converts currency rates: use ISO-4217 currency-codes like EUR and USD (http://en.wikipedia.org/wiki/ISO_4217)"
::doviz::putmsg $chan "Kullanımı: \002$::lastbind <100 try usd>\002 gibi olmalı,döviz kurları için belirlenmiş uluslararası \
ISO-4217 standartlarındaki ( https://tr.wikipedia.org/wiki/ISO_4217 ),Döviz kodlarını kullanmalısınız. EUR, USD, TRY gibi."
return 0
}
if {[string is digit -strict $from] || [string is digit -strict $to] || $from eq "" || $to eq ""} {
#::doviz::putmsg $chan "usage: \002$::lastbind <100 try usd>\002 converts currency rates: use ISO-4217 currency-codes like EUR and USD (http://en.wikipedia.org/wiki/ISO_4217)"
::doviz::putmsg $chan "Kullanımı: \002$::lastbind <100 try usd>\002 gibi olmalı,döviz kurları için belirlenmiş uluslararası \
ISO-4217 standartlarındaki ( https://tr.wikipedia.org/wiki/ISO_4217 ),Döviz kodlarını kullanmalısınız. EUR, USD, TRY gibi."
return 0
}
if {[regexp {^[0-9]+\..*$} $kac] && ![string is digit -strict $kac]} {
set kac [format %.0f $kac]
#::doviz::putmsg $chan "I am rounding your number to \00304$kac\003"
::doviz::putmsg $chan "\00304$kac\003 olarak kullanıldı."
}
if {[regexp {^[0-9]+,.*$} $kac]} {
set kac [regsub -line {^(.*),.*$} $kac \\1]
#::doviz::putmsg $chan "I took \00304$kac\003 for your query."
::doviz::putmsg $chan "\00304$kac\003 olarak arandı."
}
set dtex [doviz::get_dis http://www.xe.com/currencyconverter/convert/?Amount=${kac}&From=${from}&To=${to}]
regsub -all -- {(?:\n|\t|\v|\r|\x01|&nbsp;)} $dtex " " dtex
set i 0
while {[regexp -line {leftCol">(.*?)<.+Cde">(.*?)<.+rightCol">(.*?)<.+Cde">(.*?)<.+leftCol">(.*?)<.+rightCol">(.*?)<.+php'>(.*?)<} $dtex -> a b c d e f g]} {
regsub -line {leftCol">(.*?)<.+Cde">(.*?)<.+rightCol">(.*?)<.+Cde">(.*?)<.+leftCol">(.*?)<.+rightCol">(.*?)<.+php'>(.*?)<} $dtex "" dtex
if {![info exists a] || ![info exists b] || ![info exists c] || ![info exists d] || ![info exists e] || ![info exists f] || ![info exists g]} {
#::doviz::putmsg $chan "Query has been failed. converts currency rates: use ISO-4217 currency-codes like EUR and USD (https://en.wikipedia.org/wiki/ISO_4217)"
::doviz::putmsg $chan "Sorgu başarısız oldu.döviz kurları için belirlenmiş uluslararası \
ISO-4217 standartlarındaki ( https://tr.wikipedia.org/wiki/ISO_4217 ),Döviz kodlarını kullanmalısınız. EUR, USD, TRY gibi"
}
if {$a eq "0.00" || $c eq "0.00" || $b eq "---" || $d eq "---"} {
#::doviz::putmsg $chan "use ISO-4217 currency-codes like EUR and USD -> https://en.wikipedia.org/wiki/ISO_4217"
#::doviz::putmsg $chan "List of circulating currencies -> https://en.wikipedia.org/wiki/List_of_circulating_currencies"
::doviz::putmsg $chan "ISO-4217 standartlarındaki ( https://tr.wikipedia.org/wiki/ISO_4217 ),Para birim kodlarını kullanmalısınız. EUR, USD, TRY gibi"
return 0
}
regsub -all -- {^([^\s]+)([^=]+)=(.+?)\s(.*?)$} $e "\00303\\1\003 \002\\2\002 \00312=\003 \00303\\3\003 \002\\4\002" e
regsub -all -- {^([^\s]+)([^=]+)=(.+?)\s(.*?)$} $f "\00303\\1\003 \002\\2\002 \00312=\003 \00303\\3\003 \002\\4\002" f
#regsub -all -- {^([^\d]+)(.*?)$} $g \00312\\1\003\00314\\2\003 g
regexp {^([^\d]+)(.*?)$} $g - mar zmn
#set date [clock format [clock scan $zmn] -format "%d %B %Y %A %H:%M:%S" -timezone :Europe/Istanbul -locale en_US]
set date [clock format [clock scan $zmn] -format "%d %B %Y %A %H:%M:%S" -timezone :Europe/Istanbul -locale tr_TR]
set mar [string map -nocase [list "Mid-market rates:" "Serbest-Pazar Kuru:"] $mar]
::doviz::putmsg $chan "\00304$a\003 \002$b\002 \00312=\003 \00304$c\003 \002$d\002 \00310|\003 $e \00310|\003 $f \00310|\003 \00312$mar\003\00314$date\003"
incr i
}
return 0
}
proc putmsg {x y} {
putserv "privmsg $x :$y"
}
proc get_dis {link} {
::http::config -useragent "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5" -urlencoding "utf-8"
catch { set tok [::http::geturl $link -timeout [expr {12*1000}]] } err
if {[string match -nocase "*couldn't open socket*" $err]} {
putlog "[strftime "%H:%M:%S"] -> $err"
} elseif {![string equal -nocase [::http::status $tok] "ok"] || ![string equal [::http::ncode $tok] 200]} {
putlog "[strftime "%H:%M:%S"] -> [::http::code $tok] - [::http::status $tok]"
} else {
return [::http::data $tok]
}
::http::cleanup $tok
}
putlog "ok..."
}
# EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment