This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

stock exchange script for Australia

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
r
rainman
Voice
Posts: 11
Joined: Wed Apr 21, 2021 10:33 am

stock exchange script for Australia

Post by rainman »

Gday all, how's everyone doing?

I'm looking for a simple stock exchange script for Australia if someone can help make a simple one for me please

like say !asx Code-here and it shows some basic info

eg: !asx CBA etc

such as Current Price, Last Price, etc

https://www.marketindex.com.au/asx/cba <--example if you go down to snapshot if that info can be displayed in channel if possible please

Thanks
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

There is a pile of info in the "Snapshot", way too much to present in a channel post.

Maybe pick a few key entries to present?
Better yet, type out an example of what a channel post would look like:)
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
r
rainman
Voice
Posts: 11
Joined: Wed Apr 21, 2021 10:33 am

Post by rainman »

SpiKe^^ wrote:There is a pile of info in the "Snapshot", way too much to present in a channel post.

Maybe pick a few key entries to present?
Better yet, type out an example of what a channel post would look like:)
Oh right sorry :)

How about just the following

Open Price:
Last Price:
Bid / Ask:
Day Range:
Prev Close:
Last Trade:
Market Cap:
Change:

Is that more reasonable :)
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

Looking over the html source file much closer, shows they hide their quote data very well.
<td>Last (Price)</td>
<td class="text-right">
<span data-quoteapi="price"></span>
</td>
</tr>
<tr>
<td>Change</td>
<td class="text-right" data-quoteapi="changeSignCSS">
<span data-quoteapi="change showNegativeSign=false">0.00</span>
(<span data-quoteapi="pctChange showNegativeSign=true">0.00</span>)
</td>
</tr>
The headers are there but none of the data.
I do not know how to get any quote data from this site.

Maybe you know a usable source site for this stock quote data, or a way to force any data from this site?
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
r
rainman
Voice
Posts: 11
Joined: Wed Apr 21, 2021 10:33 am

Post by rainman »

SpiKe^^ wrote:Looking over the html source file much closer, shows they hide their quote data very well.
<td>Last (Price)</td>
<td class="text-right">
<span data-quoteapi="price"></span>
</td>
</tr>
<tr>
<td>Change</td>
<td class="text-right" data-quoteapi="changeSignCSS">
<span data-quoteapi="change showNegativeSign=false">0.00</span>
(<span data-quoteapi="pctChange showNegativeSign=true">0.00</span>)
</td>
</tr>
The headers are there but none of the data.
I do not know how to get any quote data from this site.

Maybe you know a usable source site for this stock quote data, or a way to force any data from this site?
Hello Spike,

How about directly from the source

https://www2.asx.com.au/markets/company/cba

Is that more usable ?

https://www2.asx.com.au/

If that's a bust only other one i found would be

https://au.finance.yahoo.com/

https://au.finance.yahoo.com/quote/CBA. ... c=fin-srch

I really do appreciate your efforts into this, thank you so much
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

maybe au.finance.yahoo.com/quote/

Post by SpiKe^^ »

Looks to me like the source code from here is user friendly:)
https://au.finance.yahoo.com/quote/CBA.AX?p=CBA.AX

With that being all the data available, what fields would you include in the channel post?
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
r
rainman
Voice
Posts: 11
Joined: Wed Apr 21, 2021 10:33 am

Re: maybe au.finance.yahoo.com/quote/

Post by rainman »

SpiKe^^ wrote:Looks to me like the source code from here is user friendly:)
https://au.finance.yahoo.com/quote/CBA.AX?p=CBA.AX

With that being all the data available, what fields would you include in the channel post?
Market Cap:
Open:
Prev Close:
Bid:
Ask:
Day's Range:

Just those please spike :)
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

ausStocks.tcl version 0.1 24Jan2023

Post by SpiKe^^ »

Tested some, give it a shot:)

Code: Select all

## ausStocks.tcl version 0.1  24Jan2023 ##

# public command syntax:  !asx <symbol>
# example:  !asx csl

package require http
package require tls

http::register https 443 {tls::socket -autoservername true}

bind pub - !asx asx:bindpub

proc asx:bindpub {nk uh hn ch tx} {
  set symbol [string toupper [lindex [split [string trim $tx]] 0]]

  if {[string length $symbol] < 3 || [string length $symbol] > 6} { return 0 }

  set address "https://au.finance.yahoo.com/quote/${symbol}.AX?p=${symbol}.AX"
  set token [::http::geturl $address -timeout 7500]
  set html [::http::data $token]  ;   ::http::cleanup $token
  set html [join [lrange [split $html "\n"] 4 6] {}]

  set ils {company xinfo lastprice change percent notice prevclose open bid ask}
  foreach vname [lappend ils dayrange 52weeks volume avgvolume marketcap] {
    set $vname "N/A"
  }

  set qmap [list %k $nk %h $ch]


  regexp {<h1 class=\"D\(ib\) Fz\(18px\)\">(.*?)</h1>(.*)$} $html - company html
  regexp {^</div>[^>]+><span>(.*?)</span>(.*)$} $html - xinfo html
  regexp {regularMarketPrice[^>]+>(.*?)</fin-str(.*)$} $html - lastprice html
  regexp {regularMarketChange[^>]+><[^>]+>(.*?)</span(.*)$} $html - change html
  regexp {MarketChangePercent[^>]+><[^>]+>(.*?)</span(.*)$} $html - percent html
  regexp {quote-market-notice[^>]+><span>(.*?)</span>(.*)$} $html - notice html

  if {[matchstr "-*" $change]} {
    set change "\00304$change\003"  ;  set percent "\00304$percent\003"
  } elseif {[matchstr "+*" $change]} {
    set change "\00303$change\003"  ;  set percent "\00303$percent\003"
  }
  lappend qmap %y $company %x $xinfo %l $lastprice %c $change %p $percent

  regexp {PREV_CLOSE-value\">(.*?)</td></tr>(.*)$} $html - prevclose html
  regexp {\"OPEN-value\">(.*?)</td></tr>(.*)$} $html - open html
  regexp {\"BID-value\">(.*?)</td></tr>(.*)$} $html - bid html
  regexp {\"ASK-value\">(.*?)</td></tr>(.*)$} $html - ask html

  lappend qmap %n $notice %r $prevclose %o $open %b $bid %a $ask

  regexp {DAYS_RANGE-value\">(.*?)</td></tr>(.*)$} $html - dayrange html
  regexp {FIFTY_TWO_WK_RANGE-value\">(.*?)</td>(.*)$} $html - 52weeks html
  regexp {regularMarketVolume[^>]+>(.*?)</fin-streamer(.*)$} $html - volume html
  regexp {AVERAGE_VOLUME_3MONTH-value\">(.*?)</td>(.*)$} $html - avgvolume html
  regexp {\"MARKET_CAP-value\">(.*?)</td></tr>(.*)$} $html - marketcap html

  lappend qmap %d $dayrange %w $52weeks %v $volume %g $avgvolume %m $marketcap


  set hmap [list "'" "'" "&" "&" """ "\""]

  #### e f i j q s t u z ####

  #  %y  = company name      ex.  Apollo Minerals Limited (AON.AX)
  #  %x  = asx info  ??      ex.  ASX - ASX Delayed price. Currency in AUD
  #  %l  = last price        ex.  108.66
  #  %c  = price change      ex.  -0.08
  #  %p  = change percent    ex.  (-0.07%)
  #  %n  = market notice     ex.  As of  10:17AM AEDT. Market open.

  #  %r  = previous close    ex.  108.74
  #  %o  = open              ex.  108.74
  #  %b  = bid               ex.  108.66 x 36400
  #  %a  = ask               ex.  108.69 x 7100
  #  %d  = day's range       ex.  108.38 - 109.15
  #  %w  = 52-week range     ex.  86.98 - 109.20
  #  %v  = volume            ex.  3,747,153
  #  %g  = avg. volume       ex.  2,190,023
  #  %m  = market cap        ex.  183.463B

  #  %k  = nick              ex.  SpiKe^^
  #  %h  = channel           ex.  #pc-mirc-help


  set say [list "\00306<ASX>\003 %y  \002%l AUD\002  Change: \002%c %p\002  %n"]

  set s "Previous close: \002%r\002  Open: \002%o\002  Bid: \002%b\002  "
  append s "Ask: \002%a\002  Day's range: \002%d\002  Market cap: \002%m\002"
  lappend say $s


  foreach ln $say {
    set ln [string map $qmap $ln]  ;   set ln [string map $hmap $ln]
    puthelp "PRIVMSG $ch :$ln"
  }
  return 0
}

putlog "Loaded ausStocks.tcl version 0.1  24Jan2023"


SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
User avatar
CrazyCat
Revered One
Posts: 1303
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

short advice: don't register globaly https but register it when needed (before query) and unregister when cleaning the connection.
If another script globaly unregister https, yours will not work anymore.

Keep in mind that your script is not the only one running on the eggdrop.
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

thommey said put it there, and stop using ::http::unregister https:)
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
r
rainman
Voice
Posts: 11
Joined: Wed Apr 21, 2021 10:33 am

Re: ausStocks.tcl version 0.1 24Jan2023

Post by rainman »

Thank you so much spike, you are the man sir :D

i'll def give it a better whirl tomorrow when markets open up xD

So far it's working as expected :D
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

ausStocks.tcl version 0.2 27Jan2023

Post by SpiKe^^ »

Version 0.2 adds some bare minimum sanity/error checks w/ reporting:
1) restricts user input to 3 - 6 alphanumeric characters.
2) adds some error checking on the http connection & get.
3) put the entire script code in the namespace ausStocks.

Code: Select all

## ausStocks.tcl version 0.2  27Jan2023 ##

## Version 0.2 adds some bare minimum sanity checks w/ reporting:
# 1) restricts user input to 3 - 6 alphanumeric characters.
# 2) adds some error checking on the http connection & get.
# 3) put the entire script code in the namespace ausStocks.


# public command syntax:  !asx <symbol>
# example:  !asx csl

##########################################
namespace eval ausStocks {

package require http
package require tls

::http::register https 443 {::tls::socket -autoservername true}
#::http::register https 443 [list ::tls::socket -servername au.finance.yahoo.com]

bind pub - !asx [namespace current]::asx:bindpub

proc asx:bindpub {nk uh hn ch tx} {
  set sym [string toupper [lindex [split [string trim $tx]] 0]]

  if {[string length $sym] ni {3 4 5 6} || [regexp {[^0-9A-Z]} $sym]} {
    puthelp "PRIVMSG $ch :\00306<ASX>\003 Command syntax:  \002!asx <symbol>\002"
    return 0
  }

  set address "https://au.finance.yahoo.com/quote/${sym}.AX?p=${sym}.AX"
  ::http::config -useragent "Mozilla/5.0 (X11; Linux i686; rv:2.0.1) Gecko/20100101 Firefox/4.0.1"
  #::http::register https 443 {::tls::socket -autoservername true}
  #::http::register https 443 [list ::tls::socket -servername au.finance.yahoo.com]

  # Thanks thommey #
  if {[catch {::http::geturl $address -timeout 7500} tok]} {  error $tok  }
  if {[::http::status $tok] ne "ok"} {
    error "TCP error: [::http::status $tok][::http::cleanup $tok]"
  } elseif {[::http::ncode $tok] != 200} {
    error "HTTP error: [::http::code $tok][::http::cleanup $tok]"
  }

  set html [::http::data $tok]  ;   ::http::cleanup $tok
  set html [join [lrange [split $html "\n"] 4 6] {}]

  set company ""  ;   set xinfo ""  ;   set lastprice ""

  regexp {<h1 class=\"D\(ib\) Fz\(18px\)\">(.*?)</h1>(.*)$} $html - company html
  regexp {^</div>[^>]+><span>(.*?)</span>(.*)$} $html - xinfo html
  regexp {regularMarketPrice[^>]+>(.*?)</fin-str(.*)$} $html - lastprice html

  if {$company eq "" || $xinfo eq "" || $lastprice eq ""} {
    puthelp "PRIVMSG $ch :\00306<ASX>\003 Invalid Company Symbol:  \002$sym\002"
    return 0
  }

  set qmap [list %k $nk %h $ch %y $company %x $xinfo %l $lastprice]


  set ils {change percent notice prevclose open bid ask dayrange}
  foreach vname [lappend ils 52weeks volume avgvolume marketcap] {
    set $vname "N/A"
  }

  regexp {regularMarketChange[^>]+><[^>]+>(.*?)</span(.*)$} $html - change html
  regexp {MarketChangePercent[^>]+><[^>]+>(.*?)</span(.*)$} $html - percent html
  regexp {quote-market-notice[^>]+><span>(.*?)</span>(.*)$} $html - notice html

  if {[matchstr "-*" $change]} {
    set change "\00304$change\003"  ;  set percent "\00304$percent\003"
  } elseif {[matchstr "+*" $change]} {
    set change "\00303$change\003"  ;  set percent "\00303$percent\003"
  }
  lappend qmap %c $change %p $percent %n $notice

  regexp {PREV_CLOSE-value\">(.*?)</td></tr>(.*)$} $html - prevclose html
  regexp {\"OPEN-value\">(.*?)</td></tr>(.*)$} $html - open html
  regexp {\"BID-value\">(.*?)</td></tr>(.*)$} $html - bid html
  regexp {\"ASK-value\">(.*?)</td></tr>(.*)$} $html - ask html
  regexp {DAYS_RANGE-value\">(.*?)</td></tr>(.*)$} $html - dayrange html

  lappend qmap %r $prevclose %o $open %b $bid %a $ask %d $dayrange

  regexp {FIFTY_TWO_WK_RANGE-value\">(.*?)</td>(.*)$} $html - 52weeks html
  regexp {regularMarketVolume[^>]+>(.*?)</fin-streamer(.*)$} $html - volume html
  regexp {AVERAGE_VOLUME_3MONTH-value\">(.*?)</td>(.*)$} $html - avgvolume html
  regexp {\"MARKET_CAP-value\">(.*?)</td></tr>(.*)$} $html - marketcap html

  lappend qmap %w $52weeks %v $volume %g $avgvolume %m $marketcap


  set hmap [list "'" "'" "&" "&" """ "\""]

  #### e f i j q s t u z ####

  #  %y  = company name      ex.  Apollo Minerals Limited (AON.AX)
  #  %x  = asx info  ??      ex.  ASX - ASX Delayed price. Currency in AUD
  #  %l  = last price        ex.  108.66
  #  %c  = price change      ex.  -0.08
  #  %p  = change percent    ex.  (-0.07%)
  #  %n  = market notice     ex.  As of  10:17AM AEDT. Market open.

  #  %r  = previous close    ex.  108.74
  #  %o  = open              ex.  108.74
  #  %b  = bid               ex.  108.66 x 36400
  #  %a  = ask               ex.  108.69 x 7100
  #  %d  = day's range       ex.  108.38 - 109.15
  #  %w  = 52-week range     ex.  86.98 - 109.20
  #  %v  = volume            ex.  3,747,153
  #  %g  = avg. volume       ex.  2,190,023
  #  %m  = market cap        ex.  183.463B

  #  %k  = nick              ex.  GreedyHamster
  #  %h  = channel           ex.  #MarketHub


  set say [list "\00306<ASX>\003 %y  \002%l AUD\002  Change: \002%c %p\002  %n"]

  set s "Previous close: \002%r\002  Open: \002%o\002  Bid: \002%b\002  "
  append s "Ask: \002%a\002  Day's range: \002%d\002  Market cap: \002%m\002"
  lappend say $s


  foreach ln $say {
    set ln [string map $qmap $ln]  ;   set ln [string map $hmap $ln]
    putserv "PRIVMSG $ch :$ln"
  }
  return 0
}

putlog "Loaded ausStocks.tcl version 0.2  27Jan2023"

}  ;## end of:  namespace eval ausStocks ##

SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
r
rainman
Voice
Posts: 11
Joined: Wed Apr 21, 2021 10:33 am

Re: ausStocks.tcl version 0.2 27Jan2023

Post by rainman »

Thanks Spike and LOL @ GreedyHamster :P love it :D
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

ausStocks.tcl version 0.3 10Feb2023

Post by SpiKe^^ »

Version 0.3 tries to make this script a little more user friendly:
1) script will now follow the redirect to the "Similar Symbol Lookup" page.
2) use .chanset #channel +asx to enable this script by channel.
3) and/or use the new channel setting: set asx(chan) "#chan #anotherchan"
4) can now use a company list file to limit invalid query symbols.
5) added public error messages for all ::http::geturl issues.
6) and lots of other small tweeks.

Code: Select all

##########  ausStocks.tcl  ver. 0.3  by SpiKe^^  ########## 10Feb2023 ##########

## Version 0.3  tries to make this script a little more user friendly:
# 1) script will now follow the redirect to the "Similar Symbol Lookup" page.
# 2) use  .chanset #channel +asx  to enable this script by channel.
# 3) and/or use the new channel setting:  set asx(chan) "#chan #anotherchan"
# 4) can now use a company list file to limit invalid query symbols.
# 5) added public error messages for all  ::http::geturl issues.
# 6) and lots of other small tweeks.

################## Version History ##################
## Version 0.2 added some bare minimum sanity checks w/ reporting:
# 1) restricts user input to 3 - 6 alphanumeric characters.
# 2) adds some error checking on the http connection & get.
# 3) put the entire script code in the namespace ::ausStocks::


# public command syntax:  !asx <symbol>
# example:  !asx csl

######################################################
namespace eval ausStocks {   variable asx

package require http
package require tls

setudef flag asx   ;# <= Use  .chanset #chan +asx  to enable this script by channel.


################### begin settings ###################

# set active channel(s) for this script  (or set empty to only use .chanset #ch +asx)
#  or use:  set asx(chan) "*"  to make the script active in all bot channels.
# note:  the channels set here can not be disabled by using  .chanset #ch -asx
set asx(chan) ""

# script logo  (placed before almost every line sent to the channel)
set asx(logo) "\00306\[ASX\]\003 "

# this filename is read at: source scripts/ausStocks.tcl
#  and makes the namespaced variable:  $::ausStocks::asx(companydict).
set asx(companylist_filename) "scripts/ausStocks.companylist.txt"


############ end settings ############ end settings ############

################################################################


::http::register https 443 {::tls::socket -autoservername true}
#::http::register https 443 [list ::tls::socket -servername au.finance.yahoo.com]

bind pub - !asx [namespace current]::bindpub

proc bindpub {nk uh hn ch tx} {   variable asx
  set c [string tolower $ch]
  if {![channel get $ch asx] && ("*" ni $asx(chan)) && ($c ni $asx(chan))} {
    return 0
  }
  set tx [string trimright [string toupper [lindex [split [string trim $tx]] 0]] "."]

  if {[matchstr "*.*" $tx]} {   set tmp [split $tx "."]
    if {[llength $tmp] > 2 || [lindex $tmp 1] ne "AX"} {
      puthelp "PRIVMSG $ch :$asx(logo)Invalid Company Symbol: \002${tx}\002"
      return 0
    }
    set sym [lindex $tmp 0]
  } else {   set sym $tx   }

  if {[string length $sym] ni {2 3 4 5 6} || [regexp {[^0-9A-Z]} $sym]} {
    set say "$asx(logo)Command syntax:  \002!asx <symbol>\002"
    puthelp "PRIVMSG $ch :$say  example:  \002!asx csl\002"
    return 0
  }
  if {$asx(companydict) ne ""} {
    if {![dict exists $asx(companydict) $sym]} {
      set say "$asx(logo)Invalid Company Symbol: \002${sym}\002"
      puthelp "PRIVMSG $ch :$say (symbol not in the $asx(companylist_filename) file.)"
      return 0
    }
  }

  set addr "https://au.finance.yahoo.com"
  set address "${addr}/quote/${sym}.AX?p=${sym}.AX"
  set uagent "Mozilla/5.0 (X11; Linux i686; rv:2.0.1) Gecko/20100101 Firefox/4.0.1"
  set emap [list "\n" " | "]

  foreach try {1 2} {  ::http::config -useragent $uagent
    if {[catch {::http::geturl $address -timeout 7500} tok]} {
      set err "1 ::http::geturl error: [string map $emap $tok]"
    } elseif {[::http::status $tok] ne "ok"} {
      set err "2 TCP error: [::http::status $tok]"
    } else {   set ncode [::http::ncode $tok]
      if {($try == 1 && $ncode ni {200 302}) || ($try == 2 && $ncode != 200)} {
        set err "3 HTTP error: [::http::code $tok]"
      }
    }

    if {$try == 1 && [info exists ncode] && $ncode == 302} {
      upvar #0 $tok state
      if {[dict exists $state(meta) location]} {
        set loc [dict get $state(meta) location]

        if {[matchstr "/lookup*" $loc]} {   set address "${addr}$loc"
          ::http::cleanup $tok  ;   unset tok  ;   unset ncode
          continue
        }
        set err "5 Redirect error: state(meta) 'location' not as expected ( $loc )."
      } else {
        set err "4 Redirect error: Unable to find 'location' in state(meta)."
      }
    }
    break
  }

  if {[info exists err]} {   putlog "$asx(logo) [string range $err 2 end]"
    if {[string index $err 0] > 1} {   ::http::cleanup $tok   }
    puthelp "PRIVMSG $ch :$asx(logo)Unable to get the requested data. Try again later."
    return 0
  }

  set html [::http::data $tok]  ;   ::http::cleanup $tok
  set html [join [lrange [split $html "\n"] 4 6] {}]

  # is redirected 302 #
  if {$try == 2} {   set similarto ""  ;   set allcount ""  ;   set simdict {}
    regexp {<span>Symbols similar to (.*?)</span></h2>(.*)$} $html - similarto html
    regexp {<span>All \((.*?)\)</span></a></li>(.*)$} $html - allcount html
    if {$similarto eq "" || $allcount eq ""} {
      puthelp "PRIVMSG $ch :$asx(logo)Unable to get the requested data."
      return 0
    }

    set re {<td class=\"data-col0[^>]+>[^>]+>(.*?)</a></td>[^>]+>(.*?)</td>(.*)$}
    while {[dict size $simdict] < 5} {
      if {![regexp $re $html - ssym sname html]} {   break   }
      dict set simdict $ssym $sname
    }
    set say "$asx(logo)Symbol Lookup >"

    if {[set dsize [dict size $simdict]] == 0} {
      puthelp "PRIVMSG $ch :$say Found no symbols similar to: \002${sym}\002"
      return 0
    }
    if {$dsize == 1} {  append say " Found one symbol similar to '${sym}':"
      puthelp "PRIVMSG $ch :$say  \002${ssym}\002 $sname"
      return 0
    }
    if {$dsize <= 3} {  append say " Found $dsize symbols similar to '${sym}':"
    } else {  append say " Found $allcount symbols similar to '${sym}'." }

    if {$allcount > 5} {   append say "  Showing the first 5:"
    } elseif {$allcount > 3} {   append say "  Showing all of them:"   }

    dict for {sy co} $simdict {   append say "  \002${sy}\002 $co"   }
    puthelp "PRIVMSG $ch :$say"
    return 0
  } ;# end: is redirected 302 #

  set company ""  ;   set xinfo ""

  regexp {<h1 class=\"D\(ib\) Fz\(18px\)\">(.*?)</h1>(.*)$} $html - company html
  regexp {^</div>[^>]+><span>(.*?)</span>(.*)$} $html - xinfo html
  if {$company eq "" || $xinfo eq ""} {
    puthelp "PRIVMSG $ch :$asx(logo)Invalid Company Symbol:  \002${sym}\002"
    return 0
  }
  set qmap [list %k $nk %h $ch %y $company %x $xinfo]


  set ils {lastprice change percent notice prevclose open bid ask dayrange 52weeks}
  foreach vname [lappend ils volume avgvolume marketcap] {  set $vname "N/A"  }

  regexp {regularMarketPrice[^>]+>(.*?)</fin-str(.*)$} $html - lastprice html
  regexp {regularMarketChange[^>]+><[^>]+>(.*?)</span(.*)$} $html - change html
  regexp {MarketChangePercent[^>]+><[^>]+>(.*?)</span(.*)$} $html - percent html
  regexp {quote-market-notice[^>]+><span>(.*?)</span>(.*)$} $html - notice html

  if {[matchstr "-*" $change]} {
    set change "\00304$change\003"  ;  set percent "\00304$percent\003"
  } elseif {[matchstr "+*" $change]} {
    set change "\00303$change\003"  ;  set percent "\00303$percent\003"
  }
  lappend qmap %l $lastprice %c $change %p $percent %n $notice

  regexp {PREV_CLOSE-value\">(.*?)</td></tr>(.*)$} $html - prevclose html
  regexp {\"OPEN-value\">(.*?)</td></tr>(.*)$} $html - open html
  regexp {\"BID-value\">(.*?)</td></tr>(.*)$} $html - bid html
  regexp {\"ASK-value\">(.*?)</td></tr>(.*)$} $html - ask html
  regexp {DAYS_RANGE-value\">(.*?)</td></tr>(.*)$} $html - dayrange html

  lappend qmap %r $prevclose %o $open %b $bid %a $ask %d $dayrange

  regexp {FIFTY_TWO_WK_RANGE-value\">(.*?)</td>(.*)$} $html - 52weeks html
  regexp {regularMarketVolume[^>]+>(.*?)</fin-streamer(.*)$} $html - volume html
  regexp {AVERAGE_VOLUME_3MONTH-value\">(.*?)</td>(.*)$} $html - avgvolume html
  regexp {\"MARKET_CAP-value\">(.*?)</td></tr>(.*)$} $html - marketcap html

  lappend qmap %w $52weeks %v $volume %g $avgvolume %m $marketcap


  set hmap [list "'" "'" "&" "&" """ "\""]

  #### e f i j q s t u z ####

  #  %y  = company name      ex.  Apollo Minerals Limited (AON.AX)
  #  %x  = asx info  ??      ex.  ASX - ASX Delayed price. Currency in AUD
  #  %l  = last price        ex.  108.66
  #  %c  = price change      ex.  -0.08
  #  %p  = change percent    ex.  (-0.07%)
  #  %n  = market notice     ex.  As of  10:17AM AEDT. Market open.

  #  %r  = previous close    ex.  108.74
  #  %o  = open              ex.  108.74
  #  %b  = bid               ex.  108.66 x 36400
  #  %a  = ask               ex.  108.69 x 7100
  #  %d  = day's range       ex.  108.38 - 109.15
  #  %w  = 52-week range     ex.  86.98 - 109.20
  #  %v  = volume            ex.  3,747,153
  #  %g  = avg. volume       ex.  2,190,023
  #  %m  = market cap        ex.  183.463B

  #  %k  = nick              ex.  GreedyHamster
  #  %h  = channel           ex.  #MarketHub


  set say [list "$asx(logo)%y  \002%l AUD\002  Change: \002%c %p\002  %n"]

  set s "Previous close: \002%r\002  Open: \002%o\002  Bid: \002%b\002  "
  append s "Ask: \002%a\002  Day's range: \002%d\002  Market cap: \002%m\002"
  lappend say $s


  foreach ln $say {
    set ln [string map $qmap $ln]  ;   set ln [string map $hmap $ln]
    putserv "PRIVMSG $ch :$ln"
  }
  return 0
}


proc onsource {} {   variable asx
  set asx(chan) [split [string tolower [string trim $asx(chan)]]]
  set asx(companylist_filename) [string trim $asx(companylist_filename)]

  set asx(companydict) [dict create]
  if {[file exists $asx(companylist_filename)]} {
    set open [open $asx(companylist_filename) r]
    set asx(companydict) [read -nonewline $open]   ;  close $open
  }
}
onsource


putlog "Loaded ausStocks.tcl version 0.3  10Feb2023"

}  ;## end of:  namespace eval ausStocks ##

SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
r
rainman
Voice
Posts: 11
Joined: Wed Apr 21, 2021 10:33 am

Re: ausStocks.tcl version 0.3 10Feb2023

Post by rainman »

Thanks Spike once again man, you're an awesome coder :)
Post Reply