As requested by Andrew..

I believe someone here mentioned that they had added gui editing of the
stocks, to this script..
Could whoever that is please post it?

Cheers,

Allen K

REBOL [
        Title: "Simple Stock Monitor"
        Date: 3-Feb-2000
        File: %stocks.r
        Purpose: {
                Shows how to iterate a set of faces that make up
                the rows of a table.  Plus, it's a fun script.
                This one is faster and updates every 15 minutes.
        }
]

update-rate: 0:15  ; minutes

;-- Put your favorite stocks here, with # shares, and your purchase price:
stocks: [
        ["Apple Computer" AAPL  100 $50   ]
        ["IBM Corp"       IBM   100 $140  ]
        ["Yahoo"          YHOO  200 $80   ]
        ["General Magic"  GMGC 1000 $4.25 ]
        ["Amazon.com"     AMZN   50 $75   ]
]

record: [company symbol shares base price chg total]
labels: ["Company" "Symbol" "Shares" "Base" "Price" "Change"]

;-- Fetch current stock prices:
update-stocks: func [][
        syms: copy ""
        foreach stock stocks [append syms trim/all reform [stock/2 "+"]]
        clear back tail syms
        data: read join http://finance.yahoo.com/d/quotes.csv?s= [syms 
"&f=sl1d1t1c1ohgv&e=.csv"]
        stock-data: copy []
        parse data [
                some [
                        thru "," copy prc to ","
                        3 thru "," copy chg to ","
                        thru newline
                        (
                                rec: copy first stocks
                                append rec to-money prc
                                append rec to-money chg
                                append/only stock-data rec
                                stocks: next stocks
                        )
                ]
        ]
        stocks: head stocks
]

;-- Styles for the page:
stylize [
        entry main [
                size: 200x24
                body: [color: 80.40.20]
                font: [style: 'bold]
                edge: [effect: 'ibezel]
        ]
        right entry [font: [align: 'right]]
]

;-- Common field sizes:
big-size: 160x24
mid-size: 100x24
sml-size: 70x24

;-- Row as a face of fields:
row-face: make face [
        offset: 20x20
        size: 640x24
        body: edge: none
        pane: layout size [
                origin 0x0 across space 0
                row-company: entry big-size
                row-symbol:  entry sml-size
                row-shares:  right sml-size
                row-price:   right sml-size
                row-change:  right sml-size
                row-total:   right mid-size
        ]
]

;-- Sets colors for the row:
set-row-color: func [color][
        foreach face row-face/pane [face/body/color: color]
]

;-- Iteration function for generating table:
table-func: func [face index] [
        index: index - 1
        if index > (length? stock-data) [return none]
        if zero? index [
                set-row-color 0.0.0
                set record labels
        ]
        if positive? index [
                set record pick stock-data index
                set-row-color either price > base [0.120.0][200.0.0]
                row-face/offset: row-face/offset + (row-face/size * 0x1)
        ]
        row-company/text: company
        row-symbol/text:  symbol
        row-price/text:   price
        row-change/text:  chg
        row-shares/text:  shares
        row-total/text: either positive? index [(price - base) * shares]["Profit"]
        return row-face
]

;-- The face that holds the iterated pane:
table-face: make face [
        offset: 0x70
        size: 640x480
        body: edge: none
        feel: make feel [over: none]
        pane: :table-func
]

;-- Main pane for window:
main: make face [
        span: size: 640x480
        offset: 10x10
        pane: layout 640x480 [
                backtile (load carlwaves.jpg) 10.10.160
                Title "Stock Portfolio"
                status: Text "Updating..." 500x24
                at 500x30 button "Update Now" [update-display]
        ]
]

;-- Update stock display:
update-display: func [] [
        update-stocks
        row-face/offset: 20x20
        last-time: now/time + 24:00
        status/text: reform ["Updated on" now/date "at" now/time
                "  Courtesy of Yahoo.com  Updates every:" update-rate]
        show main
]

;-- Show it and wait for events:
show main
append main/pane table-face
update-display
event-port: open [scheme: 'event]
forever [
        time: now/time + 24:00
        if (time - last-time) > update-rate [update-display]
        wait event-port
        event: first event-port
        if event/type = 'quit [break]
        do event
]
close event-port

Reply via email to