DEV Community

Red for hopeless programmers - Part I

lepinekong on November 07, 2017

Part II is available. So you wanna learn to code ? You tried hard to tackle C++, C#, Java or even Python or Javascript but soon realise you stil...
Collapse
 
rgchris profile image
Chris Ross-Gill

COLLECT/KEEP is a nice way to manage multiple appends without even using additional words:

view collect [
    keep [text "stock symbol:"]
    keep [field]
    keep [return]
    keep [text "start date:"]
    keep [field]
    keep [return]
    keep [text "end date:"]
    keep [field]
    keep [return]
    keep [button "OK"]
]
Enter fullscreen mode Exit fullscreen mode
Collapse
 
pungiish profile image
Jan

Nice, never would have thought I'm going to learn a new language today :D

Collapse
 
lepinekong profile image
lepinekong

Glad you discovered it :)

Collapse
 
red_adi profile image
red-adi • Edited

@lepinekong Thanks for this nice introduction! As it seems, historical data aren't available from Google Finance any longer. So I switched to Yahoo Finance.

Red []

stock-symbol: trim ask "Enter stock symbol: " 

; load is a work-around as the to-date conversion is not working, yet
; to-integer converts to Unix epoch time
start-date: to-integer load ask "Enter start date (YYYY-MM-DD): "
end-date: to-integer load ask "Enter end date (YYYY-MM-DD): "

url: to-url rejoin [
    "https://query1.finance.yahoo.com/v7/finance/download/" stock-symbol
    "?period1=" start-date 
    "&period2=" end-date
    "&interval=1d&events=history&includeAdjustedClose=true"
]

quotes: Read url

write %quotes.csv quotes
Enter fullscreen mode Exit fullscreen mode
Collapse
 
jacobgood1 profile image
JacobGood1

"If you like this tutorial, I may start part II soon :)"

I like it, so go ahead with part 2 =)

Collapse
 
godwinburby profile image
Godwin Burby

Love this red language. I'm waiting for part iv where I can learn to automate windows apps with red. Currently i use Autohotkey.

Collapse
 
gltewalt profile image
Greg T • Edited

Very cool, thanks lepinkong :-)

Steps 1, 2, 3, can even be done all in one line.

Collapse
 
lepinekong profile image
lepinekong

You're welcome. Yes you're right and it's almost plain english :)