Advertisement
illpastethat

Stock Quote Script (Financial Data) v2.0

Nov 4th, 2013
464
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 6.03 KB | None | 0 0
  1. ;Stock Quote Script (Financial Stock Data) v2.0
  2. ;Made by nick1
  3. ;View online and report bugs at http://www.hawkee.com/snippet/9578
  4. ;Last edit November 04, 2013
  5.  
  6. ;DISCLAIMER: Data and information provided may be delayed.
  7. ;Data and information is provided for informational purposes only, and is not intended for trading purposes. - Currency in USD
  8. ;For your convenience, the URL I am using to get this data is
  9. ;http://developer.yahoo.com/yql/console/#h= the query below
  10. ;Column options are listed here http://www.gummy-stuff.org/Yahoo-data.htm
  11.  
  12. alias -l stockVersion {
  13.   return v2.0
  14. }
  15. alias stock {
  16.   var %ticks $ticks
  17.   tokenize 32 $strip($1-)
  18.   if ($1) {
  19.     var %ticker $upper($1)
  20.     set $+(%,stock.,%ticks,.msgtype) echo -a
  21.     set $+(%,stock.,%ticks,.ticker) %ticker
  22.     if (!$istok(%stock.shortened,$1,44)) {
  23.       set $+(%,stock.,%ticks,.shorten) %ticker
  24.       sockopen $+(stocklink.,%ticks) ou.gs 80
  25.     }
  26.     sockopen $+(stock.,%ticks) query.yahooapis.com 80
  27.   }
  28.   elseif ($1 == $null) {
  29.     echo -act info 4Incorrect Syntax - Use10 /stock <ticker symbol>
  30.   }
  31. }
  32.  
  33. on $*:text:/^[!@](stock|stocks|stockquote|price|q|quote)(\s|$)/Si:#:{
  34.   if ($($+(%,botflood.,$nick),2)) {
  35.     if ($($+(%,botflood.,$nick),2) >= 300) { ignore -u60 $address($nick,0) | msg $chan $+($nick,$chr(44)) You Have Been Put On Ignore For 60secs For Abusing The Bot. | halt }
  36.     elseif ($($+(%,botflood.,$nick),2) >= 200) { msg $chan $+($nick,$chr(44)) Please Do Not Abuse The Bot. | inc -z $+(%,botflood.,$nick) 20 | halt }
  37.     else { inc -z $+(%,botflood.,$nick) 25 }
  38.   }
  39.   else { inc -z $+(%,botflood.,$nick) 25 }
  40.   var %ticks $ticks
  41.   tokenize 32 $strip($1-)
  42.   if ($2) {
  43.     set $+(%,stock.,%ticks,.msgtype) $iif($chan,$iif($left($1,1) == @,msg $chan,notice $nick),msg $nick)
  44.     set $+(%,stock.,%ticks,.ticker) $2
  45.     if (!$istok(%stock.shortened,$2,44)) {
  46.       set $+(%,stock.,%ticks,.shorten) $upper($2)
  47.       sockopen $+(stocklink.,%ticks) ou.gs 80
  48.     }
  49.     sockopen $+(stock.,%ticks) query.yahooapis.com 80
  50.   }
  51.   elseif ($2 == $null) {
  52.     notice $nick 4Incorrect Syntax - Use10 $1 <ticker symbol>
  53.   }
  54. }
  55.  
  56. on *:sockopen:stock.*: {  
  57.   var %sw sockwrite -nt $sockname
  58.   var %enc1 $(select%20*%20from%20csv%20where%20url%3D'http%3A%2F%2Fdownload.finance.yahoo.com%2Fd%2Fquotes.csv%3Fs%3D,0)
  59.   var %enc2 $(%26f%3D,0)
  60.   var %enc3 $(%26e%3D.csv'%20and%20columns%3D',0)
  61.   var %options e1snd1t1l1c6p2j1c8r
  62.   var %columns Error,symbol,name,date,time,price,change,percentChange,MarketCap,AfterChange,PERatio
  63.   var %columns $replace(%columns,$chr(44),$(%2C,0))
  64.   %sw GET $+(/v1/public/yql?q=,%enc1,$($+(%,$sockname,.ticker),2),%enc2,%options,%enc3,%columns,'&diagnostics=true) HTTP/1.1
  65.   %sw Host: query.yahooapis.com
  66.   %sw $crlf
  67. }
  68. alias -l months {
  69.   return January,February,March,April,May,June,July,August,September,October,November,December
  70. }
  71. r
  72. on *:SOCKREAD:stock.*: {
  73.   if ($sockerr) { echo -a SOCKET ERROR: $sockerr | halt }
  74.   sockread &t
  75.   var %pos $bfind(&t,1,<row>)
  76.   var %pos2 $bfind(&t,%pos,</row>)
  77.   if (%pos != 0) {
  78.     var %ticks $remove($sockname,stock.)
  79.     set $+(%,stock.,%ticks,.xml) $bvar(&t,$+($calc(%pos + 5),-,$calc(%pos2 - 1))).text
  80.     if ($stockparser(%ticks,error) != N/A) {
  81.       $($+(%,stock.,%ticks,.msgtype),2) $+(7,$($+(%,stock.,%ticks,.ticker),2),) 04This symbol could not be found. $&
  82.         Please try again or search for it at12 $+(http://ou.gs/stock_,$($+(%,stock.,%ticks,.ticker),2))
  83.       unset $+(%,stock.,$remove($sockname,stock.),*)
  84.       sockclose $sockname
  85.     }  
  86.     else {
  87.       var %colorcode $iif($left($stockparser(%ticks,change),1) == +,03,04)
  88.       var %month $gettok($months,$gettok($stockparser(%ticks,date),1,47),44)
  89.       var %ascdate $replace($+(%month,/,$gettok($stockparser(%ticks,date),2-,47)) $stockparser(%ticks,time),/,$chr(32))
  90.       var %timestamp $duration($calc($ctime - $ctime(%ascdate)),2) ago
  91.       $($+(%,stock.,%ticks,.msgtype),2) $+(7,$stockparser(%ticks,symbol)) $&
  92.         $+(,$openparens,07,$replace($stockparser(%ticks,name),&amp;,&,&#39;,'),$closeparens) $&
  93.         10Last:04 $stockparser(%ticks,price) $+(,$openparens,04,%timestamp,$closeparens) $&
  94.         $+(10Change:,%colorcode) $stockparser(%ticks,change) $&
  95.         $+($openparens,%colorcode,$stockparser(%ticks,percentchange),$closeparens) $&
  96.         %afterstring $&
  97.         10Mkt Cap:3 $stockparser(%ticks,marketcap) $&
  98.         10Link:12 $+(http://ou.gs/stock_,$upper($($+(%,stock.,%ticks,.ticker),2)))
  99.       unset $+(%,stock.,$remove($sockname,stock.),*)
  100.       sockclose $sockname
  101.     }
  102.   }
  103. }
  104.  
  105. on *:sockopen:stocklink.*: {
  106.   var %symbol $($+(%,stock.,$remove($sockname,stocklink.),.shorten),2)
  107.   sockwrite -nt $sockname GET $+(/index.php?url=http://www.google.com/finance?q=,%symbol,&alias=,stock_,%symbol) HTTP/1.1
  108.   set %stock.shortened $addtok(%stock.shortened,%symbol,44)
  109.   sockwrite -nt $sockname Host: ou.gs
  110.   sockwrite -nt $sockname $crlf
  111. }
  112.  
  113. alias -l openparens { return $+(01,$chr(40)) }
  114.  
  115. alias -l closeparens { return $+(01,$chr(41)) }
  116.  
  117. alias -l stockParser {
  118.   ;Syntax $stockparser(ticks,DATA_TYPE)
  119.   ;Options for DATA_TYPE are {error,symbol,name,date,time,price,change,percentChange,MarketCap,PERatio}
  120.   var %xml $($+(%,stock.,$1,.xml),2)
  121.   return $remove($wildtok(%xml,* $+ $2 $+ *,1,60),>,$2)
  122. }
  123.  
  124. on *:start: .timerStockUpdate 1 60 StockUpdate
  125.  
  126. alias stockUpdate {
  127.   echo -atc info 12[04Stock Script12] Checking for updates...
  128.   sockopen stockUpdate www.hawkee.com 80
  129. }
  130.  
  131. on *:sockopen:stockUpdate: {  
  132.   sockwrite -nt $sockname GET /snippet/9578/ HTTP/1.1
  133.   sockwrite -nt $sockname Host: www.hawkee.com
  134.   sockwrite -nt $sockname $crlf
  135. }
  136.  
  137. on *:SOCKREAD:stockUpdate: {
  138.   if ($sockerr) { echo -a SOCKET ERROR: $sockerr $sockname $asctime | halt }
  139.   sockread %sockreader
  140.   if (*<title>* iswm %sockreader) {
  141.     tokenize 32 %sockreader
  142.     echo -atc info 12[04Stock Script12] Current: $StockVersion Latest: $7 Status: $iif($StockVersion == $7,Up to date,Please update at www.hawkee.com/snippet/9578/)
  143.     unset %sockreader
  144.     sockclose $sockname
  145.   }
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement