Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;Stock Quote Script (Financial Stock Data) v2.0
- ;Made by nick1
- ;View online and report bugs at http://www.hawkee.com/snippet/9578
- ;Last edit November 04, 2013
- ;DISCLAIMER: Data and information provided may be delayed.
- ;Data and information is provided for informational purposes only, and is not intended for trading purposes. - Currency in USD
- ;For your convenience, the URL I am using to get this data is
- ;http://developer.yahoo.com/yql/console/#h= the query below
- ;Column options are listed here http://www.gummy-stuff.org/Yahoo-data.htm
- alias -l stockVersion {
- return v2.0
- }
- alias stock {
- var %ticks $ticks
- tokenize 32 $strip($1-)
- if ($1) {
- var %ticker $upper($1)
- set $+(%,stock.,%ticks,.msgtype) echo -a
- set $+(%,stock.,%ticks,.ticker) %ticker
- if (!$istok(%stock.shortened,$1,44)) {
- set $+(%,stock.,%ticks,.shorten) %ticker
- sockopen $+(stocklink.,%ticks) ou.gs 80
- }
- sockopen $+(stock.,%ticks) query.yahooapis.com 80
- }
- elseif ($1 == $null) {
- echo -act info 4Incorrect Syntax - Use10 /stock <ticker symbol>
- }
- }
- on $*:text:/^[!@](stock|stocks|stockquote|price|q|quote)(\s|$)/Si:#:{
- if ($($+(%,botflood.,$nick),2)) {
- 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 }
- elseif ($($+(%,botflood.,$nick),2) >= 200) { msg $chan $+($nick,$chr(44)) Please Do Not Abuse The Bot. | inc -z $+(%,botflood.,$nick) 20 | halt }
- else { inc -z $+(%,botflood.,$nick) 25 }
- }
- else { inc -z $+(%,botflood.,$nick) 25 }
- var %ticks $ticks
- tokenize 32 $strip($1-)
- if ($2) {
- set $+(%,stock.,%ticks,.msgtype) $iif($chan,$iif($left($1,1) == @,msg $chan,notice $nick),msg $nick)
- set $+(%,stock.,%ticks,.ticker) $2
- if (!$istok(%stock.shortened,$2,44)) {
- set $+(%,stock.,%ticks,.shorten) $upper($2)
- sockopen $+(stocklink.,%ticks) ou.gs 80
- }
- sockopen $+(stock.,%ticks) query.yahooapis.com 80
- }
- elseif ($2 == $null) {
- notice $nick 4Incorrect Syntax - Use10 $1 <ticker symbol>
- }
- }
- on *:sockopen:stock.*: {
- var %sw sockwrite -nt $sockname
- var %enc1 $(select%20*%20from%20csv%20where%20url%3D'http%3A%2F%2Fdownload.finance.yahoo.com%2Fd%2Fquotes.csv%3Fs%3D,0)
- var %enc2 $(%26f%3D,0)
- var %enc3 $(%26e%3D.csv'%20and%20columns%3D',0)
- var %options e1snd1t1l1c6p2j1c8r
- var %columns Error,symbol,name,date,time,price,change,percentChange,MarketCap,AfterChange,PERatio
- var %columns $replace(%columns,$chr(44),$(%2C,0))
- %sw GET $+(/v1/public/yql?q=,%enc1,$($+(%,$sockname,.ticker),2),%enc2,%options,%enc3,%columns,'&diagnostics=true) HTTP/1.1
- %sw Host: query.yahooapis.com
- %sw $crlf
- }
- alias -l months {
- return January,February,March,April,May,June,July,August,September,October,November,December
- }
- r
- on *:SOCKREAD:stock.*: {
- if ($sockerr) { echo -a SOCKET ERROR: $sockerr | halt }
- sockread &t
- var %pos $bfind(&t,1,<row>)
- var %pos2 $bfind(&t,%pos,</row>)
- if (%pos != 0) {
- var %ticks $remove($sockname,stock.)
- set $+(%,stock.,%ticks,.xml) $bvar(&t,$+($calc(%pos + 5),-,$calc(%pos2 - 1))).text
- if ($stockparser(%ticks,error) != N/A) {
- $($+(%,stock.,%ticks,.msgtype),2) $+(7,$($+(%,stock.,%ticks,.ticker),2),) 04This symbol could not be found. $&
- Please try again or search for it at12 $+(http://ou.gs/stock_,$($+(%,stock.,%ticks,.ticker),2))
- unset $+(%,stock.,$remove($sockname,stock.),*)
- sockclose $sockname
- }
- else {
- var %colorcode $iif($left($stockparser(%ticks,change),1) == +,03,04)
- var %month $gettok($months,$gettok($stockparser(%ticks,date),1,47),44)
- var %ascdate $replace($+(%month,/,$gettok($stockparser(%ticks,date),2-,47)) $stockparser(%ticks,time),/,$chr(32))
- var %timestamp $duration($calc($ctime - $ctime(%ascdate)),2) ago
- $($+(%,stock.,%ticks,.msgtype),2) $+(7,$stockparser(%ticks,symbol)) $&
- $+(,$openparens,07,$replace($stockparser(%ticks,name),&,&,','),$closeparens) $&
- 10Last:04 $stockparser(%ticks,price) $+(,$openparens,04,%timestamp,$closeparens) $&
- $+(10Change:,%colorcode) $stockparser(%ticks,change) $&
- $+($openparens,%colorcode,$stockparser(%ticks,percentchange),$closeparens) $&
- %afterstring $&
- 10Mkt Cap:3 $stockparser(%ticks,marketcap) $&
- 10Link:12 $+(http://ou.gs/stock_,$upper($($+(%,stock.,%ticks,.ticker),2)))
- unset $+(%,stock.,$remove($sockname,stock.),*)
- sockclose $sockname
- }
- }
- }
- on *:sockopen:stocklink.*: {
- var %symbol $($+(%,stock.,$remove($sockname,stocklink.),.shorten),2)
- sockwrite -nt $sockname GET $+(/index.php?url=http://www.google.com/finance?q=,%symbol,&alias=,stock_,%symbol) HTTP/1.1
- set %stock.shortened $addtok(%stock.shortened,%symbol,44)
- sockwrite -nt $sockname Host: ou.gs
- sockwrite -nt $sockname $crlf
- }
- alias -l openparens { return $+(01,$chr(40)) }
- alias -l closeparens { return $+(01,$chr(41)) }
- alias -l stockParser {
- ;Syntax $stockparser(ticks,DATA_TYPE)
- ;Options for DATA_TYPE are {error,symbol,name,date,time,price,change,percentChange,MarketCap,PERatio}
- var %xml $($+(%,stock.,$1,.xml),2)
- return $remove($wildtok(%xml,* $+ $2 $+ *,1,60),>,$2)
- }
- on *:start: .timerStockUpdate 1 60 StockUpdate
- alias stockUpdate {
- echo -atc info 12[04Stock Script12] Checking for updates...
- sockopen stockUpdate www.hawkee.com 80
- }
- on *:sockopen:stockUpdate: {
- sockwrite -nt $sockname GET /snippet/9578/ HTTP/1.1
- sockwrite -nt $sockname Host: www.hawkee.com
- sockwrite -nt $sockname $crlf
- }
- on *:SOCKREAD:stockUpdate: {
- if ($sockerr) { echo -a SOCKET ERROR: $sockerr $sockname $asctime | halt }
- sockread %sockreader
- if (*<title>* iswm %sockreader) {
- tokenize 32 %sockreader
- 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/)
- unset %sockreader
- sockclose $sockname
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement