Here is the code to get you started; I will show how to grab the buffer URL, parse each line, and then display the ticker and price of each item. You can change it from there to do what you need.
This parses each row of stock data in the list, and it directly intercepts the values ββusing the first, second, third functions or using the nth. You can write functions to capture every element you want, for example, get-ticker (quote), which will just return (first ticker)
I would not think which data structure to use; all that is easiest is beautiful. If you need high performance, you should not use emacs lisp for this anyway.
(defun test() (interactive) (let ((quotes (get-quotes '("AAPL" "GOOG" "MSFT" "ORCL" "ERTS" "THQI") "sb"))) (show-quotes quotes))) (defun show-quotes(quotes) (dolist (quote quotes) (message (format "%s $%.2f" (first quote) (string-to-number (second quote)))))) (defun get-quotes(tickers field-string) "Given a list of ticker names and a string of fields to return as above, this grabs them from Yahoo, and parses them" (let ((results-buffer (get-yahoo-quotes-to-buffer (get-price-url tickers field-string)))) (switch-to-buffer results-buffer) (parse-quote-buffer results-buffer))) (defun get-price-url (tickers field-string) "Set up the get url" (concat "http://download.finance.yahoo.com/d/quotes.csv?s=" (mapconcat 'identity tickers "+") "&f=" field-string)) (defun get-yahoo-quotes-to-buffer(url) "Retrieve the quotes to a buffer and return it" (url-retrieve-synchronously url)) (defun parse-quote-buffer(b) "Parse the buffer for quotes" (goto-line 1) (re-search-forward "^\n") (beginning-of-line) (let ((res nil)) (while (> (point-max) (point)) (setf res (cons (split-string (thing-at-point 'line) ",") res)) (forward-line 1)) (reverse res)))
justinhj
source share